#!/bin/sh # SPDX-FileCopyrightText: 2024 HÃ¥vard Moen # # SPDX-License-Identifier: GPL-3.0-only set -e # Initialize the Kaniko executor command set -- /kaniko/executor # Handle Docker credentials if [ -n "${INPUT_CREDENTIALS}" ]; then echo '{"auths": {' > /kaniko/.docker/config.json for CREDENTIAL in ${INPUT_CREDENTIALS}; do echo "${CREDENTIAL}" | ( IFS='=' read -r server creds auth="$(echo -n "${creds}" | base64 -w0)" echo "\"${server}\": {\"auth\": \"${auth}\"}," >> /kaniko/.docker/config.json ) done # Remove the trailing comma sed -i '$s/,$//' /kaniko/.docker/config.json echo '}}' >> /kaniko/.docker/config.json fi # Handle Dockerfile path if [ -n "${INPUT_DOCKER_FILE}" ]; then set -- "$@" --dockerfile "${INPUT_DOCKER_FILE}" fi # Handle build context if [ -n "${INPUT_CONTEXT}" ]; then CONTEXT="${INPUT_CONTEXT}" else CONTEXT=. fi set -- "$@" --context "dir://${CONTEXT}" # Handle push flag if [ "${INPUT_PUSH}" = "false" ]; then set -- "$@" --no-push fi # Handle caching if [ "${INPUT_CACHE}" = "true" ] && [ -n "${INPUT_CACHE_REPO}" ]; then set -- "$@" --cache=true --cache-repo "${INPUT_CACHE_REPO}" if [ -n "${INPUT_CACHE_TTL}" ]; then set -- "$@" --cache-ttl="${INPUT_CACHE_TTL}" fi fi # Handle destinations if [ -n "${INPUT_DESTINATIONS}" ]; then for DESTINATION in ${INPUT_DESTINATIONS}; do set -- "$@" --destination "${DESTINATION}" done fi # Handle licenses if [ -d "${CONTEXT}/LICENSES" ]; then licenses="" for l in LICENSES/*; do license=$(basename "$l" .txt) if [ -z "${licenses}" ]; then licenses="${license}" else licenses="${licenses} AND ${license}" fi done set -- "$@" --label "org.opencontainers.image.licenses=${licenses}" fi # Handle version label if [ -n "${INPUT_VERSION}" ]; then set -- "$@" --label "org.opencontainers.image.version=${INPUT_VERSION}" fi # Handle build arguments if [ -n "${INPUT_BUILD_ARGS}" ]; then while IFS= read -r line; do # Skip empty lines and comments [ -z "$line" ] && continue echo "$line" | grep -qE '^\s*#' && continue set -- "$@" --build-arg "$line" done <