From b7334cfac265598c582e9b5eddbbb04659eb1bd5 Mon Sep 17 00:00:00 2001 From: thethreemagi Date: Mon, 18 May 2026 03:19:01 +0100 Subject: [PATCH] =?UTF-8?q?Rewrite=20reusable=20workflow=20with=20shell=20?= =?UTF-8?q?commands=20=E2=80=94=20no=20node=20dependency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/build-and-push.yml | 72 +++++++++++++---------------- 1 file changed, 31 insertions(+), 41 deletions(-) diff --git a/.gitea/workflows/build-and-push.yml b/.gitea/workflows/build-and-push.yml index 59226e3..3af83a6 100644 --- a/.gitea/workflows/build-and-push.yml +++ b/.gitea/workflows/build-and-push.yml @@ -1,7 +1,6 @@ # Reusable workflow — called by project repos via `uses:` -# Requires Gitea 1.21+ for workflow_call support. -# Runner assumed on Pi 5 (ARM64 native) — no QEMU needed. -# If runner moves to x86 NAS, uncomment the QEMU setup steps. +# Shell-based — no node/JS actions required, works in host mode. +# Requires: git and docker available on the runner host. name: Build and push Docker image @@ -12,16 +11,15 @@ on: description: "Image name (no registry prefix)" required: true type: string + repo_name: + description: "Source repo name (e.g. mtg-meta-scraper)" + required: true + type: string dockerfile_path: - description: "Path to Dockerfile" + description: "Path to Dockerfile relative to repo root" required: false type: string default: "Dockerfile" - platforms: - description: "Target platform(s)" - required: false - type: string - default: "linux/arm64" registry: description: "Container registry host" required: false @@ -37,44 +35,36 @@ on: required: true REGISTRY_TOKEN: required: true + GITEA_TOKEN: + required: true jobs: build: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v4 + run: | + rm -rf /tmp/${{ inputs.image_name }}-build + git clone https://oauth2:${{ secrets.GITEA_TOKEN }}@${{ inputs.registry }}/${{ inputs.registry_owner }}/${{ inputs.repo_name }}.git /tmp/${{ inputs.image_name }}-build + cd /tmp/${{ inputs.image_name }}-build && git checkout ${{ gitea.sha }} - # Uncomment if runner is on x86 NAS (cross-compiling for Pi ARM64): - # - name: Set up QEMU - # uses: docker/setup-qemu-action@v3 - # - name: Set up Docker Buildx - # uses: docker/setup-buildx-action@v3 - - - name: Log in to Gitea registry - uses: docker/login-action@v3 - with: - registry: ${{ inputs.registry }} - username: ${{ secrets.REGISTRY_USER }} - password: ${{ secrets.REGISTRY_TOKEN }} - - - name: Extract metadata - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ inputs.registry }}/${{ inputs.registry_owner }}/${{ inputs.image_name }} - tags: | - type=raw,value=latest,enable={{is_default_branch}} - type=sha,prefix=sha-,format=short + - name: Login to registry + run: | + echo "${{ secrets.REGISTRY_TOKEN }}" | docker login ${{ inputs.registry }} -u "${{ secrets.REGISTRY_USER }}" --password-stdin - name: Build and push - uses: docker/build-push-action@v5 - with: - context: . - file: ${{ inputs.dockerfile_path }} - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - platforms: ${{ inputs.platforms }} - cache-from: type=registry,ref=${{ inputs.registry }}/${{ inputs.registry_owner }}/${{ inputs.image_name }}:buildcache - cache-to: type=registry,ref=${{ inputs.registry }}/${{ inputs.registry_owner }}/${{ inputs.image_name }}:buildcache,mode=max + run: | + SHORT_SHA=$(echo "${{ gitea.sha }}" | cut -c1-7) + IMAGE="${{ inputs.registry }}/${{ inputs.registry_owner }}/${{ inputs.image_name }}" + docker build /tmp/${{ inputs.image_name }}-build \ + -f /tmp/${{ inputs.image_name }}-build/${{ inputs.dockerfile_path }} \ + -t "${IMAGE}:latest" \ + -t "${IMAGE}:sha-${SHORT_SHA}" + docker push "${IMAGE}:latest" + docker push "${IMAGE}:sha-${SHORT_SHA}" + + - name: Cleanup + if: always() + run: | + docker logout ${{ inputs.registry }} || true + rm -rf /tmp/${{ inputs.image_name }}-build