From 781414f5736fe268e675b87029d317e0a46d2e26 Mon Sep 17 00:00:00 2001 From: Simon Koudijs Date: Tue, 10 Nov 2026 13:08:29 +0000 Subject: [PATCH 1/3] ci: Build and push a container image for PRs and main Co-Authored-By: Claude Opus 5.5 --- .dockerignore | 14 +++++++ .github/dependabot.yml | 12 ++++++ .github/workflows/image.yml | 70 +++++++++++++++++++++++++++++++ .gitignore | 3 ++ Dockerfile | 13 ++++++ README.md | 14 +++++++ nginx/default.conf | 20 +++++++++ tests/image.sh | 83 +++++++++++++++++++++++++++++++++++++ 8 files changed, 229 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/image.yml create mode 100644 Dockerfile create mode 100644 nginx/default.conf create mode 100644 tests/image.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..62ced1c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,14 @@ +.git +.github +.devcontainer +.astro +node_modules +dist +design +docs +raw-input.md +tests +test-results +playwright-report +blob-report +external/koudijs-public-website diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..bbb9f0e --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +version: 2 +updates: + # Base images in the Dockerfile (pinned by digest). + - package-ecosystem: "docker" + directory: "/" + schedule: + interval: "weekly" + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml new file mode 100644 index 0000000..199fa78 --- /dev/null +++ b/.github/workflows/image.yml @@ -0,0 +1,70 @@ +name: Container image + +# ghcr.io/:pr- / :main (moving) and :sha- (immutable, pin this). +on: + pull_request: + push: + branches: [ main ] + workflow_dispatch: + +concurrency: + group: image-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: read + packages: write + +jobs: + image: + # Fork PRs get a read-only token and can't push. + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + with: + submodules: true + + - uses: docker/login-action@v4 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - id: meta + uses: docker/metadata-action@v5 + env: + # Tag the PR head commit, not GitHub's merge commit. + DOCKER_METADATA_PR_HEAD_SHA: true + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=ref,event=pr + type=ref,event=branch + type=sha,format=short + + # Push before testing, so a failing image can still be inspected. + - id: push + uses: docker/build-push-action@v7 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Test image + env: + DIGEST: ${{ steps.push.outputs.digest }} + run: IMAGE="ghcr.io/${GITHUB_REPOSITORY,,}@$DIGEST" tests/image.sh + + - name: Summary + if: always() && steps.push.outputs.digest + run: | + { + echo '### Image' + echo '```' + echo "${{ steps.meta.outputs.tags }}" + echo + echo "digest: ${{ steps.push.outputs.digest }}" + echo '```' + } >> "$GITHUB_STEP_SUMMARY" diff --git a/.gitignore b/.gitignore index 671bb59..3e0204b 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,6 @@ Icon? # Windows system files Desktop.ini + +# Reference clone (not a submodule) +external/koudijs-public-website/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5cc17de --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +# Static Astro build served by unprivileged nginx on :8080. +# Bases are pinned by digest so Dependabot proposes (and CI tests) bumps. +FROM node:24-alpine@sha256:a34ab6d7f6f4813f4d0c5469d74685604b962fbdbf5793a7bc7b4998ecb867c8 AS build +WORKDIR /site +COPY package.json package-lock.json ./ +RUN npm ci --no-audit --no-fund +COPY . . +RUN npm run build + +FROM nginxinc/nginx-unprivileged:alpine@sha256:b5047b9b76845eac124358373c6852377c52e4b05834a47647e955dd91cb8f1e +COPY nginx/default.conf /etc/nginx/conf.d/default.conf +COPY --from=build /site/dist/ /usr/share/nginx/html/ +EXPOSE 8080 diff --git a/README.md b/README.md index 15677ed..64b6aea 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,20 @@ npm run test:e2e # Playwright end-to-end tests against the production build SSH commit signing through the host agent). It follows the gitops-reverser devcontainer; see [`.devcontainer/README.md`](.devcontainer/README.md). +## Container image + +[`.github/workflows/image.yml`](.github/workflows/image.yml) builds the site into an nginx image +(port 8080, non-root) for every PR and every push to main: + +| Tag | Moves? | Use | +| --- | --- | --- | +| `ghcr.io/configbutler/public-website:pr-` | yes | latest build of a PR | +| `ghcr.io/configbutler/public-website:main` | yes | latest main | +| `ghcr.io/configbutler/public-website:sha-` | no | pin this (PR head or main commit) | + +`tests/image.sh` runs the image and checks routing (`/about` and `/about/` serve directly, unknown +paths 404). Run it locally with Docker: `tests/image.sh`. + ## gitops-reverser submodule [`external/gitops-reverser`](external/gitops-reverser) is a git submodule of diff --git a/nginx/default.conf b/nginx/default.conf new file mode 100644 index 0000000..d9deded --- /dev/null +++ b/nginx/default.conf @@ -0,0 +1,20 @@ +server { + listen 8080; + server_name _; + + root /usr/share/nginx/html; + index index.html; + + # Behind a reverse proxy: never leak the internal scheme/host/:8080. + absolute_redirect off; + + # /about and /about/ both serve about/index.html directly, no redirect. + location / { + try_files $uri $uri.html $uri/index.html =404; + } + + # Astro's hashed assets never change. + location /_astro/ { + add_header Cache-Control "public, max-age=31536000, immutable"; + } +} diff --git a/tests/image.sh b/tests/image.sh new file mode 100644 index 0000000..3ad556f --- /dev/null +++ b/tests/image.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env bash +# Black-box test of the container image (Dockerfile + nginx/default.conf). +# +# tests/image.sh # build from the repo, test, clean up +# IMAGE=ghcr.io/foo/bar:tag tests/image.sh # test an existing image +set -euo pipefail +cd "$(dirname "$0")/.." + +PORT="${PORT:-18088}" +CONTAINER="site-image-test-$$" +IMAGE="${IMAGE:-}" +BUILT_IMAGE="" + +cleanup() { + docker rm -f "$CONTAINER" >/dev/null 2>&1 || true + [ -n "$BUILT_IMAGE" ] && docker rmi "$BUILT_IMAGE" >/dev/null 2>&1 || true +} +trap cleanup EXIT + +if [ -z "$IMAGE" ]; then + BUILT_IMAGE="site-image-test:$$" + IMAGE="$BUILT_IMAGE" + echo "==> docker build -> $IMAGE" + docker build -q -t "$IMAGE" . >/dev/null +fi + +echo "==> running $IMAGE on :$PORT" +docker run -d --name "$CONTAINER" -p "$PORT:8080" "$IMAGE" >/dev/null +base="http://localhost:$PORT" + +for _ in $(seq 1 30); do + curl -fsS -o /dev/null "$base/" 2>/dev/null && break + sleep 0.5 +done + +fail=0 +pass() { printf ' ok %s\n' "$1"; } +bad() { printf ' FAIL %s\n' "$1"; fail=1; } + +assert_status() { + local got + got=$(curl -s -o /dev/null -w '%{http_code}' "$base$1") + [ "$got" = "$2" ] && pass "$1 -> $got" || bad "$1 -> $got (want $2)" +} + +# 2xx with no Location header: nothing can leak the internal :8080. +assert_served_directly() { + local headers code loc + headers=$(curl -s -D - -o /dev/null "$base$1") + code=$(printf '%s' "$headers" | awk 'NR==1{print $2}') + loc=$(printf '%s' "$headers" | grep -i '^location:' || true) + if [ "${code:0:1}" = "2" ] && [ -z "$loc" ]; then + pass "$1 served directly ($code)" + else + bad "$1 want direct 2xx, got code=$code location='$loc'" + fi +} + +# Capture first; piping curl into `grep -q` flakes under pipefail (SIGPIPE). +assert_body_contains() { + local body + body=$(curl -s "$base$1") + [[ "$body" == *"$2"* ]] && pass "$1 contains '$2'" || bad "$1 missing '$2'" +} + +echo "== status ==" +assert_status "/" 200 +assert_status "/robots.txt" 200 +assert_status "/sitemap.xml" 200 +assert_status "/does-not-exist-xyz123" 404 + +echo "== pretty URLs, no redirect ==" +for p in /about /about/ /gitops /gitops/ /technology /technology/; do + assert_served_directly "$p" +done + +echo "== real pages ==" +assert_body_contains "/" "ConfigButler" +assert_body_contains "/about" "ConfigButler" + +echo +[ "$fail" -eq 0 ] || { echo "IMAGE TESTS FAILED" >&2; exit 1; } +echo "ALL IMAGE TESTS PASSED" From 035ec99677cbddd74619942a7337f4a903bf032b Mon Sep 17 00:00:00 2001 From: Simon Koudijs Date: Tue, 10 Nov 2026 13:16:24 +0000 Subject: [PATCH 2/3] fix: Make tests/image.sh executable Co-Authored-By: Claude Opus 5.5 --- tests/image.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 tests/image.sh diff --git a/tests/image.sh b/tests/image.sh old mode 100644 new mode 100755 From 90405cee67be5ad724b770a0e4c6a507660b0d64 Mon Sep 17 00:00:00 2001 From: Simon Koudijs Date: Tue, 10 Nov 2026 17:06:58 +0000 Subject: [PATCH 3/3] fix: Build the PR head so sha tags match their contents Co-Authored-By: Claude Opus 5.5 --- .github/workflows/image.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml index 199fa78..b250131 100644 --- a/.github/workflows/image.yml +++ b/.github/workflows/image.yml @@ -21,8 +21,10 @@ jobs: if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository runs-on: ubuntu-latest steps: + # Build the PR head, not the merge commit, so sha- names exactly what's inside. - uses: actions/checkout@v7 with: + ref: ${{ github.event.pull_request.head.sha || github.sha }} submodules: true - uses: docker/login-action@v4 @@ -34,7 +36,6 @@ jobs: - id: meta uses: docker/metadata-action@v5 env: - # Tag the PR head commit, not GitHub's merge commit. DOCKER_METADATA_PR_HEAD_SHA: true with: images: ghcr.io/${{ github.repository }}