feat: input context

This commit is contained in:
Leandro Costa 2025-10-16 08:50:47 -03:00
parent 8ba1608afe
commit 4bedfc30b7
3 changed files with 47 additions and 9 deletions

View file

@ -1,3 +1,3 @@
{ {
"cSpell.words": ["elif", "kaniko"] "cSpell.words": ["elif", "esac", "kaniko"]
} }

View file

@ -6,7 +6,7 @@ Build OCI images using Kaniko.
### Example: Basic Usage, all options. ### Example: Basic Usage, all options.
```yaml ````yaml
jobs: jobs:
cowsay: cowsay:
runs-on: docker runs-on: docker
@ -20,7 +20,24 @@ jobs:
registry: docker.example.org registry: docker.example.org
username: ${{ secrets.REGISTRY_USERNAME }} username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }} password: ${{ secrets.REGISTRY_PASSWORD }}
```
### Example: Custom build context
```yaml
jobs:
build:
runs-on: docker
steps:
- uses: actions/checkout@v4
- uses: https://github.com/leandro-costa-oliveira/forgejo-kaniko-action@v3
with:
context: ./subdir
image: my-user/test-image:latest
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
````
````
### Example: Multiple Tags, Default registry ### Example: Multiple Tags, Default registry
@ -34,7 +51,7 @@ jobs:
image: my-user/test-image:latest,my-user/test-image:${{ github.sha }} image: my-user/test-image:latest,my-user/test-image:${{ github.sha }}
username: ${{ secrets.REGISTRY_USERNAME }} username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }} password: ${{ secrets.REGISTRY_PASSWORD }}
``` ````
### Credits ### Credits

View file

@ -8,6 +8,9 @@ inputs:
dockerfile: dockerfile:
description: The Dockerfile to pass to Kaniko description: The Dockerfile to pass to Kaniko
required: false required: false
context:
description: Build context directory (absolute or relative to GITHUB_WORKSPACE)
required: false
image: image:
description: Name and tag under which to upload the image description: Name and tag under which to upload the image
required: true required: true
@ -31,13 +34,31 @@ runs:
mkdir -p /kaniko/.docker mkdir -p /kaniko/.docker
echo '{"auths":{"${{ inputs.registry }}":{"auth":"'$(printf "%s:%s" "${{ inputs.username }}" "${{ inputs.password }}" | base64 | tr -d '\n')'"}}}' > /kaniko/.docker/config.json echo '{"auths":{"${{ inputs.registry }}":{"auth":"'$(printf "%s:%s" "${{ inputs.username }}" "${{ inputs.password }}" | base64 | tr -d '\n')'"}}}' > /kaniko/.docker/config.json
# Resolve build context
if [ -n "${{ inputs.context }}" ]; then
case "${{ inputs.context }}" in
/*)
CONTEXT="${{ inputs.context }}"
;;
*)
CONTEXT="$GITHUB_WORKSPACE/${{ inputs.context }}"
;;
esac
else
CONTEXT="$GITHUB_WORKSPACE"
fi
echo "Using context: $CONTEXT"
# Ensure Dockerfile exists within the resolved context
if [ -n "${{ inputs.dockerfile }}" ]; then if [ -n "${{ inputs.dockerfile }}" ]; then
echo "Using Dockerfile from input" echo "Using Dockerfile from input"
echo "${{ inputs.dockerfile }}" > Dockerfile mkdir -p "$CONTEXT"
elif [ -f "./Dockerfile" ]; then echo "${{ inputs.dockerfile }}" > "$CONTEXT/Dockerfile"
echo "Using existing ./Dockerfile from workspace" elif [ -f "$CONTEXT/Dockerfile" ]; then
echo "Using existing Dockerfile at $CONTEXT/Dockerfile"
else else
echo "ERROR: No Dockerfile provided and no ./Dockerfile found in workspace" echo "ERROR: No Dockerfile provided and no Dockerfile found at $CONTEXT/Dockerfile"
exit 1 exit 1
fi fi
@ -48,4 +69,4 @@ runs:
echo "Destinations: $dest_flags" echo "Destinations: $dest_flags"
/kaniko/executor --dockerfile Dockerfile --context $GITHUB_WORKSPACE $dest_flags /kaniko/executor --dockerfile Dockerfile --context "$CONTEXT" $dest_flags