feat: input context
This commit is contained in:
parent
8ba1608afe
commit
4bedfc30b7
3 changed files with 47 additions and 9 deletions
31
action.yml
31
action.yml
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue