diff --git a/README.md b/README.md index b38b937..060f3e1 100644 --- a/README.md +++ b/README.md @@ -50,13 +50,6 @@ or - **stages_image_name**: Set custom name for stages. Useful if using a job matrix (default: `$image_name-stages)`. -- **build_extra_args**: Extra params for `docker build` (e.g. `"--build-arg=hello=world"`). - > :star2: New in v5.11.0: If you need extra args with newlines or spaces, use json format like this: - `build_extra_args: '{"--build-arg": "myarg=Hello\nWorld"}'` - - > :star2: If you need multiple args with same key, use an array as the value of the key like this: - `build_extra_args: '{"--build-arg": ["foo=bar", "one=two"]}'` - - **push_image_and_stages**: Test a command before pushing. Use `false` to not push at all (default: `true`). This input also supports 2 special values, which are useful if your workflow can be triggered by different events: @@ -74,6 +67,13 @@ or - **dockerfile**: Dockerfile filename path (default: `"$context"/Dockerfile`). +- **build_extra_args**: Extra params for `docker build` (e.g. `"--build-arg=hello=world"`). + > :star2: New in v5.11.0: If you need extra args with newlines or spaces, use json format like this: + `build_extra_args: '{"--build-arg": "myarg=Hello\nWorld"}'` + + > :star2: If you need multiple args with same key, use an array as the value of the key like this: + `build_extra_args: '{"--build-arg": ["foo=bar", "one=two"]}'` + ## Outputs - **FULL_IMAGE_NAME**: Full name of the Docker Image with the Registry (if provided) and Namespace included. diff --git a/entrypoint.sh b/entrypoint.sh index 7d63a04..3009115 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -109,16 +109,20 @@ _set_variables() { INPUT_DOCKERFILE=$(_get_dockerfile_by_service_name "$service_name") INPUT_DOCKERFILE=${INPUT_DOCKERFILE:-Dockerfile} + INPUT_BUILD_EXTRA_ARGS=$(_get_args_by_service_name "$service_name") + echo "Exporting variables:" echo "INPUT_IMAGE_NAME=$INPUT_IMAGE_NAME" echo "INPUT_IMAGE_TAG=$INPUT_IMAGE_TAG" echo "INPUT_CONTEXT=$INPUT_CONTEXT" echo "INPUT_DOCKERFILE=$INPUT_DOCKERFILE" + echo "INPUT_BUILD_EXTRA_ARGS=$INPUT_BUILD_EXTRA_ARGS" export INPUT_IMAGE_NAME export INPUT_IMAGE_TAG export INPUT_CONTEXT export INPUT_DOCKERFILE + export INPUT_BUILD_EXTRA_ARGS } _get_service_name_by_image_name() { @@ -150,5 +154,22 @@ _get_dockerfile_by_service_name() { _yq e ".services.${service_name}.build.dockerfile // \"\"" "$merged_compose" || true } +_get_args_by_service_name() { + local service_name + service_name="${1:?I need a service name}" + + local args_json + while IFS=": " read -r arg val; do + [ -z "$arg" ] && continue + args_json=$( + jq \ + --arg key "--build-arg" \ + --arg value "$arg=$val" \ + '.[$key] += [$value]' <<< "${args_json:-"{}"}" + ) + done < <(_yq e ".services.${service_name}.build.args // \"\"" "$merged_compose") + echo "$args_json" +} + _yq --version build_from_compose_file