Skip to content

Commit d784aba

Browse files
committed
Forward LOCALSTACK_* env variables from host to emulator container
1 parent 7c026f0 commit d784aba

2 files changed

Lines changed: 15 additions & 13 deletions

File tree

internal/container/start.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ func Start(ctx context.Context, rt runtime.Runtime, sink output.Sink, opts Start
9696

9797
tel := opts.Telemetry
9898

99+
var hostEnv []string
100+
for _, e := range os.Environ() {
101+
if strings.HasPrefix(e, "CI=") || (strings.HasPrefix(e, "LOCALSTACK_") && !strings.HasPrefix(e, "LOCALSTACK_AUTH_TOKEN=")) {
102+
hostEnv = append(hostEnv, e)
103+
}
104+
}
105+
99106
containers := make([]runtime.ContainerConfig, len(opts.Containers))
100107
for i, c := range opts.Containers {
101108
image, err := c.Image()
@@ -128,10 +135,7 @@ func Start(ctx context.Context, rt runtime.Runtime, sink output.Sink, opts Start
128135
"MAIN_CONTAINER_NAME="+containerName,
129136
)
130137

131-
// Forward CI environment variable if set on the host
132-
if ci := os.Getenv("CI"); ci != "" {
133-
env = append(env, "CI="+ci)
134-
}
138+
env = append(env, hostEnv...)
135139

136140
var binds []runtime.BindMount
137141
if socketPath := rt.SocketPath(); socketPath != "" {

internal/container/start_test.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,20 @@ func TestForwardCIEnvVariable(t *testing.T) {
7272
defer os.Setenv("CI", originalCI)
7373

7474
tests := []struct {
75-
name string
76-
ciValue string
77-
wantCI bool
78-
wantCIVals []string
75+
name string
76+
ciValue string
77+
wantCI bool
7978
}{
80-
{"CI=true", "true", true, []string{"true"}},
81-
{"CI=1", "1", true, []string{"1"}},
82-
{"CI=false", "false", true, []string{"false"}},
83-
{"CI unset", "", false, nil},
79+
{"CI=true", "true", true},
80+
{"CI=1", "1", true},
81+
{"CI=false", "false", true},
82+
{"CI unset", "", false},
8483
}
8584

8685
for _, tt := range tests {
8786
t.Run(tt.name, func(t *testing.T) {
8887
os.Setenv("CI", tt.ciValue)
8988

90-
// Simulate the env building logic from start.go:136-139
9189
env := []string{"LOCALSTACK_AUTH_TOKEN=test"}
9290
if ci := os.Getenv("CI"); ci != "" {
9391
env = append(env, "CI="+ci)

0 commit comments

Comments
 (0)