Skip to content

Commit

Permalink
Merge pull request #10148 from maxcleme/feat/support_multiarch_push
Browse files Browse the repository at this point in the history
Support for docker compose build --push
  • Loading branch information
glours authored Jan 26, 2023
2 parents cf12239 + 634a7d2 commit 8bb9a33
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cmd/compose/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type buildOptions struct {
composeOptions
quiet bool
pull bool
push bool
progress string
args []string
noCache bool
Expand All @@ -57,6 +58,7 @@ func (opts buildOptions) toAPIBuildOptions(services []string) (api.BuildOptions,

return api.BuildOptions{
Pull: opts.pull,
Push: opts.push,
Progress: opts.progress,
Args: types.NewMappingWithEquals(opts.args),
NoCache: opts.noCache,
Expand Down Expand Up @@ -108,6 +110,7 @@ func buildCommand(p *ProjectOptions, streams api.Streams, backend api.Service) *
}),
ValidArgsFunction: completeServiceNames(p),
}
cmd.Flags().BoolVar(&opts.push, "push", false, "Push service images.")
cmd.Flags().BoolVarP(&opts.quiet, "quiet", "q", false, "Don't print anything to STDOUT")
cmd.Flags().BoolVar(&opts.pull, "pull", false, "Always attempt to pull a newer version of the image.")
cmd.Flags().StringVar(&opts.progress, "progress", buildx.PrinterModeAuto, fmt.Sprintf(`Set type of progress output (%s)`, strings.Join(printerModes, ", ")))
Expand Down
1 change: 1 addition & 0 deletions docs/reference/compose_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Build or rebuild services
| `--no-cache` | | | Do not use cache when building the image |
| `--progress` | `string` | `auto` | Set type of progress output (auto, tty, plain, quiet) |
| `--pull` | | | Always attempt to pull a newer version of the image. |
| `--push` | | | Push service images. |
| `-q`, `--quiet` | | | Don't print anything to STDOUT |
| `--ssh` | `string` | | Set SSH authentications used when building service images. (use 'default' for using your default SSH Agent) |

Expand Down
10 changes: 10 additions & 0 deletions docs/reference/docker_compose_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ options:
experimentalcli: false
kubernetes: false
swarm: false
- option: push
value_type: bool
default_value: "false"
description: Push service images.
deprecated: false
hidden: false
experimental: false
experimentalcli: false
kubernetes: false
swarm: false
- option: quiet
shorthand: q
value_type: bool
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ type WatchOptions struct {
type BuildOptions struct {
// Pull always attempt to pull a newer version of the image
Pull bool
// Push pushes service images
Push bool
// Progress set type of progress output ("auto", "plain", "tty")
Progress string
// Args set build-time args
Expand Down
7 changes: 5 additions & 2 deletions pkg/compose/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,15 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti
Type: "docker",
Attrs: map[string]string{
"load": "true",
"push": fmt.Sprint(options.Push),
},
}}
if len(buildOptions.Platforms) > 1 {
buildOptions.Exports = []bclient.ExportEntry{{
Type: "image",
Attrs: map[string]string{},
Type: "image",
Attrs: map[string]string{
"push": fmt.Sprint(options.Push),
},
}}
}
opts := map[string]build.Options{imageName: buildOptions}
Expand Down
6 changes: 6 additions & 0 deletions pkg/compose/build_classic.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ func (s *composeService) doBuildClassic(ctx context.Context, project *types.Proj
errs = multierror.Append(errs, err).ErrorOrNil()
}
nameDigests[imageName] = digest
if errs != nil {
return nil
}
if len(o.Exports) != 0 && o.Exports[0].Attrs["push"] == "true" {
return s.push(ctx, project, api.PushOptions{})
}
return nil
})
if err != nil {
Expand Down

0 comments on commit 8bb9a33

Please sign in to comment.