Skip to content

Commit

Permalink
Merge pull request #2932 from umohnani8/1.19
Browse files Browse the repository at this point in the history
[release-1.19] Use build-arg ENV val from local environment if set
  • Loading branch information
openshift-merge-robot authored Jan 25, 2021
2 parents ae20f06 + c868696 commit 2c6ecfe
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
7 changes: 6 additions & 1 deletion cmd/buildah/bud.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ func budCmd(c *cobra.Command, inputArgs []string, iopts budOptions) error {
if len(av) > 1 {
args[av[0]] = av[1]
} else {
delete(args, av[0])
// check if the env is set in the local environment and use that value if it is
if val, present := os.LookupEnv(av[0]); present {
args[av[0]] = val
} else {
delete(args, av[0])
}
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions tests/bud.bats
Original file line number Diff line number Diff line change
Expand Up @@ -2154,9 +2154,15 @@ EOM
}

@test "bud with --build-arg" {
_prefetch alpine
run_buildah --log-level "warn" bud --signature-policy ${TESTSDIR}/policy.json -t test ${TESTSDIR}/bud/build-arg
_prefetch alpine busybox
target=busybox-image
run_buildah --log-level "warn" bud --signature-policy ${TESTSDIR}/policy.json -t ${target} ${TESTSDIR}/bud/build-arg
expect_output --substring 'missing .+ build argument'
run_buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} --build-arg foo=bar ${TESTSDIR}/bud/build-arg
expect_output --substring "bar"
export foo=hello-world
run_buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} --build-arg foo ${TESTSDIR}/bud/build-arg
expect_output --substring "hello-world"
}

@test "bud arg and env var with same name" {
Expand Down
2 changes: 1 addition & 1 deletion tests/bud/build-arg/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM busybox

ARG foo
RUN echo $foo

0 comments on commit 2c6ecfe

Please sign in to comment.