Browse Source

introduce config --no-env-resolution

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof 8 months ago
parent
commit
a0d1c3f944

+ 9 - 0
cmd/compose/config.go

@@ -47,6 +47,7 @@ type configOptions struct {
 	noInterpolate       bool
 	noNormalize         bool
 	noResolvePath       bool
+	noResolveEnv        bool
 	services            bool
 	volumes             bool
 	profiles            bool
@@ -135,6 +136,7 @@ func configCommand(p *ProjectOptions, dockerCli command.Cli) *cobra.Command {
 	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.noResolveEnv, "no-env-resolution", false, "Don't resolve service env files")
 
 	flags.BoolVar(&opts.services, "services", false, "Print the service names, one per line.")
 	flags.BoolVar(&opts.volumes, "volumes", false, "Print the volume names, one per line.")
@@ -190,6 +192,13 @@ func runConfigInterpolate(ctx context.Context, dockerCli command.Cli, opts confi
 		}
 	}
 
+	if !opts.noResolveEnv {
+		project, err = project.WithServicesEnvironmentResolved(true)
+		if err != nil {
+			return nil, err
+		}
+	}
+
 	if !opts.noConsistency {
 		err := project.CheckContainerNameUnicity()
 		if err != nil {

+ 1 - 0
docs/reference/compose_config.md

@@ -19,6 +19,7 @@ the canonical format.
 | `--hash`                  | `string` |         | Print the service config hash, one per line.                                |
 | `--images`                | `bool`   |         | Print the image names, one per line.                                        |
 | `--no-consistency`        | `bool`   |         | Don't check model consistency - warning: may produce invalid Compose output |
+| `--no-env-resolution`     | `bool`   |         | Don't resolve service env files                                             |
 | `--no-interpolate`        | `bool`   |         | Don't interpolate environment variables                                     |
 | `--no-normalize`          | `bool`   |         | Don't normalize compose model                                               |
 | `--no-path-resolution`    | `bool`   |         | Don't resolve file paths                                                    |

+ 10 - 0
docs/reference/docker_compose_config.yaml

@@ -59,6 +59,16 @@ options:
       experimentalcli: false
       kubernetes: false
       swarm: false
+    - option: no-env-resolution
+      value_type: bool
+      default_value: "false"
+      description: Don't resolve service env files
+      deprecated: false
+      hidden: false
+      experimental: false
+      experimentalcli: false
+      kubernetes: false
+      swarm: false
     - option: no-interpolate
       value_type: bool
       default_value: "false"

+ 3 - 0
pkg/compose/run.go

@@ -151,6 +151,9 @@ func applyRunOptions(project *types.Project, service *types.ServiceConfig, opts
 			v, ok := envResolver(project.Environment)(s)
 			return v, ok
 		}).RemoveEmpty()
+		if service.Environment == nil {
+			service.Environment = types.MappingWithEquals{}
+		}
 		service.Environment.OverrideBy(serviceOverrideEnv)
 	}
 	for k, v := range opts.Labels {