This commit is contained in:
parent
aebe9a9e6e
commit
ff26adc8c2
2 changed files with 67 additions and 41 deletions
32
action.yml
32
action.yml
|
@ -1,40 +1,58 @@
|
||||||
---
|
|
||||||
# SPDX-FileCopyrightText: 2024 Håvard Moen <post@haavard.name>
|
# SPDX-FileCopyrightText: 2024 Håvard Moen <post@haavard.name>
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: GPL-3.0-only
|
# SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
name: kaniko-action
|
name: kaniko-action
|
||||||
author: Håvard Moen
|
author: Håvard Moen
|
||||||
description: |
|
description: |
|
||||||
Build and optionally push images using [Kaniko](https://github.com/GoogleContainerTools/kaniko)
|
Build and optionally push images using [Kaniko](https://github.com/GoogleContainerTools/kaniko)
|
||||||
|
|
||||||
inputs:
|
inputs:
|
||||||
cache:
|
cache:
|
||||||
description: 'Set this flag as true to opt into caching with kaniko.'
|
description: 'Set this flag as true to opt into caching with Kaniko.'
|
||||||
required: false
|
required: false
|
||||||
default: false
|
default: false
|
||||||
cache_repo:
|
cache_repo:
|
||||||
description: 'Repository to use for cache, required if cache is true'
|
description: 'Repository to use for cache, required if cache is true'
|
||||||
|
required: false
|
||||||
cache_ttl:
|
cache_ttl:
|
||||||
description: Cache timeout in hours. Defaults to Kaniko default
|
description: 'Cache timeout in hours. Defaults to Kaniko default'
|
||||||
required: false
|
required: false
|
||||||
context:
|
context:
|
||||||
description: 'Path to the build context. Default to the workspace'
|
description: 'Path to the build context. Default to the workspace'
|
||||||
required: false
|
required: false
|
||||||
credentials:
|
credentials:
|
||||||
description: Whitespace separated list of authentication credentials in the format registry_server=user:password
|
description: |
|
||||||
|
Whitespace-separated list of authentication credentials in the format
|
||||||
|
registry_server=user:password
|
||||||
required: false
|
required: false
|
||||||
destinations:
|
destinations:
|
||||||
description: Destinations to push images to, whitespace separated . Required if push is true
|
description: |
|
||||||
|
Destinations to push images to, whitespace-separated.
|
||||||
|
Required if push is true.
|
||||||
required: false
|
required: false
|
||||||
docker_file:
|
docker_file:
|
||||||
description: 'Path to the Dockerfile. Default to Dockerfile. It must be in the context. If set, this action passes the relative path to Kaniko, same as the behavior of docker build --dockerfile'
|
description: |
|
||||||
|
Path to the Dockerfile.
|
||||||
|
Defaults to Dockerfile. It must be in the context.
|
||||||
|
If set, this action passes the relative path to Kaniko,
|
||||||
|
similar to the behavior of `docker build --dockerfile`
|
||||||
required: false
|
required: false
|
||||||
push:
|
push:
|
||||||
description: "Push an image to the registry. Default to true"
|
description: "Push an image to the registry. Default to true"
|
||||||
required: false
|
required: false
|
||||||
default: true
|
default: true
|
||||||
version:
|
version:
|
||||||
description: "Version of the software, to be added as org.opencontainers.image.version label"
|
description: |
|
||||||
|
Version of the software, to be added as
|
||||||
|
`org.opencontainers.image.version` label
|
||||||
required: false
|
required: false
|
||||||
|
build_args:
|
||||||
|
description: |
|
||||||
|
Build arguments to pass to Kaniko.
|
||||||
|
Each line represents a separate build argument in the format KEY=VALUE.
|
||||||
|
required: false
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: docker
|
using: docker
|
||||||
image: Dockerfile
|
image: Dockerfile
|
||||||
|
|
|
@ -5,68 +5,63 @@
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
# Initialize the Kaniko executor command
|
||||||
set -- /kaniko/executor
|
set -- /kaniko/executor
|
||||||
|
|
||||||
if [ -n "${INPUT_CREDENTIALS}" ]
|
# Handle Docker credentials
|
||||||
then
|
if [ -n "${INPUT_CREDENTIALS}" ]; then
|
||||||
echo '{"auths": {' > /kaniko/.docker/config.json
|
echo '{"auths": {' > /kaniko/.docker/config.json
|
||||||
for CREDENTIAL in ${INPUT_CREDENTIALS}
|
for CREDENTIAL in ${INPUT_CREDENTIALS}; do
|
||||||
do
|
echo "${CREDENTIAL}" | (
|
||||||
echo "${CREDENTIAL}" | ( IFS='=' read -r server creds
|
IFS='=' read -r server creds
|
||||||
auth="$(echo -n "${creds}" | base64 -w0)"
|
auth="$(echo -n "${creds}" | base64 -w0)"
|
||||||
echo "\"${server}\": {\"auth\": \"${auth}\"}," >> /kaniko/.docker/config.json
|
echo "\"${server}\": {\"auth\": \"${auth}\"}," >> /kaniko/.docker/config.json
|
||||||
)
|
)
|
||||||
done
|
done
|
||||||
# remove last comma
|
# Remove the trailing comma
|
||||||
sed -i '$s/,$//' /kaniko/.docker/config.json
|
sed -i '$s/,$//' /kaniko/.docker/config.json
|
||||||
echo '}}' >> /kaniko/.docker/config.json
|
echo '}}' >> /kaniko/.docker/config.json
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Handle Dockerfile path
|
||||||
if [ -n "${INPUT_DOCKER_FILE}" ]
|
if [ -n "${INPUT_DOCKER_FILE}" ]; then
|
||||||
then
|
|
||||||
set -- "$@" --dockerfile "${INPUT_DOCKER_FILE}"
|
set -- "$@" --dockerfile "${INPUT_DOCKER_FILE}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "${INPUT_CONTEXT}" ]
|
# Handle build context
|
||||||
then
|
if [ -n "${INPUT_CONTEXT}" ]; then
|
||||||
CONTEXT="${INPUT_CONTEXT}"
|
CONTEXT="${INPUT_CONTEXT}"
|
||||||
else
|
else
|
||||||
CONTEXT=.
|
CONTEXT=.
|
||||||
fi
|
fi
|
||||||
set -- "$@" --context "dir://${CONTEXT}"
|
set -- "$@" --context "dir://${CONTEXT}"
|
||||||
|
|
||||||
if [ "${INPUT_PUSH}" = "false" ]
|
# Handle push flag
|
||||||
then
|
if [ "${INPUT_PUSH}" = "false" ]; then
|
||||||
set -- "$@" --no-push
|
set -- "$@" --no-push
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${INPUT_CACHE}" = "true" ] && [ -n "${INPUT_CACHE_REPO}" ]
|
# Handle caching
|
||||||
then
|
if [ "${INPUT_CACHE}" = "true" ] && [ -n "${INPUT_CACHE_REPO}" ]; then
|
||||||
COMMAND="${COMMAND} --cache=true --cache-repo ${INPUT_CACHE_REPO}"
|
|
||||||
set -- "$@" --cache=true --cache-repo "${INPUT_CACHE_REPO}"
|
set -- "$@" --cache=true --cache-repo "${INPUT_CACHE_REPO}"
|
||||||
if [ -n "${INPUT_CACHE_TTL}" ]
|
if [ -n "${INPUT_CACHE_TTL}" ]; then
|
||||||
then
|
|
||||||
set -- "$@" --cache-ttl="${INPUT_CACHE_TTL}"
|
set -- "$@" --cache-ttl="${INPUT_CACHE_TTL}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "${INPUT_DESTINATIONS}" ]
|
# Handle destinations
|
||||||
then
|
if [ -n "${INPUT_DESTINATIONS}" ]; then
|
||||||
for DESTINATION in ${INPUT_DESTINATIONS}
|
for DESTINATION in ${INPUT_DESTINATIONS}; do
|
||||||
do
|
|
||||||
set -- "$@" --destination "${DESTINATION}"
|
set -- "$@" --destination "${DESTINATION}"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -d "${CONTEXT}/LICENSES" ]
|
# Handle licenses
|
||||||
then
|
if [ -d "${CONTEXT}/LICENSES" ]; then
|
||||||
licenses=""
|
licenses=""
|
||||||
for l in LICENSES/*;
|
for l in LICENSES/*; do
|
||||||
do
|
|
||||||
license=$(basename "$l" .txt)
|
license=$(basename "$l" .txt)
|
||||||
if [ -z "${licenses}" ]
|
if [ -z "${licenses}" ]; then
|
||||||
then
|
|
||||||
licenses="${license}"
|
licenses="${license}"
|
||||||
else
|
else
|
||||||
licenses="${licenses} AND ${license}"
|
licenses="${licenses} AND ${license}"
|
||||||
|
@ -75,9 +70,22 @@ then
|
||||||
set -- "$@" --label "org.opencontainers.image.licenses=${licenses}"
|
set -- "$@" --label "org.opencontainers.image.licenses=${licenses}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "${INPUT_VERSION}" ]
|
# Handle version label
|
||||||
then
|
if [ -n "${INPUT_VERSION}" ]; then
|
||||||
set -- "$@" --label "org.opencontainers.image.version=${INPUT_VERSION}"
|
set -- "$@" --label "org.opencontainers.image.version=${INPUT_VERSION}"
|
||||||
fi
|
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 <<EOF
|
||||||
|
${INPUT_BUILD_ARGS}
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Execute the Kaniko command
|
||||||
exec "$@"
|
exec "$@"
|
||||||
|
|
Loading…
Reference in a new issue