compose: resolve build args from service environment

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2022-01-06 11:59:41 +01:00
parent 3400fa5628
commit 5d715ada96
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
2 changed files with 14 additions and 2 deletions

View File

@ -76,6 +76,9 @@ func ParseCompose(dt []byte) (*Config, error) {
Dockerfile: dockerfilePathP,
Labels: s.Build.Labels,
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]
return val, ok
})),

View File

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