From 9b5a4588f9808e80a79f139ee53460a0655cff0a Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Thu, 11 May 2023 11:47:47 +0200 Subject: [PATCH] introduce --no-path-resolution to skip relative path to be resolved Signed-off-by: Nicolas De Loof --- cmd/compose/compose.go | 2 +- cmd/compose/config.go | 6 ++++-- docs/reference/compose_config.md | 1 + docs/reference/docker_compose_config.yaml | 10 ++++++++++ go.mod | 2 +- go.sum | 4 ++-- pkg/e2e/compose_environment_test.go | 15 +-------------- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/cmd/compose/compose.go b/cmd/compose/compose.go index d8428e603..cb6617f21 100644 --- a/cmd/compose/compose.go +++ b/cmd/compose/compose.go @@ -392,7 +392,7 @@ func RootCommand(streams command.Cli, backend api.Service) *cobra.Command { //no psCommand(&opts, streams, backend), listCommand(streams, backend), logsCommand(&opts, streams, backend), - convertCommand(&opts, streams, backend), + configCommand(&opts, streams, backend), killCommand(&opts, backend), runCommand(&opts, streams, backend), removeCommand(&opts, backend), diff --git a/cmd/compose/config.go b/cmd/compose/config.go index 3fb945e75..22d02358f 100644 --- a/cmd/compose/config.go +++ b/cmd/compose/config.go @@ -40,6 +40,7 @@ type configOptions struct { resolveImageDigests bool noInterpolate bool noNormalize bool + noResolvePath bool services bool volumes bool profiles bool @@ -51,14 +52,14 @@ type configOptions struct { func (o *configOptions) ToProject(services []string) (*types.Project, error) { return o.ProjectOptions.ToProject(services, cli.WithInterpolation(!o.noInterpolate), - cli.WithResolvedPaths(true), + cli.WithResolvedPaths(!o.noResolvePath), cli.WithNormalization(!o.noNormalize), cli.WithConsistency(!o.noConsistency), cli.WithProfiles(o.Profiles), cli.WithDiscardEnvFile) } -func convertCommand(p *ProjectOptions, streams api.Streams, backend api.Service) *cobra.Command { +func configCommand(p *ProjectOptions, streams api.Streams, backend api.Service) *cobra.Command { opts := configOptions{ ProjectOptions: p, } @@ -106,6 +107,7 @@ func convertCommand(p *ProjectOptions, streams api.Streams, backend api.Service) flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only validate the configuration, don't print anything.") flags.BoolVar(&opts.noInterpolate, "no-interpolate", false, "Don't interpolate environment variables.") flags.BoolVar(&opts.noNormalize, "no-normalize", false, "Don't normalize compose model.") + flags.BoolVar(&opts.noResolvePath, "no-path-resolution", false, "Don't resolve file paths.") flags.BoolVar(&opts.noConsistency, "no-consistency", false, "Don't check model consistency - warning: may produce invalid Compose output") flags.BoolVar(&opts.services, "services", false, "Print the service names, one per line.") diff --git a/docs/reference/compose_config.md b/docs/reference/compose_config.md index 27e21d1a1..15612ea33 100644 --- a/docs/reference/compose_config.md +++ b/docs/reference/compose_config.md @@ -18,6 +18,7 @@ Parse, resolve and render compose file in canonical format | `--no-consistency` | | | Don't check model consistency - warning: may produce invalid Compose output | | `--no-interpolate` | | | Don't interpolate environment variables. | | `--no-normalize` | | | Don't normalize compose model. | +| `--no-path-resolution` | | | Don't resolve file paths. | | `-o`, `--output` | `string` | | Save to file (default to stdout) | | `--profiles` | | | Print the profile names, one per line. | | `-q`, `--quiet` | | | Only validate the configuration, don't print anything. | diff --git a/docs/reference/docker_compose_config.yaml b/docs/reference/docker_compose_config.yaml index 387e73fea..53078ee77 100644 --- a/docs/reference/docker_compose_config.yaml +++ b/docs/reference/docker_compose_config.yaml @@ -69,6 +69,16 @@ options: experimentalcli: false kubernetes: false swarm: false + - option: no-path-resolution + value_type: bool + default_value: "false" + description: Don't resolve file paths. + deprecated: false + hidden: false + experimental: false + experimentalcli: false + kubernetes: false + swarm: false - option: output shorthand: o value_type: string diff --git a/go.mod b/go.mod index 0b55cac82..59af13c86 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.20 require ( github.com/AlecAivazis/survey/v2 v2.3.6 github.com/buger/goterm v1.0.4 - github.com/compose-spec/compose-go v1.13.4 + github.com/compose-spec/compose-go v1.13.5 github.com/containerd/console v1.0.3 github.com/containerd/containerd v1.6.21 github.com/cucumber/godog v0.0.0-00010101000000-000000000000 // replaced; see replace for the actual version used diff --git a/go.sum b/go.sum index 24c4d2707..9b407e5e4 100644 --- a/go.sum +++ b/go.sum @@ -165,8 +165,8 @@ github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWH github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= -github.com/compose-spec/compose-go v1.13.4 h1:O6xAsPqaY1s9KXteiO7wRCDTJLahv1XP/z/eUO9EfbI= -github.com/compose-spec/compose-go v1.13.4/go.mod h1:rsiZ8uaOHJYJemDBzTe9UBpaq5ZFVEOO4TxM2G3SJxk= +github.com/compose-spec/compose-go v1.13.5 h1:ogqJOGEbe3uRxMg0ZEufOoCQTpX61l8tUeyW4UQgEBk= +github.com/compose-spec/compose-go v1.13.5/go.mod h1:m0o4G6MQDHjjz9rY7No9FpnNi+9sKic262rzrwuCqic= github.com/containerd/cgroups v1.0.4 h1:jN/mbWBEaz+T1pi5OFtnkQ+8qnmEbAr1Oo1FRm5B0dA= github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw= github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U= diff --git a/pkg/e2e/compose_environment_test.go b/pkg/e2e/compose_environment_test.go index a0cfca863..6bab12764 100644 --- a/pkg/e2e/compose_environment_test.go +++ b/pkg/e2e/compose_environment_test.go @@ -177,26 +177,13 @@ func TestEnvPriority(t *testing.T) { func TestEnvInterpolation(t *testing.T) { c := NewParallelCLI(t) - // No variable defined in the Compose file and nor env variable pass to the run command - // 1. Command Line (docker compose run --env ) - // 2. Compose File (service::environment section) <-- Result expected (From environment patched by .env as a default --env-file value) - // 3. Compose File (service::env_file section file) - // 4. Container Image ENV directive - // 5. Variable is not defined t.Run("shell priority from run command", func(t *testing.T) { cmd := c.NewDockerComposeCmd(t, "-f", "./fixtures/environment/env-interpolation/compose.yaml", "config") cmd.Env = append(cmd.Env, "WHEREAMI=shell") res := icmd.RunCmd(cmd) - res.Assert(t, icmd.Expected{Out: `IMAGE: default_env:EnvFile`}) + res.Assert(t, icmd.Expected{Out: `IMAGE: default_env:shell`}) }) - // No variable defined in the Compose file and env variable pass to the run command - // 1. Command Line (docker compose run --env ) - // 2. Compose File (service::environment section) <-- Result expected (From environment patched by .env as a default --env-file value. - // This variable has a default value in case of an absent variable in the OS environment) - // 3. Compose File (service::env_file section file) - // 4. Container Image ENV directive - // 5. Variable is not defined t.Run("shell priority from run command using default value fallback", func(t *testing.T) { c.RunDockerComposeCmd(t, "-f", "./fixtures/environment/env-interpolation-default-value/compose.yaml", "config"). Assert(t, icmd.Expected{Out: `IMAGE: default_env:EnvFileDefaultValue`})