Skip to content

Commit a0d1c3f

Browse files
ndeloofglours
authored andcommitted
introduce config --no-env-resolution
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
1 parent 0c5bd16 commit a0d1c3f

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

cmd/compose/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type configOptions struct {
4747
noInterpolate bool
4848
noNormalize bool
4949
noResolvePath bool
50+
noResolveEnv bool
5051
services bool
5152
volumes bool
5253
profiles bool
@@ -135,6 +136,7 @@ func configCommand(p *ProjectOptions, dockerCli command.Cli) *cobra.Command {
135136
flags.BoolVar(&opts.noNormalize, "no-normalize", false, "Don't normalize compose model")
136137
flags.BoolVar(&opts.noResolvePath, "no-path-resolution", false, "Don't resolve file paths")
137138
flags.BoolVar(&opts.noConsistency, "no-consistency", false, "Don't check model consistency - warning: may produce invalid Compose output")
139+
flags.BoolVar(&opts.noResolveEnv, "no-env-resolution", false, "Don't resolve service env files")
138140

139141
flags.BoolVar(&opts.services, "services", false, "Print the service names, one per line.")
140142
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
190192
}
191193
}
192194

195+
if !opts.noResolveEnv {
196+
project, err = project.WithServicesEnvironmentResolved(true)
197+
if err != nil {
198+
return nil, err
199+
}
200+
}
201+
193202
if !opts.noConsistency {
194203
err := project.CheckContainerNameUnicity()
195204
if err != nil {

docs/reference/compose_config.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ the canonical format.
1919
| `--hash` | `string` | | Print the service config hash, one per line. |
2020
| `--images` | `bool` | | Print the image names, one per line. |
2121
| `--no-consistency` | `bool` | | Don't check model consistency - warning: may produce invalid Compose output |
22+
| `--no-env-resolution` | `bool` | | Don't resolve service env files |
2223
| `--no-interpolate` | `bool` | | Don't interpolate environment variables |
2324
| `--no-normalize` | `bool` | | Don't normalize compose model |
2425
| `--no-path-resolution` | `bool` | | Don't resolve file paths |

docs/reference/docker_compose_config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ options:
5959
experimentalcli: false
6060
kubernetes: false
6161
swarm: false
62+
- option: no-env-resolution
63+
value_type: bool
64+
default_value: "false"
65+
description: Don't resolve service env files
66+
deprecated: false
67+
hidden: false
68+
experimental: false
69+
experimentalcli: false
70+
kubernetes: false
71+
swarm: false
6272
- option: no-interpolate
6373
value_type: bool
6474
default_value: "false"

pkg/compose/run.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ func applyRunOptions(project *types.Project, service *types.ServiceConfig, opts
151151
v, ok := envResolver(project.Environment)(s)
152152
return v, ok
153153
}).RemoveEmpty()
154+
if service.Environment == nil {
155+
service.Environment = types.MappingWithEquals{}
156+
}
154157
service.Environment.OverrideBy(serviceOverrideEnv)
155158
}
156159
for k, v := range opts.Labels {

0 commit comments

Comments
 (0)