mirror of https://github.com/docker/compose.git
introduce `build --print` to dump equivalent bakefile
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
6e814eac35
commit
75368c7859
|
@ -44,6 +44,7 @@ type buildOptions struct {
|
||||||
ssh string
|
ssh string
|
||||||
builder string
|
builder string
|
||||||
deps bool
|
deps bool
|
||||||
|
print bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opts buildOptions) toAPIBuildOptions(services []string) (api.BuildOptions, error) {
|
func (opts buildOptions) toAPIBuildOptions(services []string) (api.BuildOptions, error) {
|
||||||
|
@ -76,6 +77,8 @@ func (opts buildOptions) toAPIBuildOptions(services []string) (api.BuildOptions,
|
||||||
Quiet: opts.quiet,
|
Quiet: opts.quiet,
|
||||||
Services: services,
|
Services: services,
|
||||||
Deps: opts.deps,
|
Deps: opts.deps,
|
||||||
|
Memory: int64(opts.memory),
|
||||||
|
Print: opts.print,
|
||||||
SSHs: SSHKeys,
|
SSHs: SSHKeys,
|
||||||
Builder: builderName,
|
Builder: builderName,
|
||||||
}, nil
|
}, nil
|
||||||
|
@ -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.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.StringVar(&p.Progress, "progress", string(buildkit.AutoMode), fmt.Sprintf(`Set type of ui output (%s)`, strings.Join(printerModes, ", ")))
|
||||||
flags.MarkHidden("progress") //nolint:errcheck
|
flags.MarkHidden("progress") //nolint:errcheck
|
||||||
|
flags.BoolVar(&opts.print, "print", false, "Print equivalent bake file")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
@ -150,6 +154,5 @@ func runBuild(ctx context.Context, dockerCli command.Cli, backend api.Service, o
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
apiBuildOptions.Memory = int64(opts.memory)
|
|
||||||
return backend.Build(ctx, project, apiBuildOptions)
|
return backend.Build(ctx, project, apiBuildOptions)
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ run `docker compose build` to rebuild it.
|
||||||
| `--dry-run` | `bool` | | Execute command in dry run mode |
|
| `--dry-run` | `bool` | | Execute command in dry run mode |
|
||||||
| `-m`, `--memory` | `bytes` | `0` | Set memory limit for the build container. Not supported by BuildKit. |
|
| `-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 |
|
| `--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 |
|
| `--pull` | `bool` | | Always attempt to pull a newer version of the image |
|
||||||
| `--push` | `bool` | | Push service images |
|
| `--push` | `bool` | | Push service images |
|
||||||
| `-q`, `--quiet` | `bool` | | Don't print anything to STDOUT |
|
| `-q`, `--quiet` | `bool` | | Don't print anything to STDOUT |
|
||||||
|
|
|
@ -96,6 +96,16 @@ options:
|
||||||
experimentalcli: false
|
experimentalcli: false
|
||||||
kubernetes: false
|
kubernetes: false
|
||||||
swarm: 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
|
- option: progress
|
||||||
value_type: string
|
value_type: string
|
||||||
default_value: auto
|
default_value: auto
|
||||||
|
|
|
@ -155,6 +155,8 @@ type BuildOptions struct {
|
||||||
Memory int64
|
Memory int64
|
||||||
// Builder name passed in the command line
|
// Builder name passed in the command line
|
||||||
Builder string
|
Builder string
|
||||||
|
// Print don't actually run builder but print equivalent build config
|
||||||
|
Print bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply mutates project according to build options
|
// Apply mutates project according to build options
|
||||||
|
|
|
@ -105,7 +105,7 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if bake {
|
if bake || options.Print {
|
||||||
trace.SpanFromContext(ctx).SetAttributes(attribute.String("builder", "bake"))
|
trace.SpanFromContext(ctx).SetAttributes(attribute.String("builder", "bake"))
|
||||||
return s.doBuildBake(ctx, project, serviceToBuild, options)
|
return s.doBuildBake(ctx, project, serviceToBuild, options)
|
||||||
}
|
}
|
||||||
|
|
|
@ -219,6 +219,10 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
|
||||||
return nil, err
|
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))
|
logrus.Debugf("bake build config:\n%s", string(b))
|
||||||
|
|
||||||
metadata, err := os.CreateTemp(os.TempDir(), "compose")
|
metadata, err := os.CreateTemp(os.TempDir(), "compose")
|
||||||
|
|
Loading…
Reference in New Issue