Add Gitea Actions image build and registry publication
Test and publish container images / images (push) Failing after 0s
Test and publish container images / images (push) Failing after 0s
Test Go packages in Docker, build and inspect three application images, then publish commit-specific tags. Document dedicated runner and package credentials, and provide an opt-in registry Compose overlay without automatic deployment.
This commit is contained in:
1 parent
68f7d7a571
commit
02883e404b
5 files changed
+344
-1
No files matched your search
@@ -0,0 +1,172 @@
|
||||
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 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
|
||||
Reference in new issue
Block a user