-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender.go
More file actions
40 lines (33 loc) · 1023 Bytes
/
render.go
File metadata and controls
40 lines (33 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package batcha
import (
"context"
"fmt"
"path/filepath"
goconfig "github.com/kayac/go-config"
)
// render loads and renders the job definition template.
func (app *App) render(ctx context.Context) (rendered map[string]any, err error) {
loader := goconfig.New()
if err := setupPlugins(ctx, app.config, loader); err != nil {
return nil, err
}
jobDefPath := app.config.JobDefinition
if !filepath.IsAbs(jobDefPath) {
jobDefPath = filepath.Join(filepath.Dir(app.configPath), jobDefPath)
}
// go-config panics on must_env with undefined variables.
defer func() {
if r := recover(); r != nil {
rendered = nil
err = fmt.Errorf("%v", r)
}
}()
if err := loader.LoadWithEnvJSON(&rendered, jobDefPath); err != nil {
return nil, fmt.Errorf("failed to render job definition template: %w", err)
}
return rendered, nil
}
// Render renders the job definition template and prints the result.
func (app *App) Render(ctx context.Context) error {
return app.Register(ctx, RegisterOption{DryRun: true})
}