nomyo-router/.forgejo/workflows/docker-publish.yml
2026-04-02 18:42:52 +02:00

87 lines
2.8 KiB
YAML

name: Build and Publish Docker Image
on:
push:
branches:
- main
tags:
- "v*.*.*"
workflow_dispatch:
env:
REGISTRY: bitfreedom.net
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push:
runs-on: docker
container:
image: node:lts-bookworm
options: --privileged
permissions:
contents: read
packages: write
steps:
- name: Install Docker
run: |
apt-get update -qq
apt-get install -y -qq docker.io
- name: Start Docker daemon
run: |
dockerd --host=unix:///var/run/docker.sock --iptables=false --dns=8.8.8.8 --dns=8.8.4.4 > /tmp/dockerd.log 2>&1 &
for i in $(seq 1 30); do
sleep 2
docker info > /dev/null 2>&1 && echo "Docker daemon ready" && exit 0
echo "Waiting for Docker daemon... ($i/30)"
done
echo "=== dockerd failed to start, logs: ==="
cat /tmp/dockerd.log
exit 1
- name: Checkout repository
run: |
git clone --depth=1 --branch "${{ github.ref_name }}" \
"https://oauth2:${{ github.token }}@bitfreedom.net/code/${{ github.repository }}.git" \
.
- name: Set up QEMU (for multi-arch builds)
uses: https://github.com/docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: https://github.com/docker/setup-buildx-action@v3
with:
driver-opts: network=host
- name: Log in to Forgejo Container Registry
uses: https://github.com/docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: https://github.com/docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
# Tag with version on git tags (e.g. v0.7.0 → 0.7.0 and 0.7)
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
# Tag latest only on main branch pushes
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
# Tag with short SHA for traceability
type=sha,prefix=sha-
- name: Build and push Docker image
uses: https://github.com/docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache,mode=max