Preliminary cleanup of plugin.sh

This commit is contained in:
Kevin Dorner 2022-09-09 09:22:16 +02:00
parent bbbc4fa453
commit 2bac030dfd

View File

@ -4,12 +4,12 @@ set -euo pipefail
export PATH=$PATH:/kaniko/ export PATH=$PATH:/kaniko/
REGISTRY=${PLUGIN_REGISTRY:-index.docker.io} REGISTRY=${PLUGIN_REGISTRY:-docker.io}
if [ "${PLUGIN_USERNAME:-}" ] || [ "${PLUGIN_PASSWORD:-}" ]; then if [ "${PLUGIN_USERNAME:-}" ] || [ "${PLUGIN_PASSWORD:-}" ]; then
DOCKER_AUTH=`echo -n "${PLUGIN_USERNAME}:${PLUGIN_PASSWORD}" | base64 | tr -d "\n"` DOCKER_AUTH=`echo -n "${PLUGIN_USERNAME}:${PLUGIN_PASSWORD}" | base64 | tr -d "\n"`
cat > /kaniko/.docker/config.json <<DOCKERJSON cat > /kaniko/.docker/config.json <<EOF
{ {
"auths": { "auths": {
"${REGISTRY}": { "${REGISTRY}": {
@ -17,7 +17,7 @@ if [ "${PLUGIN_USERNAME:-}" ] || [ "${PLUGIN_PASSWORD:-}" ]; then
} }
} }
} }
DOCKERJSON EOF
fi fi
if [ "${PLUGIN_JSON_KEY:-}" ];then if [ "${PLUGIN_JSON_KEY:-}" ];then
@ -58,18 +58,19 @@ if [ -n "${PLUGIN_BUILD_ARGS_FROM_ENV:-}" ]; then
BUILD_ARGS_FROM_ENV=$(echo "${PLUGIN_BUILD_ARGS_FROM_ENV}" | tr ',' '\n' | while read build_arg; do echo "--build-arg ${build_arg}=$(eval "echo \$$build_arg")"; done) BUILD_ARGS_FROM_ENV=$(echo "${PLUGIN_BUILD_ARGS_FROM_ENV}" | tr ',' '\n' | while read build_arg; do echo "--build-arg ${build_arg}=$(eval "echo \$$build_arg")"; done)
fi fi
# TODO: Test auto_tag behavior; potential bugs might still be here
# auto_tag, if set auto_tag: true, auto generate .tags file # auto_tag, if set auto_tag: true, auto generate .tags file
# support format Major.Minor.Release or start with `v` # support format Major.Minor.Release or start with `v`
# docker tags: Major, Major.Minor, Major.Minor.Release and latest # docker tags: Major, Major.Minor, Major.Minor.Release and latest
if [[ "${PLUGIN_AUTO_TAG:-}" == "true" ]]; then if [[ "${PLUGIN_AUTO_TAG:-}" == "true" ]]; then
TAG=$(echo "${DRONE_TAG:-}" |sed 's/^v//g') TAG=$(echo "${CI_COMMIT_TAG:-}" |sed 's/^v//g')
part=$(echo "${TAG}" |tr '.' '\n' |wc -l) tag_part_count=$(echo "${TAG}" | tr '.' '\n' |wc -l)
# expect number # expect number
echo ${TAG} | grep -E "[a-z-]" &>/dev/null && isNum=1 || isNum=0 echo ${TAG} | grep -E "[a-z-]" &>/dev/null && isNum=1 || isNum=0
if [ ! -n "${TAG:-}" ]; then if [ ! -n "${TAG:-}" ]; then
echo "latest" > .tags echo "latest" > .tags
elif [ ${isNum} -eq 1 -o ${part} -gt 3 ];then elif [ ${isNum} -eq 1 -o ${tag_part_count} -gt 3 ]; then
echo "${TAG},latest" > .tags echo "${TAG},latest" > .tags
else else
major=$(echo "${TAG}" | awk -F'.' '{print $1}') major=$(echo "${TAG}" | awk -F'.' '{print $1}')