Rewrite reusable workflow with shell commands — no node dependency

This commit is contained in:
2026-05-18 03:19:01 +01:00
parent d24b36dfbb
commit b7334cfac2
+31 -41
View File
@@ -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