Skip to content

Commit

Permalink
Support extra build args (#41)
Browse files Browse the repository at this point in the history
* Add test for new feature

* Support extra build args

* Support additional build args

* Support extra build arg in build_and_push
  • Loading branch information
Victoremepunto authored Oct 30, 2023
1 parent ddab068 commit aeb9fe8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
12 changes: 11 additions & 1 deletion docs/cicd_tools/image_builder.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,16 @@ the provided configuration

#### cicd::container::build

Accepts any number of parameters, will be appended to the final `build` command

**Note** this is to allow extra arguments not directly supported by the library.

```shell
cicd::image_builder::build --extra-arg1 param1=value1 --param-2

# will add --extra-arg1 param1=value1 --param2 to the resulting image build command
```

This will build a container image using the provided configuration

#### cicd::container::tag
Expand Down Expand Up @@ -337,4 +347,4 @@ Returns the list of build arguments when building a new image

Returns the Image name including the default tag in the format

`registry/repository_org/repository_name:default_tag`
`registry/repository_org/repository_name:default_tag`
4 changes: 3 additions & 1 deletion src/shared/image_builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ cicd::image_builder::local_build() {
}

cicd::image_builder::build_and_push() {
cicd::image_builder::build || return 1
cicd::image_builder::build "$@" || return 1
if ! cicd::image_builder::local_build; then
cicd::image_builder::push || return 1
fi
Expand Down Expand Up @@ -66,6 +66,8 @@ cicd::image_builder::build() {
build_params+=('--build-arg' "${build_arg}")
done

build_params+=("$@")

build_params+=("$build_context")

if ! cicd::container::cmd build "${build_params[@]}"; then
Expand Down
34 changes: 34 additions & 0 deletions test/shared_image_builder.bats
Original file line number Diff line number Diff line change
Expand Up @@ -694,3 +694,37 @@ setup() {
assert_output --regexp "^build.*-t foobar:pr-123-extra1"
assert_output --regexp "^build.*-t foobar:pr-123-extra2"
}

@test "Support extra build args for build" {

# podman mock
podman() {
echo "$@"
}

source load_module.sh image_builder

export CICD_IMAGE_BUILDER_IMAGE_NAME='foobar'
export CICD_IMAGE_BUILDER_CONTAINERFILE_PATH='test/data/Containerfile.test'

run cicd::image_builder::build --some-extra-arg1 foo=foo:bar --another-extra-arg foobar=bazbar

assert_output --regexp "^build.*--some-extra-arg1 foo=foo:bar --another-extra-arg foobar=bazbar"
}

@test "Support extra build args for build_and_push" {

# podman mock
podman() {
echo "$@"
}

source load_module.sh image_builder

export CICD_IMAGE_BUILDER_IMAGE_NAME='foobar'
export CICD_IMAGE_BUILDER_CONTAINERFILE_PATH='test/data/Containerfile.test'

run cicd::image_builder::build_and_push --some-extra-arg1 foo=foo:bar --another-extra-arg foobar=bazbar

assert_output --regexp "^build.*--some-extra-arg1 foo=foo:bar --another-extra-arg foobar=bazbar"
}

0 comments on commit aeb9fe8

Please sign in to comment.