Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cmd/compose/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type buildOptions struct {
ssh string
builder string
deps bool
print bool
}

func (opts buildOptions) toAPIBuildOptions(services []string) (api.BuildOptions, error) {
Expand Down Expand Up @@ -76,6 +77,8 @@ func (opts buildOptions) toAPIBuildOptions(services []string) (api.BuildOptions,
Quiet: opts.quiet,
Services: services,
Deps: opts.deps,
Memory: int64(opts.memory),
Print: opts.print,
SSHs: SSHKeys,
Builder: builderName,
}, nil
Expand Down Expand Up @@ -131,6 +134,7 @@ func buildCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service)
flags.VarP(&opts.memory, "memory", "m", "Set memory limit for the build container. Not supported by BuildKit.")
flags.StringVar(&p.Progress, "progress", string(buildkit.AutoMode), fmt.Sprintf(`Set type of ui output (%s)`, strings.Join(printerModes, ", ")))
flags.MarkHidden("progress") //nolint:errcheck
flags.BoolVar(&opts.print, "print", false, "Print equivalent bake file")

return cmd
}
Expand All @@ -150,6 +154,5 @@ func runBuild(ctx context.Context, dockerCli command.Cli, backend api.Service, o
return err
}

apiBuildOptions.Memory = int64(opts.memory)
return backend.Build(ctx, project, apiBuildOptions)
}
1 change: 1 addition & 0 deletions docs/reference/compose_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ run `docker compose build` to rebuild it.
| `--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 |
| `--print` | `bool` | | Print equivalent bake file |
| `--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 |
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 @@ -96,6 +96,16 @@ options:
experimentalcli: false
kubernetes: false
swarm: false
- option: print
value_type: bool
default_value: "false"
description: Print equivalent bake file
deprecated: false
hidden: false
experimental: false
experimentalcli: false
kubernetes: false
swarm: false
- option: progress
value_type: string
default_value: auto
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ type BuildOptions struct {
Memory int64
// Builder name passed in the command line
Builder string
// Print don't actually run builder but print equivalent build config
Print bool
}

// Apply mutates project according to build options
Expand Down
2 changes: 1 addition & 1 deletion pkg/compose/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti
if err != nil {
return nil, err
}
if bake {
if bake || options.Print {
trace.SpanFromContext(ctx).SetAttributes(attribute.String("builder", "bake"))
return s.doBuildBake(ctx, project, serviceToBuild, options)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/compose/build_bake.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
return nil, err
}

if options.Print {
_, err = fmt.Fprintln(s.stdinfo(), string(b))
return nil, err
}
logrus.Debugf("bake build config:\n%s", string(b))

metadata, err := os.CreateTemp(os.TempDir(), "compose")
Expand Down