initial commit
This commit is contained in:
commit
8509748cae
2 changed files with 103 additions and 0 deletions
66
action.yaml
Normal file
66
action.yaml
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
name: 'Kaniko Build & Push'
|
||||
description: 'Builds a multi-stage Dockerfile using Kaniko and pushes it to a container registry'
|
||||
author: 'Your Name'
|
||||
|
||||
inputs:
|
||||
registry_user:
|
||||
description: 'Username for the container registry authentication'
|
||||
required: true
|
||||
registry_token:
|
||||
description: 'Password or Token for the container registry authentication'
|
||||
required: true
|
||||
dockerfile_path:
|
||||
description: 'Relative path to the Dockerfile (e.g., ./test-1/Dockerfile)'
|
||||
required: false
|
||||
default: './Dockerfile'
|
||||
target_stage:
|
||||
description: 'Target stage to build in a multi-stage Dockerfile'
|
||||
required: false
|
||||
default: ''
|
||||
destination_image:
|
||||
description: 'The full image name and tag (e.g., my-repo/php-fpm:test)'
|
||||
required: true
|
||||
cache_repo:
|
||||
description: 'Custom path for Kaniko cache layers'
|
||||
required: false
|
||||
default: ''
|
||||
|
||||
runs:
|
||||
using: 'composite'
|
||||
steps:
|
||||
- name: Install NodeJS for Action Compatibility
|
||||
shell: ash
|
||||
run: apk add --no-cache nodejs
|
||||
|
||||
- name: Build and Push with Kaniko
|
||||
shell: ash
|
||||
run: |
|
||||
# 1. Initialize Kaniko Docker config directory
|
||||
mkdir -p /kaniko/.docker
|
||||
|
||||
# 2. Authenticate cleanly using the full server URL string
|
||||
echo "{\"auths\":{\"${{ forgejo.server_url }}\":{\"username\":\"${{ inputs.registry_user }}\",\"password\":\"${{ inputs.registry_token }}\"}}}" > /kaniko/.docker/config.json
|
||||
|
||||
# 3. Clean up the domain name specifically for destinations and cache routing pointers
|
||||
REGISTRY_DOMAIN=$(echo "${{ forgejo.server_url }}" | sed -e 's/https:\/\///g' -e 's/http:\/\///g')
|
||||
|
||||
# 4. Construct execution arguments dynamically based on optional inputs
|
||||
TARGET_ARG=""
|
||||
if [ -n "${{ inputs.target_stage }}" ]; then
|
||||
TARGET_ARG="--target=${{ inputs.target_stage }}"
|
||||
fi
|
||||
|
||||
CACHE_REPO_ARG="$REGISTRY_DOMAIN/${{ forgejo.repository }}/cache"
|
||||
if [ -n "${{ inputs.cache_repo }}" ]; then
|
||||
CACHE_REPO_ARG="${{ inputs.cache_repo }}"
|
||||
fi
|
||||
|
||||
# 5. Fire Kaniko executor
|
||||
/kaniko/executor \
|
||||
--context="dir://${{ forgejo.workspace }}" \
|
||||
--dockerfile="${{ forgejo.workspace }}/${{ inputs.dockerfile_path }}" \
|
||||
$TARGET_ARG \
|
||||
--destination="$REGISTRY_DOMAIN/${{ inputs.destination_image }}" \
|
||||
--cache=true \
|
||||
--cache-repo="$CACHE_REPO_ARG" \
|
||||
--compressed-caching
|
||||
37
readme.md
Normal file
37
readme.md
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
# kaniko-action
|
||||
|
||||
## Requirements
|
||||
|
||||
The repository that calls the action must have valid secrets to push to registry:
|
||||
|
||||
- `REGISTRY_USER`
|
||||
- `REGISTRY_TOKEN`
|
||||
|
||||
The repository that calls the action must have cross-repository access to this repository.
|
||||
|
||||
## Usage
|
||||
|
||||
```yaml
|
||||
name: kaniko build
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ghcr.io/osscontainertools/kaniko:alpine
|
||||
steps:
|
||||
- name: Checkout Source Code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Run Kaniko Build Push Action
|
||||
uses: https://code.verua.online/verua/kaniko-action
|
||||
with:
|
||||
registry_user: ${{ secrets.REGISTRY_USER }}
|
||||
registry_token: ${{ secrets.REGISTRY_TOKEN }}
|
||||
dockerfile_path: 'test-1/Dockerfile'
|
||||
target_stage: 'development'
|
||||
destination_image: '${{ forgejo.repository }}/foo-image:latest'
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue