Skip to content

Commit

Permalink
Use build-arg ENV val from local environment if set
Browse files Browse the repository at this point in the history
If a user sets the ENV to be used with the build-arg flag in
the local environment by exporting it, look it up and use the
value set there for that ENV.
Add tests to cover this use case as well.

Signed-off-by: Urvashi Mohnani <[email protected]>
  • Loading branch information
umohnani8 committed Jan 25, 2021
1 parent 1a04337 commit 173881f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 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: 10 additions & 0 deletions tests/bud.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,16 @@ function _test_http() {
expect_output --substring "FROM alpine"
}

@test "bud with build arg ENV set in local environment" {
_prefetch alpine busybox
target=busybox-image
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 with copy-from and cache" {
_prefetch busybox
target=busybox-image
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 173881f

Please sign in to comment.