Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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"
71 changes: 71 additions & 0 deletions .github/workflows/image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Container image

# ghcr.io/<repo>:pr-<N> / :main (moving) and :sha-<short> (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:
# Build the PR head, not the merge commit, so sha-<short> 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
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- id: meta
uses: docker/metadata-action@v5
env:
DOCKER_METADATA_PR_HEAD_SHA: true
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
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"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ Icon?

# Windows system files
Desktop.ini

# Reference clone (not a submodule)
external/koudijs-public-website/
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-<N>` | yes | latest build of a PR |
| `ghcr.io/configbutler/public-website:main` | yes | latest main |
| `ghcr.io/configbutler/public-website:sha-<short>` | 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
Expand Down
20 changes: 20 additions & 0 deletions nginx/default.conf
Original file line number Diff line number Diff line change
@@ -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";
}
}
83 changes: 83 additions & 0 deletions tests/image.sh
Original file line number Diff line number Diff line change
@@ -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"
Loading