Update plugin.sh
continuous-integration/drone/push Build is failing

This commit is contained in:
2026-08-17 02:06:35 +03:00
parent 10c3501dc5
commit 7af23c7946
+129 -58
View File
@@ -1,27 +1,49 @@
#!/busybox/sh #!/busybox/sh
set -euo pipefail set -euo pipefail
set -f
export PATH=$PATH:/kaniko/ export PATH=$PATH:/kaniko/
NL='
'
REGISTRY=${PLUGIN_REGISTRY:-index.docker.io} REGISTRY=${PLUGIN_REGISTRY:-index.docker.io}
if [ "${PLUGIN_USERNAME:-}" ] || [ "${PLUGIN_PASSWORD:-}" ]; then # strip leading/trailing spaces from a single list item
trim() {
t=$1
while [ "${t# }" != "$t" ]; do t=${t# }; done
while [ "${t% }" != "$t" ]; do t=${t% }; done
printf '%s' "$t"
}
DOCKER_AUTH=`echo -n "${PLUGIN_USERNAME}:${PLUGIN_PASSWORD}" | base64 | tr -d "\n"` if [ -n "${PLUGIN_USERNAME:-}" ] || [ -n "${PLUGIN_PASSWORD:-}" ]; then
if [ -z "${PLUGIN_USERNAME:-}" ] || [ -z "${PLUGIN_PASSWORD:-}" ]; then
echo "error: username and password must both be set (missing Drone secret?)" >&2
exit 1
fi
DOCKER_AUTH=$(printf '%s' "${PLUGIN_USERNAME}:${PLUGIN_PASSWORD}" | base64 | tr -d "\n")
# kaniko resolves Docker Hub credentials under the legacy key
# https://index.docker.io/v1/, so write it alongside the plain hostname
AUTHS="\"${REGISTRY}\": {\"auth\": \"${DOCKER_AUTH}\"}"
if [ "${REGISTRY}" = "index.docker.io" ]; then
AUTHS="${AUTHS},
\"https://index.docker.io/v1/\": {\"auth\": \"${DOCKER_AUTH}\"}"
fi
cat > /kaniko/.docker/config.json <<DOCKERJSON cat > /kaniko/.docker/config.json <<DOCKERJSON
{ {
"auths": { "auths": {
"${REGISTRY}": { ${AUTHS}
"auth": "${DOCKER_AUTH}"
}
} }
} }
DOCKERJSON DOCKERJSON
fi fi
if [ "${PLUGIN_JSON_KEY:-}" ];then if [ -n "${PLUGIN_JSON_KEY:-}" ];then
echo "${PLUGIN_JSON_KEY}" > /kaniko/gcr.json echo "${PLUGIN_JSON_KEY}" > /kaniko/gcr.json
export GOOGLE_APPLICATION_CREDENTIALS=/kaniko/gcr.json export GOOGLE_APPLICATION_CREDENTIALS=/kaniko/gcr.json
fi fi
@@ -29,88 +51,137 @@ fi
DOCKERFILE=${PLUGIN_DOCKERFILE:-Dockerfile} DOCKERFILE=${PLUGIN_DOCKERFILE:-Dockerfile}
CONTEXT=${PLUGIN_CONTEXT:-$PWD} CONTEXT=${PLUGIN_CONTEXT:-$PWD}
LOG=${PLUGIN_LOG:-info} LOG=${PLUGIN_LOG:-info}
EXTRA_OPTS=""
if [[ -n "${PLUGIN_TARGET:-}" ]]; then # kaniko arguments accumulate in "$@" so that values containing spaces
TARGET="--target=${PLUGIN_TARGET}" # reach the executor as single arguments
set -- -v "${LOG}" --context="${CONTEXT}" --dockerfile="${DOCKERFILE}"
if [ -n "${PLUGIN_TARGET:-}" ]; then
set -- "$@" --target="${PLUGIN_TARGET}"
fi fi
if [[ "${PLUGIN_SKIP_TLS_VERIFY:-}" == "true" ]]; then if [ "${PLUGIN_SKIP_TLS_VERIFY:-}" = "true" ]; then
EXTRA_OPTS="--skip-tls-verify=true" set -- "$@" --skip-tls-verify=true
fi fi
if [[ "${PLUGIN_CACHE:-}" == "true" ]]; then if [ "${PLUGIN_SKIP_UNUSED_STAGES:-}" = "true" ]; then
CACHE="--cache=true" set -- "$@" --skip-unused-stages=true
fi fi
if [ -n "${PLUGIN_CACHE_REPO:-}" ]; then # snapshot_mode: full (default, most robust), redo (up to 50% faster:
CACHE_REPO="--cache-repo=${REGISTRY}/${PLUGIN_CACHE_REPO}" # mtime, size, mode, uid, gid), time (fastest: mtime only)
fi if [ -n "${PLUGIN_SNAPSHOT_MODE:-}" ]; then
case "${PLUGIN_SNAPSHOT_MODE}" in
if [ -n "${PLUGIN_CACHE_TTL:-}" ]; then full|redo|time)
CACHE_TTL="--cache-ttl=${PLUGIN_CACHE_TTL}" set -- "$@" --snapshot-mode="${PLUGIN_SNAPSHOT_MODE}"
;;
*)
echo "error: snapshot_mode must be one of: full, redo, time (got '${PLUGIN_SNAPSHOT_MODE}')" >&2
exit 1
;;
esac
fi fi
if [ -n "${PLUGIN_BUILD_ARGS:-}" ]; then if [ -n "${PLUGIN_BUILD_ARGS:-}" ]; then
BUILD_ARGS=$(echo "${PLUGIN_BUILD_ARGS}" | tr ',' '\n' | while read build_arg; do echo "--build-arg=${build_arg}"; done) IFS=",${NL}"
for build_arg in ${PLUGIN_BUILD_ARGS}; do
build_arg=$(trim "${build_arg}")
if [ -n "${build_arg}" ]; then
set -- "$@" --build-arg="${build_arg}"
fi
done
unset IFS
fi fi
if [ -n "${PLUGIN_BUILD_ARGS_FROM_ENV:-}" ]; then 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) IFS=",${NL}"
fi for env_name in ${PLUGIN_BUILD_ARGS_FROM_ENV}; do
env_name=$(trim "${env_name}")
if [[ "${PLUGIN_SKIP_UNUSED_STAGES:-}" == "true" ]]; then if [ -z "${env_name}" ]; then
SKIP_UNUSED_STAGES="--skip-unused-stages=true" continue
fi
case "${env_name}" in
[0-9]*|*[!A-Za-z0-9_]*)
echo "warning: build_args_from_env: '${env_name}' is not a valid variable name, skipping" >&2
continue
;;
esac
if eval "[ -n \"\${${env_name}+set}\" ]"; then
eval "env_value=\${${env_name}}"
set -- "$@" --build-arg="${env_name}=${env_value}"
else
echo "warning: build_args_from_env: \$${env_name} is not set, skipping" >&2
fi
done
unset IFS
fi fi
# 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=${DRONE_TAG:-}
part=$(echo "${TAG}" |tr '.' '\n' |wc -l) TAG=${TAG#v}
# expect number
echo ${TAG} |grep -E "[a-z-]" &>/dev/null && isNum=1 || isNum=0
if [ ! -n "${TAG:-}" ];then case "${TAG}" in
'')
echo "latest" > .tags echo "latest" > .tags
elif [ ${isNum} -eq 1 -o ${part} -gt 3 ];then ;;
*[!0-9.]*|*.*.*.*|.*|*.|*..*)
# not a plain Major.Minor.Release version: use the tag as-is
echo "${TAG},latest" > .tags echo "${TAG},latest" > .tags
else ;;
major=$(echo "${TAG}" |awk -F'.' '{print $1}') *)
minor=$(echo "${TAG}" |awk -F'.' '{print $2}') major=${TAG%%.*}
release=$(echo "${TAG}" |awk -F'.' '{print $3}') rest=${TAG#"${major}"}; rest=${rest#.}
minor=${rest%%.*}
rest=${rest#"${minor}"}; rest=${rest#.}
release=${rest}
major=${major:-0}
minor=${minor:-0} minor=${minor:-0}
release=${release:-0} release=${release:-0}
echo "${major},${major}.${minor},${major}.${minor}.${release},latest" > .tags echo "${major},${major}.${minor},${major}.${minor}.${release},latest" > .tags
fi ;;
esac
fi fi
TAGS=""
if [ -n "${PLUGIN_TAGS:-}" ]; then if [ -n "${PLUGIN_TAGS:-}" ]; then
DESTINATIONS=$(echo "${PLUGIN_TAGS}" | tr ',' '\n' | while read tag; do echo "--destination=${REGISTRY}/${PLUGIN_REPO}:${tag} "; done) TAGS=${PLUGIN_TAGS}
elif [ -f .tags ]; then elif [ -f .tags ]; then
DESTINATIONS=$(cat .tags| tr ',' '\n' | while read tag; do echo "--destination=${REGISTRY}/${PLUGIN_REPO}:${tag} "; done) TAGS=$(cat .tags)
elif [ -n "${PLUGIN_REPO:-}" ]; then
DESTINATIONS="--destination=${REGISTRY}/${PLUGIN_REPO}:latest"
else
DESTINATIONS="--no-push"
# Cache is not valid with --no-push
CACHE=""
fi fi
/kaniko/executor -v ${LOG} \ if [ -n "${PLUGIN_REPO:-}" ]; then
--context=${CONTEXT} \ if [ -n "${TAGS}" ]; then
--dockerfile=${DOCKERFILE} \ IFS=",${NL}"
${EXTRA_OPTS} \ for tag in ${TAGS}; do
${DESTINATIONS} \ tag=$(trim "${tag}")
${CACHE:-} \ if [ -n "${tag}" ]; then
${CACHE_TTL:-} \ set -- "$@" --destination="${REGISTRY}/${PLUGIN_REPO}:${tag}"
${CACHE_REPO:-} \ fi
${TARGET:-} \ done
${SKIP_UNUSED_STAGES:-} \ unset IFS
${BUILD_ARGS:-} \ else
${BUILD_ARGS_FROM_ENV:-} set -- "$@" --destination="${REGISTRY}/${PLUGIN_REPO}:latest"
fi
if [ "${PLUGIN_CACHE:-}" = "true" ]; then
set -- "$@" --cache=true
fi
if [ -n "${PLUGIN_CACHE_REPO:-}" ]; then
set -- "$@" --cache-repo="${REGISTRY}/${PLUGIN_CACHE_REPO}"
fi
if [ -n "${PLUGIN_CACHE_TTL:-}" ]; then
set -- "$@" --cache-ttl="${PLUGIN_CACHE_TTL}"
fi
else
if [ -n "${TAGS}" ]; then
echo "warning: tags are set but repo is not, building with --no-push" >&2
fi
# Cache is not valid with --no-push
set -- "$@" --no-push
fi
exec /kaniko/executor "$@"