feat: build
Docker Build & Publish / build-and-push (push) Failing after 1m24s
Docker Build & Publish / Prune old image versions (push) Has been skipped

This commit is contained in:
Senko-san
2026-06-07 21:11:50 +03:00
parent ceee9b9d12
commit a2fa425853
3 changed files with 93 additions and 7 deletions
+91
View File
@@ -0,0 +1,91 @@
name: Docker Build & Publish
on:
push:
branches: [master]
workflow_dispatch:
env:
# Number of tagged (non-latest) versions to keep per image name.
KEEP_VERSIONS: "5"
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
# Strip protocol and trailing slash from server_url to get the registry host.
- name: Resolve registry metadata
id: meta
run: |
host=$(echo "${{ gitea.server_url }}" | sed 's|https\?://||; s|/$||')
# Container registry requires lowercase image names.
repo_lc=$(echo "${{ gitea.repository }}" | tr '[:upper:]' '[:lower:]')
echo "host=$host" >> "$GITHUB_OUTPUT"
echo "image=$host/$repo_lc" >> "$GITHUB_OUTPUT"
echo "sha=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
- name: Log in to Gitea registry
uses: docker/login-action@v3
with:
registry: ${{ steps.meta.outputs.host }}
username: ${{ gitea.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: dockerfiles/Dockerfile.prod
push: true
# PUBLIC_API_BASE_URL left as /api/v1 so any reverse proxy works.
build-args: |
PUBLIC_API_BASE_URL=/api/v1
tags: |
${{ steps.meta.outputs.image }}:latest
${{ steps.meta.outputs.image }}:${{ steps.meta.outputs.sha }}
cleanup:
name: Prune old image versions
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Delete versions beyond KEEP_VERSIONS
env:
GITEA_URL: ${{ gitea.server_url }}
OWNER: ${{ gitea.repository_owner }}
IMAGE: ${{ gitea.event.repository.name }}
TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
image=$(echo "$IMAGE" | tr '[:upper:]' '[:lower:]')
# List all container package versions for this image (page size 50 is
# enough for typical repos; increase if you push very frequently).
response=$(curl -sf \
-H "Authorization: token $TOKEN" \
-H "Accept: application/json" \
"${GITEA_URL}/api/v1/packages/${OWNER}?type=container&limit=50&q=${image}")
# Keep the KEEP_VERSIONS newest SHA-tagged versions; always preserve 'latest'.
to_delete=$(printf '%s' "$response" \
| jq -r \
--arg name "$image" \
--argjson keep "$KEEP_VERSIONS" \
'[.[] | select(.name == $name and .version != "latest")]
| sort_by(.created) | reverse
| .[$keep:][].version')
if [ -z "$to_delete" ]; then
echo "Nothing to prune."
exit 0
fi
while IFS= read -r version; do
echo "Deleting ${image}:${version}"
curl -sf -X DELETE \
-H "Authorization: token $TOKEN" \
"${GITEA_URL}/api/v1/packages/${OWNER}/container/${image}/${version}" \
&& echo " ok" || echo " failed (may already be gone, continuing)"
done <<< "$to_delete"
+1 -6
View File
@@ -4,14 +4,9 @@
# shadows the container install. Build context = mcma-webui/. # shadows the container install. Build context = mcma-webui/.
FROM node:22-slim FROM node:22-slim
# `modern-sk` is a git dependency (git+https://...) — npm needs git to fetch it.
RUN apt-get update \
&& apt-get install -y --no-install-recommends git \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app WORKDIR /app
COPY package.json package-lock.json modern-sk-*.tgz ./ COPY package.json package-lock.json ./
RUN npm ci RUN npm ci
COPY . . COPY . .
+1 -1
View File
@@ -8,7 +8,7 @@ FROM node:22-slim AS build
WORKDIR /app WORKDIR /app
COPY package.json package-lock.json modern-sk-*.tgz ./ COPY package.json package-lock.json ./
RUN npm ci RUN npm ci
COPY . . COPY . .