only use ToModel when --no-interpolate is set

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2024-03-12 11:19:16 +01:00 committed by Nicolas De loof
parent 17d4229e57
commit 5a1ba0efcf
2 changed files with 28 additions and 15 deletions

View File

@ -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 {
model, err := opts.ToModel(ctx, dockerCli, services)
if err != nil {
return err
}
if opts.resolveImageDigests {
err = resolveImageDigests(ctx, dockerCli, model)
var content []byte
if opts.noInterpolate {
// we can't use ToProject, so the model we render here is only partially resolved
model, err := opts.ToModel(ctx, dockerCli, services)
if err != nil {
return err
}
}
content, err := formatModel(model, opts.Format)
if err != nil {
return err
if opts.resolveImageDigests {
err = resolveImageDigests(ctx, dockerCli, model)
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 {
@ -164,7 +177,7 @@ func runConfig(ctx context.Context, dockerCli command.Cli, opts configOptions, s
if opts.Output != "" && len(content) > 0 {
return os.WriteFile(opts.Output, content, 0o666)
}
_, err = fmt.Fprint(dockerCli.Out(), string(content))
_, err := fmt.Fprint(dockerCli.Out(), string(content))
return err
}

View File

@ -245,9 +245,6 @@ func TestConfig(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.Assert(t, icmd.Expected{Out: fmt.Sprintf(`name: %s
networks:
default:
name: compose-e2e-convert_default
services:
nginx:
build:
@ -255,6 +252,9 @@ services:
dockerfile: Dockerfile
networks:
default: null
networks:
default:
name: compose-e2e-convert_default
`, projectName, filepath.Join(wd, "fixtures", "simple-build-test", "nginx-build")), ExitCode: 0})
})
}