mirror of https://github.com/docker/compose.git
only use ToModel when --no-interpolate is set
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
17d4229e57
commit
5a1ba0efcf
|
@ -136,21 +136,34 @@ func configCommand(p *ProjectOptions, dockerCli command.Cli) *cobra.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
func runConfig(ctx context.Context, dockerCli command.Cli, opts configOptions, services []string) error {
|
func runConfig(ctx context.Context, dockerCli command.Cli, opts configOptions, services []string) error {
|
||||||
model, err := opts.ToModel(ctx, dockerCli, services)
|
var content []byte
|
||||||
if err != nil {
|
if opts.noInterpolate {
|
||||||
return err
|
// we can't use ToProject, so the model we render here is only partially resolved
|
||||||
}
|
model, err := opts.ToModel(ctx, dockerCli, services)
|
||||||
|
|
||||||
if opts.resolveImageDigests {
|
|
||||||
err = resolveImageDigests(ctx, dockerCli, model)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
content, err := formatModel(model, opts.Format)
|
if opts.resolveImageDigests {
|
||||||
if err != nil {
|
err = resolveImageDigests(ctx, dockerCli, model)
|
||||||
return err
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
content, err = formatModel(model, opts.Format)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
project, err := opts.ToProject(ctx, dockerCli, services)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
content, err = project.MarshalYAML()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !opts.noInterpolate {
|
if !opts.noInterpolate {
|
||||||
|
@ -164,7 +177,7 @@ func runConfig(ctx context.Context, dockerCli command.Cli, opts configOptions, s
|
||||||
if opts.Output != "" && len(content) > 0 {
|
if opts.Output != "" && len(content) > 0 {
|
||||||
return os.WriteFile(opts.Output, content, 0o666)
|
return os.WriteFile(opts.Output, content, 0o666)
|
||||||
}
|
}
|
||||||
_, err = fmt.Fprint(dockerCli.Out(), string(content))
|
_, err := fmt.Fprint(dockerCli.Out(), string(content))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -245,9 +245,6 @@ func TestConfig(t *testing.T) {
|
||||||
t.Run("up", func(t *testing.T) {
|
t.Run("up", func(t *testing.T) {
|
||||||
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/simple-build-test/compose.yaml", "-p", projectName, "convert")
|
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/simple-build-test/compose.yaml", "-p", projectName, "convert")
|
||||||
res.Assert(t, icmd.Expected{Out: fmt.Sprintf(`name: %s
|
res.Assert(t, icmd.Expected{Out: fmt.Sprintf(`name: %s
|
||||||
networks:
|
|
||||||
default:
|
|
||||||
name: compose-e2e-convert_default
|
|
||||||
services:
|
services:
|
||||||
nginx:
|
nginx:
|
||||||
build:
|
build:
|
||||||
|
@ -255,6 +252,9 @@ services:
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
networks:
|
networks:
|
||||||
default: null
|
default: null
|
||||||
|
networks:
|
||||||
|
default:
|
||||||
|
name: compose-e2e-convert_default
|
||||||
`, projectName, filepath.Join(wd, "fixtures", "simple-build-test", "nginx-build")), ExitCode: 0})
|
`, projectName, filepath.Join(wd, "fixtures", "simple-build-test", "nginx-build")), ExitCode: 0})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue