Simplify image CI and pin the job runtime
Build and publish container images / images (push) Successful in 11m4s
Build and publish container images / images (push) Successful in 11m4s
This commit is contained in:
1 parent
d8bfae99a7
commit
2893685aef
3 files changed
+121
-423
No files matched your search
+29
-131
@@ -1,110 +1,34 @@
|
||||
name: Test and publish container images
|
||||
name: Build 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' }}
|
||||
# Verified linux/amd64 job tools. The runner label only selects a runner.
|
||||
container:
|
||||
image: docker.gitea.com/runner-images:ubuntu-latest@sha256:fd911d7417bfbf0f454530e447da95b58001e1df41bbc5e1a8dd35d432575aae
|
||||
env:
|
||||
REGISTRY: ${{ vars.IMAGE_REGISTRY || 'git.anya.jp' }}
|
||||
IMAGE_OWNER: ${{ vars.IMAGE_OWNER || 'anya' }}
|
||||
IMAGE_TAG: sha-${{ github.sha }}
|
||||
# The pinned image stores Node in its tool cache. Make it available to
|
||||
# both shell steps and JavaScript Actions without login-shell setup.
|
||||
PATH: /opt/acttoolcache/node/24.19.0/x64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
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
|
||||
- name: Checkout
|
||||
uses: https://github.com/actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
with:
|
||||
ref: ${{ github.sha }}
|
||||
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
|
||||
- name: Set up Buildx
|
||||
uses: https://github.com/docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
|
||||
with:
|
||||
version: v0.34.0
|
||||
@@ -112,7 +36,7 @@ jobs:
|
||||
[worker.oci]
|
||||
max-parallelism = 2
|
||||
|
||||
- name: Test Go packages in the application build environment
|
||||
- name: Test
|
||||
uses: https://github.com/docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
|
||||
with:
|
||||
context: .
|
||||
@@ -121,16 +45,13 @@ jobs:
|
||||
platforms: linux/amd64
|
||||
push: false
|
||||
|
||||
- name: Log in to the Gitea container registry
|
||||
if: steps.config.outputs.publish == 'true'
|
||||
- name: Log in to registry
|
||||
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:
|
||||
@@ -139,23 +60,21 @@ jobs:
|
||||
target: runtime
|
||||
platforms: linux/amd64
|
||||
load: true
|
||||
push: false
|
||||
tags: ${{ steps.config.outputs.prefix }}/pageswiki-app:${{ steps.version.outputs.tag }}
|
||||
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_OWNER }}/pageswiki-app:${{ env.IMAGE_TAG }}
|
||||
labels: |
|
||||
org.opencontainers.image.revision=${{ steps.version.outputs.revision }}
|
||||
org.opencontainers.image.revision=${{ github.sha }}
|
||||
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
|
||||
|
||||
- name: Build adaptor gateway and vim.wasm
|
||||
- name: Build adaptor gateway
|
||||
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 }}
|
||||
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_OWNER }}/pageswiki-adaptor-gateway:${{ env.IMAGE_TAG }}
|
||||
labels: |
|
||||
org.opencontainers.image.revision=${{ steps.version.outputs.revision }}
|
||||
org.opencontainers.image.revision=${{ github.sha }}
|
||||
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
|
||||
|
||||
- name: Build Excalidraw viewer
|
||||
@@ -165,49 +84,28 @@ jobs:
|
||||
file: Dockerfile.excalidraw-viewer
|
||||
platforms: linux/amd64
|
||||
load: true
|
||||
push: false
|
||||
tags: ${{ steps.config.outputs.prefix }}/pageswiki-excalidraw-viewer:${{ steps.version.outputs.tag }}
|
||||
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_OWNER }}/pageswiki-excalidraw-viewer:${{ env.IMAGE_TAG }}
|
||||
labels: |
|
||||
org.opencontainers.image.revision=${{ steps.version.outputs.revision }}
|
||||
org.opencontainers.image.revision=${{ github.sha }}
|
||||
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
|
||||
|
||||
- name: Verify runtime files and build-context exclusions
|
||||
# Publish only after all builds succeed. Use the host daemon for registry
|
||||
# access; BuildKit does not inherit the runner's /etc/hosts entries.
|
||||
- name: Push images
|
||||
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"
|
||||
docker push "$REGISTRY/$IMAGE_OWNER/$image:$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 != ''
|
||||
- name: Remove local CI image tags
|
||||
if: always()
|
||||
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
|
||||
ref="$REGISTRY/$IMAGE_OWNER/$image:$IMAGE_TAG"
|
||||
if docker image inspect "$ref" >/dev/null 2>&1; then
|
||||
docker image rm "$ref" || echo "Could not remove local CI tag: $ref" >&2
|
||||
fi
|
||||
done
|
||||
Reference in new issue
Block a user