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,6 +136,9 @@ func configCommand(p *ProjectOptions, dockerCli command.Cli) *cobra.Command {
|
|||
}
|
||||
|
||||
func runConfig(ctx context.Context, dockerCli command.Cli, opts configOptions, services []string) error {
|
||||
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
|
||||
|
@ -148,10 +151,20 @@ func runConfig(ctx context.Context, dockerCli command.Cli, opts configOptions, s
|
|||
}
|
||||
}
|
||||
|
||||
content, err := formatModel(model, opts.Format)
|
||||
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 {
|
||||
content = escapeDollarSign(content)
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue