composite actions

This commit is contained in:
Tanner Wright
2026-05-23 22:39:44 -06:00
commit 2ed4619b68
2 changed files with 100 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
name: Kaniko Build and Push
description: Build and push a Docker image to the Gitea registry using kaniko
inputs:
repo:
description: Gitea repository name to clone and build
required: true
image:
description: Image name in the registry (defaults to repo name)
required: false
default: ''
runs:
using: composite
steps:
- name: Build and push
shell: sh
env:
REPO: ${{ inputs.repo }}
IMAGE: ${{ inputs.image }}
run: sh ${{ github.action_path }}/build.sh
+81
View File
@@ -0,0 +1,81 @@
#!/bin/sh
set -e
IMAGE=${IMAGE:-$REPO}
JOB_NAME="build-${IMAGE}-${GITHUB_SHA:0:8}"
kubectl apply -f - <<EOF
apiVersion: batch/v1
kind: Job
metadata:
name: ${JOB_NAME}
namespace: gitea-runner
spec:
ttlSecondsAfterFinished: 300
template:
spec:
initContainers:
- name: git-clone
image: alpine/git
command:
- sh
- -c
- git clone --depth=1 https://\$GIT_USERNAME:\$GIT_PASSWORD@gitea.saltysoup.dev/tanner/${REPO}.git /workspace
env:
- name: GIT_USERNAME
valueFrom:
secretKeyRef:
name: gitea-git-credentials
key: username
- name: GIT_PASSWORD
valueFrom:
secretKeyRef:
name: gitea-git-credentials
key: password
volumeMounts:
- name: workspace
mountPath: /workspace
containers:
- name: kaniko
image: gcr.io/kaniko-project/executor:latest
args:
- --dockerfile=/workspace/Dockerfile
- --context=dir:///workspace
- --destination=gitea.saltysoup.dev/tanner/${IMAGE}:${GITHUB_SHA}
- --destination=gitea.saltysoup.dev/tanner/${IMAGE}:latest
- --skip-tls-verify-registry=gitea.saltysoup.dev
- --snapshot-mode=redo
- --compressed-caching=false
volumeMounts:
- name: workspace
mountPath: /workspace
- name: registry-auth
mountPath: /kaniko/.docker/config.json
subPath: .dockerconfigjson
readOnly: true
volumes:
- name: workspace
emptyDir: {}
- name: registry-auth
secret:
secretName: kaniko-registry-auth
restartPolicy: Never
EOF
echo "Waiting for ${JOB_NAME}..."
while true; do
COMPLETE=$(kubectl get job ${JOB_NAME} -n gitea-runner -o jsonpath='{.status.completionTime}' 2>/dev/null)
FAILED=$(kubectl get job ${JOB_NAME} -n gitea-runner -o jsonpath='{.status.failed}' 2>/dev/null)
if [ -n "$COMPLETE" ]; then
echo "Build succeeded"
kubectl delete job ${JOB_NAME} -n gitea-runner --ignore-not-found
exit 0
fi
if [ "${FAILED:-0}" -ge 1 ]; then
echo "Build failed, logs:"
kubectl logs -n gitea-runner -l job-name=${JOB_NAME} -c kaniko --tail=100 || true
kubectl delete job ${JOB_NAME} -n gitea-runner --ignore-not-found
exit 1
fi
sleep 15
done