d1e6add207
Build and Push Docker Image / build (push) Failing after 3s
The legacy builder ignores '# syntax=docker/dockerfile:1.7' and fails at the first 'RUN --mount=type=cache' in the deps stage, which is why runs #193, #382 and #433 all died in ~3s at Step 5/38. Activating dockerd's integrated BuildKit backend fixes the build so :latest publishes again.
64 lines
2.5 KiB
YAML
64 lines
2.5 KiB
YAML
name: Build and Push Docker Image
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
build:
|
|
# Runs on the forgerunner host: bundled Docker CLI + mounted /var/run/docker.sock.
|
|
runs-on: host
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
# Full history so `git rev-list --count HEAD` yields the true commit count
|
|
# driving both the app version (v1.NNN) and the org.alwisp.version label.
|
|
fetch-depth: 0
|
|
|
|
- name: Log in to Gitea Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: registry.alwisp.com
|
|
username: ${{ secrets.REGISTRY_USER }}
|
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
|
|
- name: Build and Push
|
|
env:
|
|
# This Dockerfile uses BuildKit features (`# syntax=docker/dockerfile:1.7`
|
|
# and `RUN --mount=type=cache`). Without this the CLI falls back to the
|
|
# legacy builder, which ignores the syntax directive and fails at the first
|
|
# `--mount`. DOCKER_BUILDKIT=1 activates dockerd's integrated BuildKit
|
|
# backend (no separate buildx plugin required).
|
|
DOCKER_BUILDKIT: "1"
|
|
run: |
|
|
IMAGE="registry.alwisp.com/${{ gitea.repository }}"
|
|
GIT_SHA="$(git rev-parse --short HEAD)"
|
|
BUILD_TIME="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
COMMIT_COUNT="$(git rev-list --count HEAD)"
|
|
docker build \
|
|
--build-arg GIT_SHA="${GIT_SHA}" \
|
|
--build-arg BUILD_TIME="${BUILD_TIME}" \
|
|
--build-arg COMMIT_COUNT="${COMMIT_COUNT}" \
|
|
--label org.alwisp.git-sha="${{ gitea.sha }}" \
|
|
--label org.alwisp.version="v1.$((COMMIT_COUNT-1))" \
|
|
--label org.alwisp.repo="${{ gitea.repository }}" \
|
|
-t "${IMAGE}:latest" .
|
|
docker push "${IMAGE}:latest"
|
|
|
|
# Dangling-only prune: removes untagged leftovers from previous builds. Never
|
|
# removes the tagged :latest or any image referenced by a running container.
|
|
- name: Prune dangling images on host
|
|
if: always()
|
|
run: docker image prune -f 2>/dev/null || true
|
|
|
|
- name: Trigger PORT redeploy
|
|
if: success()
|
|
run: |
|
|
NAME="${{ gitea.repository }}"; NAME="${NAME##*/}"
|
|
curl -fsS -X POST https://port.alwisp.com/hooks/gitea \
|
|
-H "X-Deploy-Token: ${{ secrets.WEBHOOK_SECRET }}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"container\":\"${NAME}\"}" || echo "PORT redeploy trigger failed (non-fatal)"
|