forgejo-kaniko-action/action.yml

74 lines
2.3 KiB
YAML

---
name: Forgejo Kaniko
description: Build a container image using Kaniko
branding:
icon: anchor
color: blue
inputs:
dockerfile:
description: The Dockerfile to pass to Kaniko
required: false
context:
description: Build context directory (absolute or relative to GITHUB_WORKSPACE)
required: false
image:
description: Name and tag under which to upload the image
required: true
registry:
description: Domain of the registry. Should be the same as the first path component of the tag.
required: false
default: https://index.docker.io/v1/
username:
description: Username for the container registry
required: true
password:
description: Password for the container registry
required: true
runs:
using: docker
image: docker://gcr.io/kaniko-project/executor:debug
entrypoint: /bin/sh
args:
- -c
- |
mkdir -p /kaniko/.docker
echo '{"auths":{"${{ inputs.registry }}":{"auth":"'$(printf "%s:%s" "${{ inputs.username }}" "${{ inputs.password }}" | base64 | tr -d '\n')'"}}}' > /kaniko/.docker/config.json
# Resolve build context
case "${{ inputs.context }}" in
/*)
echo "🔧 Using absolute context: ${{ inputs.context }}"
CONTEXT="${{ inputs.context }}"
;;
"")
echo "⚠️ No context provided, using default directory."
CONTEXT="$GITHUB_WORKSPACE"
;;
*)
echo "🔧 Using relative context: ${{ inputs.context }}"
CONTEXT="$GITHUB_WORKSPACE/${{ inputs.context }}"
;;
esac
echo "Using context: $CONTEXT"
# Ensure Dockerfile exists within the resolved context
if [ -n "${{ inputs.dockerfile }}" ]; then
echo "Using Dockerfile from input"
mkdir -p "$CONTEXT"
echo "${{ inputs.dockerfile }}" > "$CONTEXT/Dockerfile"
elif [ -f "$CONTEXT/Dockerfile" ]; then
echo "Using existing Dockerfile at $CONTEXT/Dockerfile"
else
echo "ERROR: No Dockerfile provided and no Dockerfile found at $CONTEXT/Dockerfile"
exit 1
fi
dest_flags=""
for dest in $(echo "${{ inputs.image }}" | tr ',' ' '); do
dest_flags="$dest_flags --destination=$dest"
done
echo "Destinations: $dest_flags"
/kaniko/executor --dockerfile Dockerfile --context "$CONTEXT" $dest_flags