Skip to content

Commit

Permalink
only use ToModel when --no-interpolate is set
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Mar 13, 2024
1 parent 17d4229 commit 5a1ba0e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
37 changes: 25 additions & 12 deletions cmd/compose/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/e2e/compose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,16 @@ 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:
context: %s
dockerfile: Dockerfile
networks:
default: null
networks:
default:
name: compose-e2e-convert_default
`, projectName, filepath.Join(wd, "fixtures", "simple-build-test", "nginx-build")), ExitCode: 0})
})
}
Expand Down

0 comments on commit 5a1ba0e

Please sign in to comment.