Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add custom tag for stages image, for build-kit only #160

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ or

- **pull_image_and_stages**: Set to `false` to avoid pulling from the registry or to build from scratch (default: `true`).

- **stages_image_name**: Set custom name for stages/cache image (default: `${image_name}-stages`). Tags are ignored.
- **stages_image_name**: Set custom name for stages/cache image (default: `${image_name}-stages`).

- **stages_image_tag**: Set custom tag for the stages/cache image. (default: latest)"
required: false

- **push_image_and_stages**: Test a command before pushing. Use `false` to not push at all (default: `true`).

Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ inputs:
stages_image_name:
description: "(Optional) Use a custom name for the stages. Useful if using a job matrix (default: ${image_name}-stages)"
required: false
stages_image_tag:
description: "(Optional) Use a custom tag for the stages image. (default: latest)"
required: false
push_git_tag:
description: "(Optional) In addition to `image_tag` value, you can also push current git tag (default: false)"
required: false
Expand Down
12 changes: 8 additions & 4 deletions docker-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,13 @@ _get_stages_image_name() {
echo "${INPUT_STAGES_IMAGE_NAME:-${INPUT_IMAGE_NAME}-stages}"
}

_get_stages_image_tag() {
echo "${INPUT_STAGES_IMAGE_TAG:-latest}"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would make all stages to have tags like latest-1, latest-2, ... under legacy behavior (no buildkit) which I don't see it better than current behav.

}

_get_full_stages_image_name() {
echo "$(_get_image_namespace)$(_get_stages_image_name)"
}
}

_tag() {
local tag
Expand Down Expand Up @@ -167,15 +171,15 @@ _push_image_stages() {
local stage_image
for stage in $(_get_stages); do
echo -e "\nPushing stage: $stage_number"
stage_image=$(_get_full_stages_image_name):$stage_number
stage_image=$(_get_full_stages_image_name):"$(_get_stages_image_tag)"-$stage_number
docker tag "$stage" "$stage_image"
docker push "$stage_image"
stage_number=$(( stage_number+1 ))
done

# push the image itself as a stage (the last one)
echo -e "\nPushing stage: $stage_number"
stage_image=$(_get_full_stages_image_name):$stage_number
stage_image=$(_get_full_stages_image_name):"$(_get_stages_image_tag)"-$stage_number
docker tag "$DUMMY_IMAGE_NAME" "$stage_image"
docker push "$stage_image"
}
Expand Down Expand Up @@ -396,7 +400,7 @@ _build_image_buildkit() {
echo -e "\n[Action Step] Building image with BuildKit..."

local cache_image
cache_image="$(_get_full_stages_image_name)":latest
cache_image="$(_get_full_stages_image_name)":"$(_get_stages_image_tag)"

local cache_from
if _can_pull; then
Expand Down