All checks were successful
Build and Push to Zot / build-and-push (push) Successful in 5m12s
- Create OCI image index instead of single manifest - Use buildah manifest commands for multi-platform format - Fix Image Updater ignoring single-platform OCI images
103 lines
3.5 KiB
YAML
103 lines
3.5 KiB
YAML
name: Build and Push to Zot
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
REGISTRY: zot0213.kro.kr
|
|
IMAGE_NAME: jovies
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: k3s-home
|
|
steps:
|
|
- name: Create Build Job
|
|
run: |
|
|
JOB_NAME="buildah-jovies-$(echo $GITHUB_SHA | cut -c1-7)"
|
|
echo "Creating Buildah Job: $JOB_NAME"
|
|
|
|
cat <<EOF | kubectl apply -f -
|
|
apiVersion: batch/v1
|
|
kind: Job
|
|
metadata:
|
|
name: $JOB_NAME
|
|
namespace: gitea
|
|
spec:
|
|
ttlSecondsAfterFinished: 600
|
|
backoffLimit: 0
|
|
template:
|
|
spec:
|
|
containers:
|
|
- name: buildah
|
|
image: quay.io/buildah/stable:latest
|
|
securityContext:
|
|
privileged: true
|
|
command: ["/bin/bash", "-c"]
|
|
args:
|
|
- |
|
|
set -ex
|
|
|
|
# Install git
|
|
dnf install -y git
|
|
|
|
# Clone repository
|
|
git clone https://github0213.com/Mayne0213/jovies.git /workspace
|
|
cd /workspace/nextjs
|
|
|
|
# Login to registry
|
|
buildah login -u \$(cat /secrets/username) -p \$(cat /secrets/password) ${REGISTRY}
|
|
|
|
# Build image locally
|
|
buildah build --format oci -t localhost/${IMAGE_NAME}:${GITHUB_SHA} .
|
|
|
|
# Create manifest list for multi-platform compatibility
|
|
buildah manifest create ${REGISTRY}/${IMAGE_NAME}:latest
|
|
buildah manifest add ${REGISTRY}/${IMAGE_NAME}:latest localhost/${IMAGE_NAME}:${GITHUB_SHA}
|
|
|
|
# Push manifest list as latest
|
|
buildah manifest push --all ${REGISTRY}/${IMAGE_NAME}:latest docker://${REGISTRY}/${IMAGE_NAME}:latest
|
|
|
|
# Create and push manifest list with SHA tag
|
|
buildah manifest create ${REGISTRY}/${IMAGE_NAME}:${GITHUB_SHA}
|
|
buildah manifest add ${REGISTRY}/${IMAGE_NAME}:${GITHUB_SHA} localhost/${IMAGE_NAME}:${GITHUB_SHA}
|
|
buildah manifest push --all ${REGISTRY}/${IMAGE_NAME}:${GITHUB_SHA} docker://${REGISTRY}/${IMAGE_NAME}:${GITHUB_SHA}
|
|
|
|
echo "Done!"
|
|
env:
|
|
- name: REGISTRY
|
|
value: "${REGISTRY}"
|
|
- name: IMAGE_NAME
|
|
value: "${IMAGE_NAME}"
|
|
- name: GITHUB_SHA
|
|
value: "${GITHUB_SHA}"
|
|
volumeMounts:
|
|
- name: zot-creds
|
|
mountPath: /secrets
|
|
volumes:
|
|
- name: zot-creds
|
|
secret:
|
|
secretName: zot-registry-credentials-plain
|
|
restartPolicy: Never
|
|
EOF
|
|
|
|
- name: Wait for Build Job
|
|
run: |
|
|
JOB_NAME="buildah-jovies-$(echo $GITHUB_SHA | cut -c1-7)"
|
|
echo "Waiting for Job: $JOB_NAME"
|
|
|
|
if ! kubectl wait --for=condition=complete job/$JOB_NAME -n gitea --timeout=900s; then
|
|
echo "Job failed. Logs:"
|
|
kubectl logs job/$JOB_NAME -n gitea --all-containers
|
|
exit 1
|
|
fi
|
|
|
|
echo "Build and push completed successfully!"
|
|
|
|
- name: Cleanup
|
|
if: always()
|
|
run: |
|
|
JOB_NAME="buildah-jovies-$(echo $GITHUB_SHA | cut -c1-7)"
|
|
kubectl delete job $JOB_NAME -n gitea --ignore-not-found
|