Skip to content

Commit

Permalink
Merge pull request #137 from whoan/issue-134
Browse files Browse the repository at this point in the history
Issue 134
  • Loading branch information
whoan authored Oct 15, 2023
2 parents 950f8e2 + 806baa9 commit 3c6917f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand Down
21 changes: 21 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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

0 comments on commit 3c6917f

Please sign in to comment.