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.
```yaml
````yaml
jobs:
cowsay:
runs-on: docker
@ -20,7 +20,24 @@ jobs:
registry: docker.example.org
username: ${{ secrets.REGISTRY_USERNAME }}
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
@ -34,7 +51,7 @@ jobs:
image: my-user/test-image:latest,my-user/test-image:${{ github.sha }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
```
````
### Credits

View file

@ -8,6 +8,9 @@ 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
@ -31,13 +34,31 @@ runs:
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
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
echo "Using Dockerfile from input"
echo "${{ inputs.dockerfile }}" > Dockerfile
elif [ -f "./Dockerfile" ]; then
echo "Using existing ./Dockerfile from workspace"
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 in workspace"
echo "ERROR: No Dockerfile provided and no Dockerfile found at $CONTEXT/Dockerfile"
exit 1
fi
@ -48,4 +69,4 @@ runs:
echo "Destinations: $dest_flags"
/kaniko/executor --dockerfile Dockerfile --context $GITHUB_WORKSPACE $dest_flags
/kaniko/executor --dockerfile Dockerfile --context "$CONTEXT" $dest_flags