diff --git a/docs/cicd_tools/image_builder.md b/docs/cicd_tools/image_builder.md index dd4017f0..e3005703 100644 --- a/docs/cicd_tools/image_builder.md +++ b/docs/cicd_tools/image_builder.md @@ -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 @@ -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` \ No newline at end of file +`registry/repository_org/repository_name:default_tag` diff --git a/src/shared/image_builder.sh b/src/shared/image_builder.sh index a9595c88..030e651a 100644 --- a/src/shared/image_builder.sh +++ b/src/shared/image_builder.sh @@ -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 @@ -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 diff --git a/test/shared_image_builder.bats b/test/shared_image_builder.bats index f9c08620..440474b5 100644 --- a/test/shared_image_builder.bats +++ b/test/shared_image_builder.bats @@ -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" +}