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

Commit f159bc4

Browse files
committed
Support bypass envvars
Signed-off-by: Ulysses Souza <[email protected]>
1 parent de8834d commit f159bc4

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
@@ -245,22 +245,6 @@ func (e Event) String() string {
245245

246246
}
247247

248-
// EnvironmentMap return RunOptions.Environment as a MappingWithEquals
249-
func (opts *RunOptions) EnvironmentMap() types.MappingWithEquals {
250-
environment := types.MappingWithEquals{}
251-
for _, s := range opts.Environment {
252-
parts := strings.SplitN(s, "=", 2)
253-
key := parts[0]
254-
switch {
255-
case len(parts) == 1:
256-
environment[key] = nil
257-
default:
258-
environment[key] = &parts[1]
259-
}
260-
}
261-
return environment
262-
}
263-
264248
// ListOptions group options of the ls API
265249
type ListOptions struct {
266250
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)