Skip to content

Commit 8bb9a33

Browse files
authored
Merge pull request docker#10148 from maxcleme/feat/support_multiarch_push
Support for docker compose build --push
2 parents cf12239 + 634a7d2 commit 8bb9a33

File tree

6 files changed

+27
-2
lines changed

6 files changed

+27
-2
lines changed

cmd/compose/build.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type buildOptions struct {
3838
composeOptions
3939
quiet bool
4040
pull bool
41+
push bool
4142
progress string
4243
args []string
4344
noCache bool
@@ -57,6 +58,7 @@ func (opts buildOptions) toAPIBuildOptions(services []string) (api.BuildOptions,
5758

5859
return api.BuildOptions{
5960
Pull: opts.pull,
61+
Push: opts.push,
6062
Progress: opts.progress,
6163
Args: types.NewMappingWithEquals(opts.args),
6264
NoCache: opts.noCache,
@@ -108,6 +110,7 @@ func buildCommand(p *ProjectOptions, streams api.Streams, backend api.Service) *
108110
}),
109111
ValidArgsFunction: completeServiceNames(p),
110112
}
113+
cmd.Flags().BoolVar(&opts.push, "push", false, "Push service images.")
111114
cmd.Flags().BoolVarP(&opts.quiet, "quiet", "q", false, "Don't print anything to STDOUT")
112115
cmd.Flags().BoolVar(&opts.pull, "pull", false, "Always attempt to pull a newer version of the image.")
113116
cmd.Flags().StringVar(&opts.progress, "progress", buildx.PrinterModeAuto, fmt.Sprintf(`Set type of progress output (%s)`, strings.Join(printerModes, ", ")))

docs/reference/compose_build.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Build or rebuild services
1111
| `--no-cache` | | | Do not use cache when building the image |
1212
| `--progress` | `string` | `auto` | Set type of progress output (auto, tty, plain, quiet) |
1313
| `--pull` | | | Always attempt to pull a newer version of the image. |
14+
| `--push` | | | Push service images. |
1415
| `-q`, `--quiet` | | | Don't print anything to STDOUT |
1516
| `--ssh` | `string` | | Set SSH authentications used when building service images. (use 'default' for using your default SSH Agent) |
1617

docs/reference/docker_compose_build.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@ options:
106106
experimentalcli: false
107107
kubernetes: false
108108
swarm: false
109+
- option: push
110+
value_type: bool
111+
default_value: "false"
112+
description: Push service images.
113+
deprecated: false
114+
hidden: false
115+
experimental: false
116+
experimentalcli: false
117+
kubernetes: false
118+
swarm: false
109119
- option: quiet
110120
shorthand: q
111121
value_type: bool

pkg/api/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ type WatchOptions struct {
9191
type BuildOptions struct {
9292
// Pull always attempt to pull a newer version of the image
9393
Pull bool
94+
// Push pushes service images
95+
Push bool
9496
// Progress set type of progress output ("auto", "plain", "tty")
9597
Progress string
9698
// Args set build-time args

pkg/compose/build.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,15 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti
8686
Type: "docker",
8787
Attrs: map[string]string{
8888
"load": "true",
89+
"push": fmt.Sprint(options.Push),
8990
},
9091
}}
9192
if len(buildOptions.Platforms) > 1 {
9293
buildOptions.Exports = []bclient.ExportEntry{{
93-
Type: "image",
94-
Attrs: map[string]string{},
94+
Type: "image",
95+
Attrs: map[string]string{
96+
"push": fmt.Sprint(options.Push),
97+
},
9598
}}
9699
}
97100
opts := map[string]build.Options{imageName: buildOptions}

pkg/compose/build_classic.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ func (s *composeService) doBuildClassic(ctx context.Context, project *types.Proj
5959
errs = multierror.Append(errs, err).ErrorOrNil()
6060
}
6161
nameDigests[imageName] = digest
62+
if errs != nil {
63+
return nil
64+
}
65+
if len(o.Exports) != 0 && o.Exports[0].Attrs["push"] == "true" {
66+
return s.push(ctx, project, api.PushOptions{})
67+
}
6268
return nil
6369
})
6470
if err != nil {

0 commit comments

Comments
 (0)