From 6a05abc6de44ed5b1c5ddcc30ce315a4ea8d9c15 Mon Sep 17 00:00:00 2001 From: Unchained Date: Sun, 5 Apr 2026 08:12:24 +0200 Subject: [PATCH] ci: simplify Gitea Actions workflow to use BuildKit --- .gitea/workflows/build.yaml | 122 +++++++++++++++++++++--------------- 1 file changed, 72 insertions(+), 50 deletions(-) diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index f2fa685..b5df3d7 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -1,60 +1,82 @@ -name: Build and Push to GHCR +name: Build and Deploy on: push: branches: [master, main] -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} - jobs: build: runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Log in to Container Registry - uses: docker/login-action@v3 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Extract metadata - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - tags: | - type=sha,prefix=,suffix=,format=short - type=raw,value=latest,enable={{is_default_branch}} - - - name: Build and push Docker image - uses: docker/build-push-action@v5 - with: - context: . - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max - - - name: Update kustomization.yaml + - name: Trigger BuildKit Build run: | - COMMIT_SHA=${{ github.sha }} - SHORT_SHA=${COMMIT_SHA:0:7} - sed -i "s|newTag: .*|newTag: ${SHORT_SHA}|" k8s/kustomization.yaml - - - name: Commit and push changes - run: | - git config --local user.email "gitea-actions[bot]@users.noreply.gitea.io" - git config --local user.name "gitea-actions[bot]" - git add k8s/kustomization.yaml - git diff --quiet && git diff --staged --quiet || git commit -m "deploy: update image to ${SHORT_SHA} [skip ci]" - git push + 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!"