Documentation
¶
Index ¶
- Variables
- func Init(ctx context.Context, configPath string, opt *InitOption, stdout io.Writer) error
- func IsExitCode(err error) bool
- func MarshalIndent(v any) (string, error)
- func Normalize(def map[string]any) (map[string]any, error)
- func PruneDefaults(remote, local map[string]any) map[string]any
- func RemoteOnlyPaths(remote, local map[string]any) []string
- func RemoteToMap(jd types.JobDefinition) (map[string]any, error)
- func Run(ctx context.Context, args []string) error
- type App
- func (a *App) Deploy(ctx context.Context, opt *DeployOption) error
- func (a *App) Deregister(ctx context.Context, opt *DeregisterOption) error
- func (a *App) Diff(ctx context.Context, opt *DiffOption) error
- func (a *App) Render(ctx context.Context, opt *RenderOption) error
- func (a *App) Revisions(ctx context.Context, opt *RevisionsOption) error
- func (a *App) Rollback(ctx context.Context, opt *RollbackOption) error
- func (a *App) Run(ctx context.Context, opt *RunOption) error
- func (a *App) Status(ctx context.Context, opt *StatusOption) error
- func (a *App) Target(names []string) ([]*JobDef, error)
- type BatchAPI
- type CLI
- type Config
- type DeployOption
- type DeregisterOption
- type DiffOption
- type Funcs
- type InitOption
- type JobDef
- type JsonnetOptions
- type Options
- type Plugin
- type RenderOption
- type RevisionsOption
- type RollbackOption
- type RunOption
- type SSMAPI
- type StatusOption
Constants ¶
This section is empty.
Variables ¶
var Version = "dev"
Version is set at build time.
Functions ¶
func Init ¶
Init imports an existing job definition from AWS and starts tracking it in the configuration file, creating the file if it does not exist yet.
func IsExitCode ¶
IsExitCode reports whether err only signals a non-zero exit status.
func MarshalIndent ¶
MarshalIndent renders a job definition as the canonical JSON text used for diffs and for files written by init. Object members are sorted by name.
func Normalize ¶
Normalize converts an arbitrary job definition document into the canonical form used for diffing and registration. The document is decoded into the SDK input type (rejecting unknown members, which catches typos) and re-encoded with the member names the Batch API uses.
func PruneDefaults ¶
PruneDefaults removes members from remote that the API filled in with a default value and that local does not mention, so that a definition which omits optional members does not show a diff against every default the API materialised. Members that local does mention are always kept, even when they hold a default value.
func RemoteOnlyPaths ¶
RemoteOnlyPaths lists the dotted paths of members that survived PruneDefaults on the remote side but do not exist in the local definition. Array indexes are elided, the same convention as nonFalsyDefaults. Such a member is either something the user removed on purpose, or a default the API materialised that nonFalsyDefaults does not know about yet -- a false diff.
func RemoteToMap ¶
func RemoteToMap(jd types.JobDefinition) (map[string]any, error)
RemoteToMap converts a job definition read back from the API into the same canonical form as a local definition, so that the two can be compared.
Types ¶
type App ¶
type App struct {
Config *Config
JobDefs []*JobDef
Batch BatchAPI
Debug bool
Stdout io.Writer
Stderr io.Writer
// WaitInterval is how often run --wait polls the job status. The zero
// value means the default of 5 seconds.
WaitInterval time.Duration
}
App holds everything the commands operate on.
func (*App) Deploy ¶
func (a *App) Deploy(ctx context.Context, opt *DeployOption) error
Deploy registers a new revision for each job definition that differs from the latest ACTIVE revision.
func (*App) Deregister ¶
func (a *App) Deregister(ctx context.Context, opt *DeregisterOption) error
Deregister makes revisions INACTIVE, either a specific one or everything older than the newest N.
func (*App) Diff ¶
func (a *App) Diff(ctx context.Context, opt *DiffOption) error
Diff compares each local job definition against the latest ACTIVE revision.
func (*App) Render ¶
func (a *App) Render(ctx context.Context, opt *RenderOption) error
Render prints the fully evaluated job definitions as JSON.
func (*App) Revisions ¶
func (a *App) Revisions(ctx context.Context, opt *RevisionsOption) error
Revisions lists the revisions of each job definition, newest first.
func (*App) Rollback ¶
func (a *App) Rollback(ctx context.Context, opt *RollbackOption) error
Rollback deregisters the latest ACTIVE revision so that the one before it becomes the revision jobs resolve to.
func (*App) Run ¶
Run submits a one-off job using the latest ACTIVE revision, meant as a smoke test right after a deploy. Production job submission -- schedules, overrides, dependencies, array jobs -- is out of scope; use SubmitJob directly for that.
type BatchAPI ¶
type BatchAPI interface {
DescribeJobDefinitions(ctx context.Context, params *batch.DescribeJobDefinitionsInput, optFns ...func(*batch.Options)) (*batch.DescribeJobDefinitionsOutput, error)
RegisterJobDefinition(ctx context.Context, params *batch.RegisterJobDefinitionInput, optFns ...func(*batch.Options)) (*batch.RegisterJobDefinitionOutput, error)
DeregisterJobDefinition(ctx context.Context, params *batch.DeregisterJobDefinitionInput, optFns ...func(*batch.Options)) (*batch.DeregisterJobDefinitionOutput, error)
SubmitJob(ctx context.Context, params *batch.SubmitJobInput, optFns ...func(*batch.Options)) (*batch.SubmitJobOutput, error)
DescribeJobs(ctx context.Context, params *batch.DescribeJobsInput, optFns ...func(*batch.Options)) (*batch.DescribeJobsOutput, error)
}
BatchAPI is the subset of the Batch client batchbru uses.
type CLI ¶
type CLI struct {
Config string `help:"path to the configuration file" short:"c" default:"batchbru.yml" env:"BATCHBRU_CONFIG"`
Debug bool `help:"print debug logs"`
ExtStr map[string]string `help:"Jsonnet external variable (string), repeatable as KEY=VALUE" name:"ext-str"`
ExtCode map[string]string `help:"Jsonnet external variable (code), repeatable as KEY=EXPR" name:"ext-code"`
Init InitOption `cmd:"" help:"import an existing job definition and start tracking it"`
Render RenderOption `cmd:"" help:"print the fully evaluated job definitions"`
Diff DiffOption `cmd:"" help:"show the difference against the latest ACTIVE revision"`
Deploy DeployOption `cmd:"" help:"register a new revision for changed job definitions"`
Run RunOption `cmd:"" help:"submit a one-off job to smoke-test the latest ACTIVE revision"`
Status StatusOption `cmd:"" help:"show the latest ACTIVE revision of each job definition"`
Revisions RevisionsOption `cmd:"" help:"list the revisions of each job definition"`
Rollback RollbackOption `cmd:"" help:"deregister the latest ACTIVE revision"`
Deregister DeregisterOption `cmd:"" help:"deregister revisions"`
Version struct{} `cmd:"" help:"print the version"`
}
CLI is the command line interface of batchbru.
type Config ¶
type Config struct {
Region string `yaml:"region,omitempty" json:"region,omitempty"`
JobDefinitions []string `yaml:"job_definitions" json:"job_definitions"`
Plugins []Plugin `yaml:"plugins,omitempty" json:"plugins,omitempty"`
// contains filtered or unexported fields
}
Config is the batchbru configuration file.
func LoadConfig ¶
func LoadConfig(ctx context.Context, path string, funcs *Funcs, opts *JsonnetOptions) (*Config, error)
LoadConfig reads and validates the configuration file at path.
func (*Config) Dir ¶
Dir is the directory the configuration was loaded from. Job definition paths are resolved relative to it.
func (*Config) ResolveJobDefinitionFiles ¶
ResolveJobDefinitionFiles expands the job_definitions patterns into a sorted, deduplicated list of file paths.
type DeployOption ¶
type DeployOption struct {
Names []string `help:"job definition names to target (wildcards allowed, repeatable)" name:"name" short:"n"`
DryRun bool `help:"show what would be registered without calling the API"`
Force bool `help:"register a new revision even when there is no difference"`
}
DeployOption configures the deploy command.
type DeregisterOption ¶
type DeregisterOption struct {
Names []string `help:"job definition names to target (wildcards allowed, repeatable)" name:"name" short:"n"`
Revision int32 `help:"deregister this revision"`
KeepLatest int32 `help:"deregister every ACTIVE revision except the newest N"`
DryRun bool `help:"show what would be deregistered without calling the API"`
Force bool `help:"do not ask for confirmation"`
}
DeregisterOption configures the deregister command.
type DiffOption ¶
type DiffOption struct {
Names []string `help:"job definition names to target (wildcards allowed, repeatable)" name:"name" short:"n"`
ExitCode bool `help:"exit with code 1 when there is a difference"`
}
DiffOption configures the diff command.
type Funcs ¶
type Funcs struct {
// contains filtered or unexported fields
}
Funcs holds the template functions available while reading configuration and job definition files.
type InitOption ¶
type InitOption struct {
JobDefinition string `help:"name of the existing job definition to import" required:""`
Format string `help:"output format of the job definition file" enum:"jsonnet,json,yaml" default:"jsonnet"`
Path string `help:"directory to write the job definition file into" default:"jobdefs"`
Region string `help:"AWS region (defaults to the SDK resolution)"`
Overwrite bool `help:"overwrite the job definition file if it already exists"`
}
InitOption configures the init command.
type JobDef ¶
type JobDef struct {
// Name is the jobDefinitionName declared in the file.
Name string
// Path is the file the definition was loaded from.
Path string
// Def is the definition in canonical form.
Def map[string]any
}
JobDef is a job definition loaded from a local file.
func Filter ¶
Filter returns the definitions whose name matches one of the given patterns. Patterns accept shell-style wildcards. An empty pattern list matches all.
func LoadJobDefFile ¶
func LoadJobDefFile(path string, funcs *Funcs, opts *JsonnetOptions) (*JobDef, error)
LoadJobDefFile reads a single job definition file: template functions are evaluated first, then the result is parsed according to the file extension and normalized.
func LoadJobDefs ¶
func LoadJobDefs(c *Config, funcs *Funcs, opts *JsonnetOptions) ([]*JobDef, error)
LoadJobDefs reads every job definition file listed in the configuration.
type JsonnetOptions ¶
JsonnetOptions carries the external variables passed on the command line.
type Options ¶
type Options struct {
ConfigPath string
Debug bool
ExtStr map[string]string
ExtCode map[string]string
}
Options are the global command line options.
type Plugin ¶
type Plugin struct {
Name string `yaml:"name" json:"name"`
Config map[string]any `yaml:"config,omitempty" json:"config,omitempty"`
FuncPrefix string `yaml:"func_prefix,omitempty" json:"func_prefix,omitempty"`
}
Plugin extends the template functions available to job definition files.
type RenderOption ¶
type RenderOption struct {
Names []string `help:"job definition names to target (wildcards allowed, repeatable)" name:"name" short:"n"`
}
RenderOption configures the render command.
type RevisionsOption ¶
type RevisionsOption struct {
Names []string `help:"job definition names to target (wildcards allowed, repeatable)" name:"name" short:"n"`
All bool `help:"include INACTIVE revisions"`
}
RevisionsOption configures the revisions command.
type RollbackOption ¶
type RollbackOption struct {
Names []string `help:"job definition names to target (wildcards allowed, repeatable)" name:"name" short:"n"`
DryRun bool `help:"show what would be deregistered without calling the API"`
}
RollbackOption configures the rollback command.
type RunOption ¶
type RunOption struct {
Names []string `help:"job definition name to run (wildcards allowed, must match exactly one)" name:"name" short:"n"`
Queue string `help:"job queue to submit to" required:""`
Wait bool `help:"poll until the job reaches SUCCEEDED or FAILED"`
}
RunOption configures the run command.
type SSMAPI ¶
type SSMAPI interface {
GetParameter(ctx context.Context, params *ssm.GetParameterInput, optFns ...func(*ssm.Options)) (*ssm.GetParameterOutput, error)
}
SSMAPI is the subset of the SSM client used to resolve the ssm template function.
type StatusOption ¶
type StatusOption struct {
Names []string `help:"job definition names to target (wildcards allowed, repeatable)" name:"name" short:"n"`
}
StatusOption configures the status command.