Files
manoon-headless/.gitea/workflows/build.yaml

83 lines
2.9 KiB
YAML

name: Build and Deploy
on:
push:
branches: [master, main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Trigger BuildKit Build
run: |
echo "Triggering BuildKit build for commit: ${{ github.sha }}"
# Delete old job if exists
kubectl delete job build-manoon-headless-action -n gitea --ignore-not-found=true
# Create build job
cat << 'EOF' | kubectl apply -f -
apiVersion: batch/v1
kind: Job
metadata:
name: build-manoon-headless-action
namespace: gitea
labels:
commit: ${{ github.sha }}
triggered-by: gitea-actions
spec:
ttlSecondsAfterFinished: 86400
template:
spec:
restartPolicy: Never
initContainers:
- name: clone
image: alpine/git:latest
command:
- sh
- -c
- |
set -e
git clone --depth 1 http://gitea:3000/unchained/manoon-headless.git /workspace
cd /workspace && git checkout ${{ github.sha }}
echo "Building commit: $(git rev-parse --short HEAD)"
volumeMounts:
- name: workspace
mountPath: /workspace
containers:
- name: build
image: moby/buildkit:latest
command:
- sh
- -c
- |
set -e
mkdir -p /root/.docker
cp /docker-config/.dockerconfigjson /root/.docker/config.json
echo "Building with BuildKit..."
buildctl --addr tcp://buildkit.gitea.svc.cluster.local:1234 build \
--frontend dockerfile.v0 \
--local context=/workspace \
--local dockerfile=/workspace \
--output type=image,name=ghcr.io/unchainedio/manoon-headless:latest,push=true
echo "Build complete! Triggering Flux..."
kubectl annotate kustomization -n flux-system manoonoils-storefront --overwrite reconcile.fluxcd.io/requestedAt="$(date +%s)"
echo "Done!"
volumeMounts:
- name: workspace
mountPath: /workspace
- name: docker-config
mountPath: /docker-config
readOnly: true
volumes:
- name: workspace
emptyDir: {}
- name: docker-config
secret:
secretName: ghcr-pull-secret
EOF
echo "Build job created. Waiting for completion..."
kubectl wait --for=condition=complete job/build-manoon-headless-action -n gitea --timeout=600s || echo "Build still running in background"
echo "Build triggered successfully!"