Files
pages/.gitea/workflows/images.yml
T
Anya Tokugawa d8bfae99a7
Test and publish container images / images (push) Failing after 1s
Remove curl dependency from CI connectivity checks
Use verified Node HTTPS with bounded timeouts and separate tool, DNS, TLS and HTTP diagnostics. Cover the preflight with regression tests and document explicit Docker job labels for Runner 3.
2026-09-27 17:50:15 +09:00

214 lines
9.4 KiB
YAML

name: Test and publish container images
on:
push:
branches: [main, mk_district]
tags: ['v*']
workflow_dispatch:
inputs:
publish:
description: Publish tested images to the Gitea registry
required: true
default: 'true'
type: boolean
# No pull_request trigger: a Docker-capable runner must only run trusted code.
# Gitea 1.24 ignores workflow concurrency/permissions/timeout controls; configure
# runner capacity and timeout explicitly (see docs/operations/gitea-images.md).
jobs:
images:
runs-on: ${{ vars.IMAGE_RUNNER_LABEL || 'ubuntu-latest' }}
env:
REGISTRY: ${{ vars.IMAGE_REGISTRY || 'git.anya.jp' }}
IMAGE_OWNER: ${{ vars.IMAGE_OWNER || 'anya' }}
DOCKER_BUILD_SUMMARY: 'false'
DOCKER_BUILD_RECORD_UPLOAD: 'false'
steps:
- name: Check Gitea HTTPS connectivity before checkout
shell: bash
env:
GITEA_SERVER_URL: ${{ github.server_url }}
run: |
set -euo pipefail
if ! command -v node >/dev/null 2>&1; then
echo 'Runner tool missing: node. Use a job environment with Node.js 20+ for the JavaScript Actions. No network check was performed.' >&2
exit 1
fi
node <<'NODE'
const https = require('node:https');
let url;
try {
url = new URL(process.env.GITEA_SERVER_URL.replace(/\/$/, '') + '/api/v1/version');
if (url.protocol !== 'https:' || url.username || url.password) throw new Error();
} catch {
console.error('Invalid GITEA_SERVER_URL: expected an HTTPS URL without credentials.');
process.exit(1);
}
const request = https.get(url, { rejectUnauthorized: true }, response => {
clearTimeout(deadline);
response.destroy(); // Only the verified TLS connection and HTTP status are needed.
if (response.statusCode !== 200) {
console.error(`Gitea responded with HTTP ${response.statusCode}; check the reverse proxy and access policy.`);
process.exitCode = 1;
} else {
console.log('Gitea HTTPS connectivity OK (TLS certificate verified).');
}
});
const deadline = setTimeout(() => {
request.destroy(Object.assign(new Error('Request deadline exceeded'), { code: 'ETIMEDOUT' }));
}, 15000);
request.on('error', error => {
clearTimeout(deadline);
console.error(`Gitea HTTPS check failed: ${error.code || 'UNKNOWN'}.`);
console.error('Check job-container DNS/hosts, routing and TLS trust. See docs/operations/gitea-images.md.');
process.exitCode = 1;
});
NODE
- name: Check runner and publication configuration
id: config
shell: bash
env:
EVENT_NAME: ${{ github.event_name }}
REQUEST_PUBLISH: ${{ github.event.inputs.publish }}
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_TOKEN }}
run: |
set -euo pipefail
docker version
publish=true
if [[ "$EVENT_NAME" == workflow_dispatch && "$REQUEST_PUBLISH" == false ]]; then
publish=false
fi
if [[ "$publish" == true && ( -z "$REGISTRY_USERNAME" || -z "$REGISTRY_PASSWORD" ) ]]; then
echo 'Set Actions secrets REGISTRY_USERNAME and REGISTRY_TOKEN (write:package), or manually run with publish=false.' >&2
exit 1
fi
[[ "$REGISTRY" =~ ^[a-z0-9][a-z0-9.-]*(:[0-9]+)?$ ]] || { echo 'Invalid IMAGE_REGISTRY' >&2; exit 1; }
[[ "$IMAGE_OWNER" =~ ^[a-z0-9][a-z0-9_-]*$ ]] || { echo 'Invalid IMAGE_OWNER' >&2; exit 1; }
echo "publish=$publish" >> "$GITHUB_OUTPUT"
echo "prefix=$REGISTRY/$IMAGE_OWNER" >> "$GITHUB_OUTPUT"
- name: Check out the exact revision without persisting credentials
uses: https://github.com/actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- name: Identify the commit-specific image version
id: version
shell: bash
run: |
set -euo pipefail
revision="$(git rev-parse HEAD)"
[[ "$revision" =~ ^[a-f0-9]{40}$ ]]
echo "revision=$revision" >> "$GITHUB_OUTPUT"
echo "tag=sha-$revision" >> "$GITHUB_OUTPUT"
- name: Set up an isolated BuildKit builder
uses: https://github.com/docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
with:
version: v0.34.0
buildkitd-config-inline: |
[worker.oci]
max-parallelism = 2
- name: Test Go packages in the application build environment
uses: https://github.com/docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
with:
context: .
file: Dockerfile
target: test
platforms: linux/amd64
push: false
- name: Log in to the Gitea container registry
if: steps.config.outputs.publish == 'true'
uses: https://github.com/docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_TOKEN }}
# Build all three first: a compilation failure must not publish a partial
# release. Loading also permits a local image inspection before publishing.
- name: Build PagesWiki
uses: https://github.com/docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
with:
context: .
file: Dockerfile
target: runtime
platforms: linux/amd64
load: true
push: false
tags: ${{ steps.config.outputs.prefix }}/pageswiki-app:${{ steps.version.outputs.tag }}
labels: |
org.opencontainers.image.revision=${{ steps.version.outputs.revision }}
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
- name: Build adaptor gateway and vim.wasm
uses: https://github.com/docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
with:
context: .
file: Dockerfile.adapter-gateway
platforms: linux/amd64
load: true
push: false
tags: ${{ steps.config.outputs.prefix }}/pageswiki-adaptor-gateway:${{ steps.version.outputs.tag }}
labels: |
org.opencontainers.image.revision=${{ steps.version.outputs.revision }}
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
- name: Build Excalidraw viewer
uses: https://github.com/docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
with:
context: .
file: Dockerfile.excalidraw-viewer
platforms: linux/amd64
load: true
push: false
tags: ${{ steps.config.outputs.prefix }}/pageswiki-excalidraw-viewer:${{ steps.version.outputs.tag }}
labels: |
org.opencontainers.image.revision=${{ steps.version.outputs.revision }}
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
- name: Verify runtime files and build-context exclusions
shell: bash
env:
PREFIX: ${{ steps.config.outputs.prefix }}
TAG: ${{ steps.version.outputs.tag }}
run: |
set -euo pipefail
docker run --rm --network none --entrypoint /bin/sh "$PREFIX/pageswiki-app:$TAG" -c \
'test -x /pageswiki && test -d /src/templates && test -d /src/static && test ! -e /src/.env && test ! -e /src/.git && test ! -e /src/data && test ! -e /src/data2 && test ! -e /src/.deployment-backups'
docker run --rm --network none --entrypoint /bin/sh "$PREFIX/pageswiki-adaptor-gateway:$TAG" -c \
'test -x /adapter-gateway && test -s /vimwasm/vendor/vim.wasm && test -s /vimwasm/HackNerdFont-Regular.ttf'
docker run --rm --network none --entrypoint /bin/sh "$PREFIX/pageswiki-excalidraw-viewer:$TAG" -c \
'test -s /usr/share/nginx/html/index.html && nginx -t'
- name: Publish all built images
if: steps.config.outputs.publish == 'true'
shell: bash
env:
PREFIX: ${{ steps.config.outputs.prefix }}
TAG: ${{ steps.version.outputs.tag }}
run: |
set -euo pipefail
for image in pageswiki-app pageswiki-adaptor-gateway pageswiki-excalidraw-viewer; do
docker push "$PREFIX/$image:$TAG"
done
echo "Published all three images: $PREFIX/<image>:$TAG"
echo 'Deploy only after this workflow has completed successfully; registry pushes are not atomic.'
- name: Remove only the per-run image tags from the runner
if: always() && steps.version.outputs.tag != ''
shell: bash
env:
PREFIX: ${{ steps.config.outputs.prefix }}
TAG: ${{ steps.version.outputs.tag }}
run: |
for image in pageswiki-app pageswiki-adaptor-gateway pageswiki-excalidraw-viewer; do
if docker image inspect "$PREFIX/$image:$TAG" >/dev/null 2>&1; then
docker image rm "$PREFIX/$image:$TAG" || echo "Could not remove local CI tag: $image:$TAG" >&2
fi
done