Skip to content

Commit a1761ad

Browse files
authored
fix: no 'overridden by config' warning for X=${X} (#1316)
1 parent 1e1083d commit a1761ad

File tree

14 files changed

+27
-39
lines changed

14 files changed

+27
-39
lines changed

src/pkg/cli/client/mock.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ func (m MockProvider) CreateUploadURL(ctx context.Context, req *defangv1.UploadU
1818
}
1919

2020
func (m MockProvider) ListConfig(ctx context.Context, req *defangv1.ListConfigsRequest) (*defangv1.Secrets, error) {
21-
return &defangv1.Secrets{Names: []string{"VAR1"}}, nil
21+
return &defangv1.Secrets{Names: []string{"CONFIG1", "CONFIG2", "dummy", "ENV1", "SENSITIVE_DATA", "VAR1"}}, nil
2222
}
2323

2424
func (m MockProvider) ServiceDNS(service string) string {
25-
return service
25+
return "mock-" + service
2626
}
2727

2828
// MockServerStream mocks a ServerStream.

src/pkg/cli/compose/fixup.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,13 @@ func FixupServices(ctx context.Context, provider client.Provider, project *compo
9797
}
9898

9999
// Pack the build context into a Archive and upload
100-
url, err := getRemoteBuildContext(ctx, provider, project.Name, svccfg.Name, svccfg.Build, upload)
101-
if err != nil {
102-
return err
100+
if !strings.Contains(svccfg.Build.Context, "://") {
101+
url, err := getRemoteBuildContext(ctx, provider, project.Name, svccfg.Name, svccfg.Build, upload)
102+
if err != nil {
103+
return err
104+
}
105+
svccfg.Build.Context = url
103106
}
104-
svccfg.Build.Context = url
105107

106108
var removedArgs []string
107109
for key, value := range svccfg.Build.Args {
@@ -143,8 +145,8 @@ func FixupServices(ctx context.Context, provider client.Provider, project *compo
143145
delete(svccfg.Environment, key) // remove the empty key; this is safe
144146
continue
145147
}
146-
if value == nil {
147-
continue // will be from config
148+
if value == nil || *value == "${"+key+"}" {
149+
continue // actual value will be from config
148150
}
149151

150152
// Check if the environment variable is an existing config; if so, mark it as such

src/pkg/cli/compose/loader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,14 @@ func (c *Loader) NewProjectOptions() (*cli.ProjectOptions, error) {
156156
if hasSubstitution(templ, key) {
157157
// We don't (yet) support substitution patterns during deployment
158158
if inEnv {
159-
term.Warnf("Environment variable %q is not used; add it to `.env` if needed", key)
159+
term.Warnf("Environment variable %q is ignored; add it to `.env` if needed", key)
160160
} else {
161161
term.Debugf("Unresolved environment variable %q", key)
162162
}
163163
return "", false
164164
}
165165
if inEnv {
166-
term.Warnf("Environment variable %q is not used; add it to `.env` or it may be resolved from config during deployment", key)
166+
term.Warnf("Environment variable %q is ignored; add it to `.env` or it may be resolved from config during deployment", key)
167167
} else {
168168
term.Debugf("Environment variable %q was not resolved locally. It may be resolved from config during deployment", key)
169169
}

src/pkg/cli/compose/validation_test.go

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,6 @@ import (
1616
composeTypes "github.com/compose-spec/compose-go/v2/types"
1717
)
1818

19-
type validationMockProvider struct {
20-
client.Provider
21-
configs []string
22-
}
23-
24-
func (m validationMockProvider) ListConfig(ctx context.Context, req *defangv1.ListConfigsRequest) (*defangv1.Secrets, error) {
25-
return &defangv1.Secrets{
26-
Names: m.configs,
27-
Project: "mock-project",
28-
}, nil
29-
}
30-
31-
func (m validationMockProvider) ServiceDNS(name string) string {
32-
return "mock-" + name
33-
}
34-
3519
func TestValidationAndConvert(t *testing.T) {
3620
oldTerm := term.DefaultTerm
3721
t.Cleanup(func() {
@@ -40,9 +24,7 @@ func TestValidationAndConvert(t *testing.T) {
4024

4125
t.Setenv("NODE_ENV", "if-you-see-this-env-was-used") // for interpolate/compose.yaml; should be ignored
4226

43-
mockClient := validationMockProvider{
44-
configs: []string{"CONFIG1", "CONFIG2", "dummy", "ENV1", "SENSITIVE_DATA"},
45-
}
27+
mockClient := client.MockProvider{}
4628
listConfigNamesFunc := func(ctx context.Context) ([]string, error) {
4729
configs, err := mockClient.ListConfig(ctx, &defangv1.ListConfigsRequest{})
4830
if err != nil {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
! service "service1": environment variable(s) ["VAR1"] overridden by config
12
! service "service1": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors

src/testdata/fixupenv/compose.yaml.fixup

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"command": null,
1919
"entrypoint": null,
2020
"environment": {
21-
"CONFIG1": "http://mistral:8000"
21+
"CONFIG1": null
2222
},
2323
"image": "service:latest",
2424
"networks": {
@@ -30,7 +30,7 @@
3030
"context": ".",
3131
"dockerfile": "Dockerfile",
3232
"args": {
33-
"API_URL": "http://mistral:8000"
33+
"API_URL": "http://mock-mistral:8000"
3434
}
3535
},
3636
"command": null,
@@ -59,7 +59,7 @@
5959
"command": null,
6060
"entrypoint": null,
6161
"environment": {
62-
"API_URL": "http://mistral:8000",
62+
"API_URL": "http://mock-mistral:8000",
6363
"SENSITIVE_DATA": null
6464
},
6565
"image": "ui:latest",

src/testdata/interpolate/compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ services:
1111
- NOP_BRACED=abc$${def} # FIXME: this should not get resolved in CD
1212
- NODE_ENV=${NODE_ENV}
1313
- PORT=${PORT:-8080}
14+
- VAR1=${VAR1} # from config

src/testdata/interpolate/compose.yaml.fixup

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"NOP": "abc$def",
1111
"NOP_BRACED": "abc${def}",
1212
"PORT": "8080",
13+
"VAR1": "${VAR1}",
1314
"interpolate": "value"
1415
},
1516
"image": "alpine",

src/testdata/interpolate/compose.yaml.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ services:
99
NOP: abc$def
1010
NOP_BRACED: abc${def}
1111
PORT: "8080"
12+
VAR1: ${VAR1}
1213
interpolate: value
1314
image: alpine
1415
networks:
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
! Environment variable "NODE_ENV" is not used; add it to `.env` if needed
2-
! Environment variable "NODE_ENV" is not used; add it to `.env` or it may be resolved from config during deployment
1+
! Environment variable "NODE_ENV" is ignored; add it to `.env` if needed
2+
! Environment variable "NODE_ENV" is ignored; add it to `.env` or it may be resolved from config during deployment
33
! service "interpolate": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
44
missing configs ["NODE_ENV" "POSTGRES_PASSWORD" "def"] (https://docs.defang.io/docs/concepts/configuration)

0 commit comments

Comments
 (0)