compose: resolve build args from service environment

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
pull/905/head
CrazyMax 3 years ago
parent 3400fa5628
commit 5d715ada96
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7

@ -76,6 +76,9 @@ func ParseCompose(dt []byte) (*Config, error) {
Dockerfile: dockerfilePathP, Dockerfile: dockerfilePathP,
Labels: s.Build.Labels, Labels: s.Build.Labels,
Args: flatten(s.Build.Args.Resolve(func(val string) (string, bool) { Args: flatten(s.Build.Args.Resolve(func(val string) (string, bool) {
if val, ok := s.Environment[val]; ok && val != nil {
return *val, true
}
val, ok := cfg.Environment[val] val, ok := cfg.Environment[val]
return val, ok return val, ok
})), })),

@ -280,7 +280,7 @@ services:
require.Equal(t, c.Targets[1].NoCache, newBool(true)) require.Equal(t, c.Targets[1].NoCache, newBool(true))
} }
func TestEnvFile(t *testing.T) { func TestEnv(t *testing.T) {
envf, err := os.CreateTemp("", "env") envf, err := os.CreateTemp("", "env")
require.NoError(t, err) require.NoError(t, err)
defer os.Remove(envf.Name()) defer os.Remove(envf.Name())
@ -293,12 +293,21 @@ services:
scratch: scratch:
build: build:
context: . context: .
args:
CT_ECR: foo
FOO:
NODE_ENV:
environment:
- NODE_ENV=test
- AWS_ACCESS_KEY_ID=dummy
- AWS_SECRET_ACCESS_KEY=dummy
env_file: env_file:
- ` + envf.Name() + ` - ` + envf.Name() + `
`) `)
_, err = ParseCompose(dt) c, err := ParseCompose(dt)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, c.Targets[0].Args, map[string]string{"CT_ECR": "foo", "FOO": "bsdf -csdf", "NODE_ENV": "test"})
} }
func newBool(val bool) *bool { func newBool(val bool) *bool {

Loading…
Cancel
Save