Skip to content

Commit

Permalink
introduce --no-path-resolution to skip relative path to be resolved
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 May 16, 2023
1 parent 00f72cb commit 9b5a458
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion cmd/compose/compose.go
Expand Up @@ -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),
Expand Down
6 changes: 4 additions & 2 deletions cmd/compose/config.go
Expand Up @@ -40,6 +40,7 @@ type configOptions struct {
resolveImageDigests bool
noInterpolate bool
noNormalize bool
noResolvePath bool
services bool
volumes bool
profiles bool
Expand All @@ -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,
}
Expand Down Expand Up @@ -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.")
Expand Down
1 change: 1 addition & 0 deletions docs/reference/compose_config.md
Expand Up @@ -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. |
Expand Down
10 changes: 10 additions & 0 deletions docs/reference/docker_compose_config.yaml
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -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=
Expand Down
15 changes: 1 addition & 14 deletions pkg/e2e/compose_environment_test.go
Expand Up @@ -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 <KEY[=VAL]>)
// 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 <KEY[=VAL]>)
// 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`})
Expand Down

0 comments on commit 9b5a458

Please sign in to comment.