PR Check / Security scan (Snyk) (pull_request) Skipped
PR Check / Lint + typecheck (pull_request) Successful in 1m16s
PR Check / Secret scan (gitleaks) (pull_request) Successful in 6s
PR Check / Dependency audit (pull_request) Successful in 10s
PR Check / Dockerfile lint (droast) (pull_request) Successful in 5s
PR Check / AI code review (opencode) (pull_request) Successful in 41s
Build Dockerfile on every v* tag push (created by release-please when the release PR merges) and push registry.noelsabia.dev/cv_website/nuxt as the version, sha-<12> and latest. Main pushes do not build: the registry holds releases, not commits. The job runs in node:22-bookworm and needs only the Docker client, so the act_runner must expose its host socket (container.docker_host: automount); a preflight step fails with that cause when it does not.
118 lines
4.8 KiB
YAML
118 lines
4.8 KiB
YAML
name: Publish image
|
|
|
|
# Fires on the version tag release-please creates when the release PR is
|
|
# merged (vX.Y.Z, plain tags - see OKF_Nuxt/decisions/release-engineering.md).
|
|
# A push to main does NOT build: an image tag always maps to a released
|
|
# version, so what runs in the cluster is traceable to a release, not to an
|
|
# arbitrary commit.
|
|
on:
|
|
push:
|
|
tags:
|
|
- 'v*'
|
|
|
|
# The runner has capacity 1, so releases already serialize. This keeps a
|
|
# manual re-run from racing a fresh release on the same tags.
|
|
concurrency:
|
|
group: publish-image
|
|
cancel-in-progress: false
|
|
|
|
env:
|
|
# Registry host + repository path. The path segment is the Gitea
|
|
# organisation, so k3s pulls registry.noelsabia.dev/cv_website/nuxt:<tag>.
|
|
IMAGE: registry.noelsabia.dev/cv_website/nuxt
|
|
APP_DIR: .
|
|
|
|
jobs:
|
|
publish:
|
|
name: Build and push image
|
|
runs-on: ubuntu-latest
|
|
# Same base image as the other jobs. The build runs on the runner's
|
|
# Docker daemon (not in a nested daemon), so this container only needs
|
|
# the CLI - see OKF_Nuxt/decisions/registry-publishing.md.
|
|
container: node:22-bookworm
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Install Docker CLI
|
|
# Debian's docker.io, not a curl-piped binary from GitHub: apt is a
|
|
# signed channel, and bookworm ships an arm64 build. Only the client
|
|
# is needed; the daemon lives on the host.
|
|
run: |
|
|
apt-get update
|
|
apt-get install -y --no-install-recommends docker.io
|
|
docker --version
|
|
|
|
- name: Check daemon access
|
|
# Fail here, with the cause, instead of halfway through a build.
|
|
# An unreachable daemon means the runner was started without the
|
|
# host socket mounted: set `docker_host: automount` in the
|
|
# act_runner config and restart the service.
|
|
run: |
|
|
echo "DOCKER_HOST=${DOCKER_HOST:-<unset - the default socket path>}"
|
|
if ! docker info > /dev/null 2>&1; then
|
|
echo "::error::no Docker daemon reachable from this job - the act_runner needs the host Docker socket (docker_host: automount)"
|
|
exit 1
|
|
fi
|
|
|
|
- name: Resolve version and tags
|
|
id: version
|
|
run: |
|
|
# GITHUB_REF_NAME is the tag on a tag push. The git fallback keeps
|
|
# this working if a runner version does not set it.
|
|
version="${GITHUB_REF_NAME:-$(git describe --tags --exact-match HEAD)}"
|
|
case "$version" in
|
|
v[0-9]*) ;;
|
|
*) echo "::error::expected a vX.Y.Z tag, got '${version}'"; exit 1 ;;
|
|
esac
|
|
# Short SHA tag alongside the version: OKF_CV_Website/architecture/
|
|
# delivery.md asks for SHA-tagged images so every deploy is
|
|
# traceable to a commit even after a tag is moved.
|
|
sha="$(git rev-parse --short=12 HEAD)"
|
|
{
|
|
echo "version=${version}"
|
|
echo "sha=${sha}"
|
|
} >> "$GITHUB_OUTPUT"
|
|
echo "Building ${version} from ${sha}"
|
|
|
|
- name: Log in to the registry
|
|
env:
|
|
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
|
|
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
|
run: |
|
|
# Missing secrets must fail loudly: an anonymous `docker push`
|
|
# would answer 401 with a message most people misread as a
|
|
# missing repository.
|
|
[ -n "$REGISTRY_USERNAME" ] || { echo "::error::secret REGISTRY_USERNAME is empty"; exit 1; }
|
|
[ -n "$REGISTRY_PASSWORD" ] || { echo "::error::secret REGISTRY_PASSWORD is empty"; exit 1; }
|
|
printf '%s' "$REGISTRY_PASSWORD" \
|
|
| docker login registry.noelsabia.dev -u "$REGISTRY_USERNAME" --password-stdin
|
|
|
|
- name: Build image
|
|
env:
|
|
VERSION: ${{ steps.version.outputs.version }}
|
|
SHA: ${{ steps.version.outputs.sha }}
|
|
run: |
|
|
# --platform is explicit so a build on the wrong architecture fails
|
|
# instead of silently producing an amd64 image the arm64 node
|
|
# cannot run. Native here, no QEMU involved.
|
|
docker build \
|
|
--platform linux/arm64 \
|
|
--label "org.opencontainers.image.version=${VERSION}" \
|
|
--label "org.opencontainers.image.revision=${SHA}" \
|
|
-t "${IMAGE}:${VERSION}" \
|
|
-t "${IMAGE}:sha-${SHA}" \
|
|
-t "${IMAGE}:latest" \
|
|
"${APP_DIR}"
|
|
|
|
- name: Push image
|
|
env:
|
|
VERSION: ${{ steps.version.outputs.version }}
|
|
SHA: ${{ steps.version.outputs.sha }}
|
|
run: |
|
|
# Explicit per tag, not `--all-tags`: --all-tags would also push
|
|
# stale local tags left on the shared daemon by earlier runs.
|
|
docker push "${IMAGE}:${VERSION}"
|
|
docker push "${IMAGE}:sha-${SHA}"
|
|
docker push "${IMAGE}:latest"
|
|
echo "Pushed ${IMAGE}:${VERSION}, :sha-${SHA}, :latest"
|