diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b5cdba3..4b287c2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -180,6 +180,22 @@ jobs: - name: Validate Homepage site classification run: sh scripts/homepage-group.test.sh + # The platform reconciles deploy/ for production and deploy/dev for the dev environment, both from + # the same published artifact. This renders all three entry points and keeps the production + # identity (routes, domain, TLS, DNS, PDB, simply.com credentials) out of dev. No install: the + # script is `sh` + `kubectl` + `yq`, all present on the runner. + deploy-overlays: + name: Deploy Overlays + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: 🧱 Render production and dev manifests + run: sh scripts/deploy-overlays.test.sh + # Dependabot writes package-lock.json with npm 11, and a lockfile one npm major writes fails the other # major's `npm ci`. package.json declares that major, and this keeps every job that runs npm, and the # Docker build, on a Node line that bundles it. No npm install: the script is `sh` + `yq` + `jq`, all @@ -241,7 +257,7 @@ jobs: ci-required-checks: name: CI - Required Checks runs-on: ubuntu-latest - needs: [lint, check, test, e2e, build, lighthouse, container-smoke, workflow-caller-pins, npm-toolchain, release-classification, publish-pin-approved, validate-retired-links] + needs: [lint, check, test, e2e, build, lighthouse, container-smoke, workflow-caller-pins, deploy-overlays, npm-toolchain, release-classification, publish-pin-approved, validate-retired-links] permissions: actions: read if: ${{ always() }} @@ -259,6 +275,7 @@ jobs: ${{ needs.lighthouse.result }} ${{ needs.container-smoke.result }} ${{ needs.workflow-caller-pins.result }} + ${{ needs.deploy-overlays.result }} ${{ needs.npm-toolchain.result }} ${{ needs.release-classification.result }} ${{ needs.publish-pin-approved.result }} diff --git a/AGENTS.md b/AGENTS.md index 285c879..66cddf5 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -26,7 +26,7 @@ Both failures are silent on a modern engine — no build error, no console warni - `src/lib/` — shared modules: `content` (copy, public contact details and `bookingHref`, the contact-section anchor every booking button uses) and `mailto` (builds the contact `mailto:` link). - `static/` — files served as-is: `favicon.png`, `logo.png` (touch icon and structured data) and `og-image.jpg`. Images shown on the page live in `src/lib/assets/` and are resized to AVIF/WebP at build time by `enhanced:img`. The logo exists twice (`static/logo.png` and `src/lib/assets/logo.png`): when it changes, replace both and regenerate the 64 px `favicon.png` from it. - `tests/unit/` (Vitest) and `tests/e2e/` (Playwright). **Accessibility is a tested invariant:** `tests/e2e/a11y.test.ts` runs axe-core (WCAG 2.1 A/AA) against the built site and fails the E2E gate on any critical/serious violation, so a future contrast/focus/landmark regression cannot ship silently. Keep it green — fix the markup at the root rather than relaxing the check; only allow-list a finding that is a deliberate, documented design choice. -- `deploy/` — Kustomize manifests for the platform cluster (Deployment, Service, HTTPRoute). `Dockerfile` and `docker/nginx.conf` build and serve the static output. +- `deploy/` — Kustomize manifests for the platform cluster, published as one signed artifact for both environments. `deploy/kustomization.yaml` is the production entry the platform reconciles at `path: .` and includes only `prod`. `deploy/base/` is what production and dev share: the site's Deployment (whose container receives the published image digest), Service and network policy. `deploy/prod/` adds everything that carries the production identity: the `ascoachingogvaner.dk` and `www` routes, the ReferenceGrant, Issuer and Certificate, the tenant's own external-dns, the PodDisruptionBudget, and the simply.com credentials with their SecretStore. `deploy/dev/` is the dev overlay: the base at one replica in the `ascoachingogvaner-dev` namespace, changed only by kustomize settings and patches, never a copied manifest and never a route, domain, certificate, DNS or production secret (the platform reconciles it at `path: ./dev` and owns its ingress behind sign-on). `scripts/deploy-overlays.test.sh` (CI job `Deploy Overlays`) renders all three and enforces that split. The site has no runtime feature flags and its Umami tag is baked in at build time (`src/app.html`), so dev differences that need code are tracked in #369. `Dockerfile` and `docker/nginx.conf` build and serve the static output. - CI/CD: `.github/workflows/` — `ci.yaml` (PR gate), `release.yaml` (semantic-release on `main`), `cd.yaml` (publish OCI artifact on tags). A release, and so a deploy, is cut for `feat`, `fix`, `perf` and breaking commits, for `build(deps)` commits (Dependabot's prefix for the Docker base images), and for `build(deps-dev)` commits whose title names the `site-bundle` group (`.releaserc`). That group in `.github/dependabot.yml` lists the packages whose code ends up in the built site; every other package is tooling, its updates arrive as plain `build(deps-dev)`, and workflow updates as `ci(deps)`, and neither releases on its own. `scripts/release-classification.test.sh` fails until a newly added package is classified as one or the other. ## Validation @@ -40,6 +40,7 @@ npm run check # svelte-kit sync && svelte-check (type check) npm test # Vitest unit tests npm run test:e2e # Playwright E2E (builds + previews the static site) npm run build # Static prerender build (adapter-static -> build/) +sh scripts/deploy-overlays.test.sh # Render deploy/ (production) and deploy/dev; needs kubectl + yq ``` No database, secrets or environment variables are required: the site is fully static. Copy and public contact details live in `src/lib/content.ts`. Never commit `.env` files. diff --git a/deploy/deployment.yaml b/deploy/base/deployment.yaml similarity index 100% rename from deploy/deployment.yaml rename to deploy/base/deployment.yaml diff --git a/deploy/base/kustomization.yaml b/deploy/base/kustomization.yaml new file mode 100644 index 0000000..10f55e2 --- /dev/null +++ b/deploy/base/kustomization.yaml @@ -0,0 +1,10 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +# The static site that production (../prod) and dev (../dev) both run. Put a +# manifest here only when both environments run it unchanged. +resources: + - deployment.yaml + - service.yaml + # Tenant-owned CiliumNetworkPolicy allow-list (layered on the platform's + # default-deny floor): the site's Gateway ingress + DNS egress. + - networkpolicy.yaml diff --git a/deploy/networkpolicy.yaml b/deploy/base/networkpolicy.yaml similarity index 100% rename from deploy/networkpolicy.yaml rename to deploy/base/networkpolicy.yaml diff --git a/deploy/service.yaml b/deploy/base/service.yaml similarity index 100% rename from deploy/service.yaml rename to deploy/base/service.yaml diff --git a/deploy/dev/kustomization.yaml b/deploy/dev/kustomization.yaml new file mode 100644 index 0000000..23b40d0 --- /dev/null +++ b/deploy/dev/kustomization.yaml @@ -0,0 +1,35 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +# Dev: the shared site (../base), changed only by the settings below. The +# platform reconciles it at `path: ./dev` into its own namespace and owns its +# ingress behind sign-on, so dev carries none of production's identity: no +# route, domain, certificate, DNS (external-dns), disruption budget or +# simply.com credentials. Change base objects with patches here; never copy a +# manifest. +# +# Analytics: the Umami tag is baked into the image at build time +# (src/app.html), so it cannot be switched from here. Its `data-domains` +# attribute limits tracking to ascoachingogvaner.dk, so dev's hostname sends +# no page views to the production website. +# +# The base hard-codes the production namespace on some objects; pin dev's own +# (the platform's Flux targetNamespace sets the same) so dev never renders +# into production's namespace. +namespace: ascoachingogvaner-dev +resources: + - ../base +# One replica; production runs two. +replicas: + - name: ascoachingogvaner + count: 1 +patches: + # The base policy's only egress rule names the kube-system namespace for DNS. + # A new tenant policy may name no namespace (the platform's + # restrict-tenant-network-policies), and the platform generates allow-dns in + # every tenant namespace, so dev keeps only the Gateway ingress. + - target: + kind: CiliumNetworkPolicy + name: app + patch: |- + - op: remove + path: /spec/egress diff --git a/deploy/kustomization.yaml b/deploy/kustomization.yaml index a189441..91d207e 100644 --- a/deploy/kustomization.yaml +++ b/deploy/kustomization.yaml @@ -1,25 +1,9 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization +# Production entry point. The platform reconciles the published manifests +# artifact at `path: .`, which is this file, so it must only include ./prod. +# Shared manifests live in ./base, production-only ones in ./prod, and the dev +# overlay in ./dev (reconciled at `path: ./dev` into the +# `ascoachingogvaner-dev` namespace). resources: - - deployment.yaml - - external-dns-deployment.yaml - - external-dns-serviceaccount.yaml - - httproute.yaml - - httproute-www.yaml - - pod-disruption-budget.yaml - - service.yaml - # Tenant-owned CiliumNetworkPolicy allow-lists (layered on the platform's - # default-deny floor): the app's Gateway ingress + DNS egress, and the - # external-dns pods' egress to the kube-apiserver + simply.com API. - - networkpolicy.yaml - - external-dns-networkpolicy.yaml - # Namespaced SecretStore backing the simply.com credentials below. - - secretstore.yaml - - simply-credentials-seed.yaml - - simply-credentials-externalsecret.yaml - # Tenant-owned TLS for ascoachingogvaner.dk: namespaced ACME Issuer (simply.com - # DNS01) + Certificate + a ReferenceGrant so the shared platform Gateway can - # terminate TLS with the resulting Secret cross-namespace. - - issuer.yaml - - certificate.yaml - - referencegrant.yaml + - prod diff --git a/deploy/certificate.yaml b/deploy/prod/certificate.yaml similarity index 100% rename from deploy/certificate.yaml rename to deploy/prod/certificate.yaml diff --git a/deploy/external-dns-deployment.yaml b/deploy/prod/external-dns-deployment.yaml similarity index 100% rename from deploy/external-dns-deployment.yaml rename to deploy/prod/external-dns-deployment.yaml diff --git a/deploy/external-dns-networkpolicy.yaml b/deploy/prod/external-dns-networkpolicy.yaml similarity index 100% rename from deploy/external-dns-networkpolicy.yaml rename to deploy/prod/external-dns-networkpolicy.yaml diff --git a/deploy/external-dns-serviceaccount.yaml b/deploy/prod/external-dns-serviceaccount.yaml similarity index 100% rename from deploy/external-dns-serviceaccount.yaml rename to deploy/prod/external-dns-serviceaccount.yaml diff --git a/deploy/httproute-www.yaml b/deploy/prod/httproute-www.yaml similarity index 100% rename from deploy/httproute-www.yaml rename to deploy/prod/httproute-www.yaml diff --git a/deploy/httproute.yaml b/deploy/prod/httproute.yaml similarity index 100% rename from deploy/httproute.yaml rename to deploy/prod/httproute.yaml diff --git a/deploy/issuer.yaml b/deploy/prod/issuer.yaml similarity index 100% rename from deploy/issuer.yaml rename to deploy/prod/issuer.yaml diff --git a/deploy/prod/kustomization.yaml b/deploy/prod/kustomization.yaml new file mode 100644 index 0000000..52c3977 --- /dev/null +++ b/deploy/prod/kustomization.yaml @@ -0,0 +1,26 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +# Production: the shared site (../base) plus everything that carries the +# production identity — the public routes and domain, its certificate and DNS, +# the disruption budget, and the simply.com credentials. The platform +# reconciles this through ../kustomization.yaml. +resources: + - ../base + - external-dns-deployment.yaml + - external-dns-serviceaccount.yaml + - httproute.yaml + - httproute-www.yaml + - pod-disruption-budget.yaml + # The external-dns pods' egress to the kube-apiserver + simply.com API, + # layered on the platform's default-deny floor. + - external-dns-networkpolicy.yaml + # Namespaced SecretStore backing the simply.com credentials below. + - secretstore.yaml + - simply-credentials-seed.yaml + - simply-credentials-externalsecret.yaml + # Tenant-owned TLS for ascoachingogvaner.dk: namespaced ACME Issuer (simply.com + # DNS01) + Certificate + a ReferenceGrant so the shared platform Gateway can + # terminate TLS with the resulting Secret cross-namespace. + - issuer.yaml + - certificate.yaml + - referencegrant.yaml diff --git a/deploy/pod-disruption-budget.yaml b/deploy/prod/pod-disruption-budget.yaml similarity index 100% rename from deploy/pod-disruption-budget.yaml rename to deploy/prod/pod-disruption-budget.yaml diff --git a/deploy/referencegrant.yaml b/deploy/prod/referencegrant.yaml similarity index 100% rename from deploy/referencegrant.yaml rename to deploy/prod/referencegrant.yaml diff --git a/deploy/secretstore.yaml b/deploy/prod/secretstore.yaml similarity index 100% rename from deploy/secretstore.yaml rename to deploy/prod/secretstore.yaml diff --git a/deploy/simply-credentials-externalsecret.yaml b/deploy/prod/simply-credentials-externalsecret.yaml similarity index 100% rename from deploy/simply-credentials-externalsecret.yaml rename to deploy/prod/simply-credentials-externalsecret.yaml diff --git a/deploy/simply-credentials-seed.yaml b/deploy/prod/simply-credentials-seed.yaml similarity index 100% rename from deploy/simply-credentials-seed.yaml rename to deploy/prod/simply-credentials-seed.yaml diff --git a/scripts/deploy-overlays.test.sh b/scripts/deploy-overlays.test.sh new file mode 100755 index 0000000..8d7acae --- /dev/null +++ b/scripts/deploy-overlays.test.sh @@ -0,0 +1,52 @@ +#!/bin/sh +# Render deploy/ (the production entry), deploy/prod and deploy/dev, and keep +# production's identity out of dev. Needs kubectl (with its built-in Kustomize) +# and yq, both present on the runner. +set -eu + +repo_root=$(CDPATH='' cd -- "$(dirname -- "$0")/.." && pwd) +work=$(mktemp -d) +trap 'rm -rf "$work"' EXIT + +fail() { + printf 'FAIL: %s\n' "$*" >&2 + exit 1 +} + +kubectl kustomize "$repo_root/deploy" > "$work/root.yaml" || fail "deploy/ does not render" +kubectl kustomize "$repo_root/deploy/prod" > "$work/prod.yaml" || fail "deploy/prod does not render" +kubectl kustomize "$repo_root/deploy/dev" > "$work/dev.yaml" || fail "deploy/dev does not render" + +# The platform reconciles deploy/ for production, so it must be exactly deploy/prod. +cmp -s "$work/root.yaml" "$work/prod.yaml" || + fail "deploy/kustomization.yaml must include only ./prod" + +count_kind() { + KIND=$1 yq eval-all '[.] | map(select(.kind == strenv(KIND))) | length' "$work/dev.yaml" +} + +# Dev runs the site alone: one Deployment with one replica. +[ "$(count_kind Deployment)" -eq 1 ] || fail "deploy/dev must render only the site's Deployment" +[ "$(yq eval-all 'select(.kind == "Deployment") | .metadata.name' "$work/dev.yaml")" = ascoachingogvaner ] || + fail "deploy/dev must render the ascoachingogvaner Deployment" +[ "$(yq eval-all 'select(.kind == "Deployment") | .spec.replicas' "$work/dev.yaml")" = 1 ] || + fail "deploy/dev must run one replica" + +# Production identity stays in deploy/prod: routes, domain, TLS, DNS, the +# disruption budget and the simply.com credentials. +for kind in HTTPRoute Gateway ReferenceGrant Certificate Issuer PodDisruptionBudget \ + SecretStore ExternalSecret PushSecret Password ServiceAccount; do + [ "$(count_kind "$kind")" -eq 0 ] || fail "deploy/dev renders a $kind; it belongs in deploy/prod" +done +for needle in ascoachingogvaner.dk apps/ascoachingogvaner/ simply-credentials 'namespace: ascoachingogvaner$'; do + if grep -Eq -- "$needle" "$work/dev.yaml"; then + fail "deploy/dev references production ($needle)" + fi +done +# Dev's network policy is created fresh in its own namespace, where the +# platform refuses a tenant policy that names any namespace. +if grep -Fq 'io.kubernetes.pod.namespace' "$work/dev.yaml"; then + fail "deploy/dev network policy names a namespace; select pods by label instead" +fi + +printf '%s\n' 'PASS: deploy/ renders deploy/prod; deploy/dev runs one replica without production identity' diff --git a/scripts/homepage-group.test.sh b/scripts/homepage-group.test.sh index e64ceeb..a5cff37 100644 --- a/scripts/homepage-group.test.sh +++ b/scripts/homepage-group.test.sh @@ -3,7 +3,7 @@ set -eu repo_root=$(CDPATH='' cd -- "$(dirname -- "$0")/.." && pwd) -route="${repo_root}/deploy/httproute.yaml" +route="${repo_root}/deploy/prod/httproute.yaml" enabled=$(yq -r '.metadata.annotations."gethomepage.dev/enabled"' "${route}") group=$(yq -r '.metadata.annotations."gethomepage.dev/group"' "${route}") if [ "${enabled}" != true ] || [ "${group}" != "Business & Clients" ]; then