feat: Add `continue-on-failure` option to build command

Signed-off-by: Kuba Knysiak <kuba.knysiak@gmail.com>
This commit is contained in:
Kuba Knysiak 2024-10-21 14:20:51 +02:00 committed by Kuba Knysiak
parent 82417bd5bc
commit 2780d27df7
4 changed files with 46 additions and 31 deletions

View File

@ -35,15 +35,16 @@ import (
type buildOptions struct {
*ProjectOptions
quiet bool
pull bool
push bool
args []string
noCache bool
memory cliopts.MemBytes
ssh string
builder string
deps bool
quiet bool
pull bool
push bool
args []string
noCache bool
memory cliopts.MemBytes
ssh string
builder string
deps bool
continueOnFailure bool
}
func (opts buildOptions) toAPIBuildOptions(services []string) (api.BuildOptions, error) {
@ -68,16 +69,17 @@ func (opts buildOptions) toAPIBuildOptions(services []string) (api.BuildOptions,
uiMode = "rawjson"
}
return api.BuildOptions{
Pull: opts.pull,
Push: opts.push,
Progress: uiMode,
Args: types.NewMappingWithEquals(opts.args),
NoCache: opts.noCache,
Quiet: opts.quiet,
Services: services,
Deps: opts.deps,
SSHs: SSHKeys,
Builder: builderName,
Pull: opts.pull,
Push: opts.push,
Progress: uiMode,
Args: types.NewMappingWithEquals(opts.args),
NoCache: opts.noCache,
Quiet: opts.quiet,
Services: services,
Deps: opts.deps,
SSHs: SSHKeys,
Builder: builderName,
ContinueOnFailure: opts.continueOnFailure,
}, nil
}
@ -118,6 +120,7 @@ func buildCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service)
flags.StringVar(&opts.ssh, "ssh", "", "Set SSH authentications used when building service images. (use 'default' for using your default SSH Agent)")
flags.StringVar(&opts.builder, "builder", "", "Set builder to use")
flags.BoolVar(&opts.deps, "with-dependencies", false, "Also build dependencies (transitively)")
flags.BoolVar(&opts.continueOnFailure, "continue-on-failure", false, "If any service build fails, continue building the remaining services")
flags.Bool("parallel", true, "Build images in parallel. DEPRECATED")
flags.MarkHidden("parallel") //nolint:errcheck

View File

@ -13,18 +13,19 @@ run `docker compose build` to rebuild it.
### Options
| Name | Type | Default | Description |
|:----------------------|:--------------|:--------|:------------------------------------------------------------------------------------------------------------|
| `--build-arg` | `stringArray` | | Set build-time variables for services |
| `--builder` | `string` | | Set builder to use |
| `--dry-run` | `bool` | | Execute command in dry run mode |
| `-m`, `--memory` | `bytes` | `0` | Set memory limit for the build container. Not supported by BuildKit. |
| `--no-cache` | `bool` | | Do not use cache when building the image |
| `--pull` | `bool` | | Always attempt to pull a newer version of the image |
| `--push` | `bool` | | Push service images |
| `-q`, `--quiet` | `bool` | | Don't print anything to STDOUT |
| `--ssh` | `string` | | Set SSH authentications used when building service images. (use 'default' for using your default SSH Agent) |
| `--with-dependencies` | `bool` | | Also build dependencies (transitively) |
| Name | Type | Default | Description |
|:------------------------|:--------------|:--------|:------------------------------------------------------------------------------------------------------------|
| `--build-arg` | `stringArray` | | Set build-time variables for services |
| `--builder` | `string` | | Set builder to use |
| `--dry-run` | `bool` | | Execute command in dry run mode |
| `-m`, `--memory` | `bytes` | `0` | Set memory limit for the build container. Not supported by BuildKit. |
| `--no-cache` | `bool` | | Do not use cache when building the image |
| `--pull` | `bool` | | Always attempt to pull a newer version of the image |
| `--push` | `bool` | | Push service images |
| `-q`, `--quiet` | `bool` | | Don't print anything to STDOUT |
| `--ssh` | `string` | | Set SSH authentications used when building service images. (use 'default' for using your default SSH Agent) |
| `--with-dependencies` | `bool` | | Also build dependencies (transitively) |
| `--continue-on-failure` | `bool` | false | If any service build fails, continue building the remaining services |
<!---MARKER_GEN_END-->

View File

@ -150,6 +150,8 @@ type BuildOptions struct {
Memory int64
// Builder name passed in the command line
Builder string
// If any service build fails, continue building the remaining services
ContinueOnFailure bool
}
// Apply mutates project according to build options

View File

@ -161,6 +161,9 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti
if !buildkitEnabled {
id, err := s.doBuildClassic(ctx, project, service, options)
if err != nil {
if options.ContinueOnFailure {
return nil
}
return err
}
builtDigests[getServiceIndex(name)] = id
@ -177,11 +180,17 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti
buildOptions, err := s.toBuildOptions(project, service, options)
if err != nil {
if options.ContinueOnFailure {
return nil
}
return err
}
digest, err := s.doBuildBuildkit(ctx, name, buildOptions, w, nodes)
if err != nil {
if options.ContinueOnFailure {
return nil
}
return err
}
builtDigests[getServiceIndex(name)] = digest