Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit db6978a

Browse files
authored
Merge pull request #1628 from ulyssessouza/add-bypass-envvar
Support bypass envvars
2 parents 9432716 + f159bc4 commit db6978a

File tree

3 files changed

+10
-20
lines changed

3 files changed

+10
-20
lines changed

api/compose/api.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -247,22 +247,6 @@ func (e Event) String() string {
247247

248248
}
249249

250-
// EnvironmentMap return RunOptions.Environment as a MappingWithEquals
251-
func (opts *RunOptions) EnvironmentMap() types.MappingWithEquals {
252-
environment := types.MappingWithEquals{}
253-
for _, s := range opts.Environment {
254-
parts := strings.SplitN(s, "=", 2)
255-
key := parts[0]
256-
switch {
257-
case len(parts) == 1:
258-
environment[key] = nil
259-
default:
260-
environment[key] = &parts[1]
261-
}
262-
}
263-
return environment
264-
}
265-
266250
// ListOptions group options of the ls API
267251
type ListOptions struct {
268252
All bool

api/compose/api_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package compose
1919
import (
2020
"testing"
2121

22+
"github.com/compose-spec/compose-go/types"
2223
"gotest.tools/v3/assert"
2324
)
2425

@@ -30,7 +31,7 @@ func TestRunOptionsEnvironmentMap(t *testing.T) {
3031
"QIX",
3132
},
3233
}
33-
env := opts.EnvironmentMap()
34+
env := types.NewMappingWithEquals(opts.Environment)
3435
assert.Equal(t, *env["FOO"], "BAR")
3536
assert.Equal(t, *env["ZOT"], "")
3637
assert.Check(t, env["QIX"] == nil)

local/compose/run.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (s *composeService) RunOneOffContainer(ctx context.Context, project *types.
4242
return 0, err
4343
}
4444

45-
applyRunOptions(&service, opts)
45+
applyRunOptions(project, &service, opts)
4646

4747
slug := moby.GenerateRandomID()
4848
if service.ContainerName == "" {
@@ -107,7 +107,7 @@ func (s *composeService) RunOneOffContainer(ctx context.Context, project *types.
107107

108108
}
109109

110-
func applyRunOptions(service *types.ServiceConfig, opts compose.RunOptions) {
110+
func applyRunOptions(project *types.Project, service *types.ServiceConfig, opts compose.RunOptions) {
111111
service.Tty = opts.Tty
112112
service.ContainerName = opts.Name
113113

@@ -124,7 +124,12 @@ func applyRunOptions(service *types.ServiceConfig, opts compose.RunOptions) {
124124
service.Entrypoint = opts.Entrypoint
125125
}
126126
if len(opts.Environment) > 0 {
127-
service.Environment.OverrideBy(opts.EnvironmentMap())
127+
env := types.NewMappingWithEquals(opts.Environment)
128+
projectEnv := env.Resolve(func(s string) (string, bool) {
129+
v, ok := project.Environment[s]
130+
return v, ok
131+
}).RemoveEmpty()
132+
service.Environment.OverrideBy(projectEnv)
128133
}
129134
for k, v := range opts.Labels {
130135
service.Labels.Add(k, v)

0 commit comments

Comments
 (0)