1
0
Fork 0
mirror of https://github.com/aevea/action-kaniko.git synced 2025-01-31 06:09:39 +01:00

Allow multiple tags

This commit is contained in:
SIRICA1 2023-05-02 15:44:27 +01:00
parent 78060c4e9d
commit 9ffe94bf27
3 changed files with 65 additions and 55 deletions

View file

@ -21,8 +21,8 @@ inputs:
image: image:
description: "Image name" description: "Image name"
required: true required: true
tag: tags:
description: "Image tag" description: "List of Image tags"
required: false required: false
cache: cache:
description: "Enables build cache" description: "Enables build cache"

View file

@ -7,13 +7,12 @@ fi
export REGISTRY=${INPUT_REGISTRY:-"docker.io"} export REGISTRY=${INPUT_REGISTRY:-"docker.io"}
export IMAGE=${INPUT_IMAGE} export IMAGE=${INPUT_IMAGE}
export BRANCH=$(echo ${GITHUB_REF} | sed -E "s/refs\/(heads|tags)\///g" | sed -e "s/\//-/g") export BRANCH=$(echo ${GITHUB_REF} | sed -E "s/refs\/(heads|tags)\///g" | sed -e "s/\//-/g")
export TAG=${INPUT_TAG:-$([ "$BRANCH" == "master" ] && echo latest || echo $BRANCH)} export TAGS=${INPUT_TAGS:-$([ "$BRANCH" == "master" ] && echo latest || echo $BRANCH)}
export TAG=${TAG:-"latest"} export TAGS=${TAGS:-"latest"}
export TAG=${TAG#$INPUT_STRIP_TAG_PREFIX} export TAGS=${TAGS#$INPUT_STRIP_TAG_PREFIX}
export USERNAME=${INPUT_USERNAME:-$GITHUB_ACTOR} export USERNAME=${INPUT_USERNAME:-$GITHUB_ACTOR}
export PASSWORD=${INPUT_PASSWORD:-$GITHUB_TOKEN} export PASSWORD=${INPUT_PASSWORD:-$GITHUB_TOKEN}
export REPOSITORY=$IMAGE export REPOSITORY=$IMAGE
export IMAGE=$IMAGE:$TAG
export CONTEXT_PATH=${INPUT_PATH} export CONTEXT_PATH=${INPUT_PATH}
if [[ "$INPUT_TAG_WITH_LATEST" == "true" ]]; then if [[ "$INPUT_TAG_WITH_LATEST" == "true" ]]; then
@ -31,12 +30,30 @@ ensure "${REGISTRY}" "registry"
ensure "${USERNAME}" "username" ensure "${USERNAME}" "username"
ensure "${PASSWORD}" "password" ensure "${PASSWORD}" "password"
ensure "${IMAGE}" "image" ensure "${IMAGE}" "image"
ensure "${TAG}" "tag" ensure "${TAGS}" "tags"
ensure "${CONTEXT_PATH}" "path" ensure "${CONTEXT_PATH}" "path"
# Set credentials here
cat <<EOF >/kaniko/.docker/config.json
{
"auths": {
"https://${REGISTRY}": {
"username": "${USERNAME}",
"password": "${PASSWORD}"
}
}
}
EOF
tags=$(echo $TAGS | tr "," "\n")
for tag in $tags; do
export TAGGED_IMAGE=$IMAGE:$tag
if [ "$REGISTRY" == "ghcr.io" ]; then if [ "$REGISTRY" == "ghcr.io" ]; then
IMAGE_NAMESPACE="$(echo $GITHUB_REPOSITORY | tr '[:upper:]' '[:lower:]')" IMAGE_NAMESPACE="$(echo $GITHUB_REPOSITORY | tr '[:upper:]' '[:lower:]')"
export IMAGE="$IMAGE_NAMESPACE/$IMAGE" export TAGGED_IMAGE="$IMAGE_NAMESPACE/$IMAGE"
export REPOSITORY="$IMAGE_NAMESPACE/$REPOSITORY" export REPOSITORY="$IMAGE_NAMESPACE/$REPOSITORY"
if [ ! -z $IMAGE_LATEST ]; then if [ ! -z $IMAGE_LATEST ]; then
@ -51,13 +68,17 @@ fi
if [ "$REGISTRY" == "docker.io" ]; then if [ "$REGISTRY" == "docker.io" ]; then
export REGISTRY="index.${REGISTRY}/v1/" export REGISTRY="index.${REGISTRY}/v1/"
else else
export IMAGE="$REGISTRY/$IMAGE" export TAGGED_IMAGE="$REGISTRY/$TAGGED_IMAGE"
if [ ! -z $IMAGE_LATEST ]; then if [ ! -z $IMAGE_LATEST ]; then
export IMAGE_LATEST="$REGISTRY/$IMAGE_LATEST" export IMAGE_LATEST="$REGISTRY/$IMAGE_LATEST"
fi fi
fi fi
export DESTINATIONS="$DESTINATIONS --destination $TAGGED_IMAGE"
done
export CACHE=${INPUT_CACHE:+"--cache=true"} export CACHE=${INPUT_CACHE:+"--cache=true"}
export CACHE=$CACHE${INPUT_CACHE_TTL:+" --cache-ttl=$INPUT_CACHE_TTL"} export CACHE=$CACHE${INPUT_CACHE_TTL:+" --cache-ttl=$INPUT_CACHE_TTL"}
export CACHE=$CACHE${INPUT_CACHE_REGISTRY:+" --cache-repo=$INPUT_CACHE_REGISTRY"} export CACHE=$CACHE${INPUT_CACHE_REGISTRY:+" --cache-repo=$INPUT_CACHE_REGISTRY"}
@ -67,27 +88,16 @@ export DOCKERFILE="--dockerfile $CONTEXT_PATH/${INPUT_BUILD_FILE:-Dockerfile}"
export TARGET=${INPUT_TARGET:+"--target=$INPUT_TARGET"} export TARGET=${INPUT_TARGET:+"--target=$INPUT_TARGET"}
if [ ! -z $INPUT_SKIP_UNCHANGED_DIGEST ]; then if [ ! -z $INPUT_SKIP_UNCHANGED_DIGEST ]; then
export DESTINATION="--digest-file digest --no-push --tarPath image.tar --destination $IMAGE" export DESTINATION="--digest-file digest --no-push --tarPath image.tar $DESTINATIONS"
else else
export DESTINATION="--destination $IMAGE" export DESTINATION=$DESTINATIONS
if [ ! -z $IMAGE_LATEST ]; then if [ ! -z $IMAGE_LATEST ]; then
export DESTINATION="$DESTINATION --destination $IMAGE_LATEST" export DESTINATION="$DESTINATIONS --destination $IMAGE_LATEST"
fi fi
fi fi
export ARGS="$CACHE $CONTEXT $DOCKERFILE $TARGET $DESTINATION $INPUT_EXTRA_ARGS" export ARGS="$CACHE $CONTEXT $DOCKERFILE $TARGET $DESTINATION $INPUT_EXTRA_ARGS"
cat <<EOF >/kaniko/.docker/config.json
{
"auths": {
"https://${REGISTRY}": {
"username": "${USERNAME}",
"password": "${PASSWORD}"
}
}
}
EOF
# https://github.com/GoogleContainerTools/kaniko/issues/1349 # https://github.com/GoogleContainerTools/kaniko/issues/1349
/kaniko/executor --reproducible --force $ARGS /kaniko/executor --reproducible --force $ARGS
@ -106,7 +116,7 @@ if [ ! -z $INPUT_SKIP_UNCHANGED_DIGEST ]; then
echo "Pushing image..." echo "Pushing image..."
/kaniko/crane push image.tar $IMAGE /kaniko/crane push image.tar $TAGGED_IMAGE
if [ ! -z $IMAGE_LATEST ]; then if [ ! -z $IMAGE_LATEST ]; then
echo "Tagging latest..." echo "Tagging latest..."