Skip to content

Commit

Permalink
sanitize image tags for github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
nqb committed Dec 27, 2022
1 parent 4c74909 commit ab4f91b
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions containers/kanikobuild
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ detect_multi_tags() {
multi_tags=$(echo $IMAGE_TAGS|grep -o ','|wc -l)
}

sanitize_tag() {
local tag=$1
echo $tag | tr A-Z a-z | tr -c a-z0-9\\n -
}


# support multi-tags
# https://github.com/GoogleContainerTools/kaniko/issues/217
generate_destinations() {
Expand All @@ -61,16 +67,18 @@ generate_destinations() {
# Multi-tags detected, parsing ${IMAGE_TAGS}"
TAGS=$(echo $IMAGE_TAGS | tr ',' ' ')
for tag in ${TAGS}; do
tag_slug=$(sanitize_tag $tag)
# just to handle case of first iteration
if [ -z "$destinations" ]; then
destinations="--destination ${KNK_REGISTRY_URL}/${IMAGE_NAME}:${tag}"
destinations="--destination ${KNK_REGISTRY_URL}/${IMAGE_NAME}:${tag_slug}"
else
destinations="$destinations --destination ${KNK_REGISTRY_URL}/${IMAGE_NAME}:${tag}"
destinations="$destinations --destination ${KNK_REGISTRY_URL}/${IMAGE_NAME}:${tag_slug}"
fi
done
else
# Only one tag detected, using ${IMAGE_TAG} as tag
IMAGE_DEST="${KNK_REGISTRY_URL}/${IMAGE_NAME}:${IMAGE_TAG}"
tag_slug=$(sanitize_tag ${IMAGE_TAG})
IMAGE_DEST="${KNK_REGISTRY_URL}/${IMAGE_NAME}:${tag_slug}"
destinations="--destination ${IMAGE_DEST}"
fi
echo "$destinations"
Expand Down

0 comments on commit ab4f91b

Please sign in to comment.