thermograph/.forgejo/workflows/build.yml
emi 92e74c585a
All checks were successful
Sync infra to hosts / sync-beta (push) Successful in 13s
Sync infra to hosts / sync-prod (push) Successful in 12s
secrets-guard / encrypted (push) Successful in 7s
shell-lint / shellcheck (push) Successful in 8s
Build + push frontend image (Forgejo registry) / build-push (push) Successful in 53s
Deploy frontend to beta VPS / deploy (push) Successful in 1m16s
secrets-guard / encrypted (pull_request) Successful in 5s
shell-lint / shellcheck (pull_request) Successful in 6s
frontend: rewrite the SSR content service in Go (#28)
Ports frontend/ (Jinja2/FastAPI, ~1180 LOC) to Go with html/template. No
climate math, no DB, no auth -- every route fetches from the backend's
/content/* API.

Verified with a golden-HTML diff, not just unit tests: both the Python
original and the Go rewrite were run against the same committed fixtures
and every route compared byte-for-byte, confirmed programmatically. That
process caught defects unit tests alone missed, since map[string]any has
no compile-time field check:

- Render-context keys were snake_case throughout while the templates read
  PascalCase fields. A missing map key doesn't error, it silently renders
  empty -- title, meta description, canonical URL, OpenGraph tags, and the
  homepage's entire ranked list were blank on every page despite every
  route returning 200. Fixed by renaming every key to match each
  template's own documented field contract, and passing API structs
  straight through wherever their fields already matched (removes a whole
  layer of future drift risk).
- Three pages 500'd: ToolHref needed a composed href, not a bare
  "lat,lon" fragment; the records table needed the raw API struct.
- JSON-LD was double-encoded: <script type="application/ld+json"> is
  JAVASCRIPT context to html/template's escaper regardless of the
  script's type attribute, so template.HTML gets re-escaped as a quoted
  JS string. Needed template.JS. The glossary term page's JSON-LD was
  never built at all -- added.
- html/template silently strips literal HTML and JS comments from parsed
  output (verified in isolation) -- both need a FuncMap function
  returning template.HTML/template.JS to survive.

Packaging: 187MB -> 22.6MB. Two defects caught before reaching a host: the
Swarm stack's entrypoint override with no explicit command drops the
image's CMD entirely (every deploy would have exited 127), and
COPY --chown by name fails under the classic Docker builder on Alpine.
Both fixed.

go build/vet/test -race clean; docker build passes its embedded test step
under both BuildKit and the classic builder; shellcheck 0 findings.
2026-07-24 00:53:48 +00:00

58 lines
2.7 KiB
YAML

name: Build check (reusable)
# `docker build` + in-image test check for ONE app domain, reused via
# `uses:` by pr-build.yml and the deploy-dev workflows -- the monorepo port of
# each app repo's build.yml. Still deliberately NOT a live boot+healthz check:
# that was tried in the split repos and repeatedly hit this runner's own
# environment quirks (bridge-IP reachability, non-unique $$, squatted host
# ports) without ever going reliably green. Image boot is verified by hand
# instead (docker run + alembic + /healthz 200 + a real /api/v2/place 200).
#
# Monorepo port: the domain (backend|frontend) arrives as a workflow_call
# input, and the build CONTEXT is that domain's subdirectory -- so each
# Dockerfile sees exactly the tree it saw when its domain was a repo root,
# byte-for-byte the same build as the split era.
on:
workflow_call:
inputs:
domain:
description: "App domain to build: backend | frontend"
required: true
type: string
jobs:
build:
runs-on: docker
steps:
- uses: actions/checkout@v4
- name: Install Docker CLI
run: |
apt-get update -qq
apt-get install -y -qq docker.io
- name: Build
run: docker build -t thermograph-${{ inputs.domain }}:ci ${{ inputs.domain }}/
# Run the hermetic test tier INSIDE the image we just built (the backend
# image ships tests/ + every runtime dep via COPY . /app/): the exact
# interpreter/deps that ship, none of the runner-environment quirks that
# sank the old host-side boot check. Backend only: the frontend image is
# a Go binary with no interpreter or toolchain to test with -- its vet +
# test suite runs in frontend/Dockerfile's builder stage instead, so the
# Build step above already fails when the Go tests do; its integration
# tier (needs a live backend container) stays a local `make`/scripts
# concern, see frontend/scripts/backend-for-tests.sh.
# requirements-dev only layers pytest on top, so the install is tiny.
# -u 0: the image's default user can't write to site-packages.
# --entrypoint sh: backend's entrypoint is alembic-migrate + uvicorn --
# without the override the test command is swallowed as entrypoint args
# and the container just boots the server forever. unset
# THERMOGRAPH_BASE: the image bakes the prod root-mount (/), which moves
# every route off the /thermograph prefix the tests are written against.
- name: Run tests in the built image (backend only)
if: inputs.domain == 'backend'
run: |
docker run --rm -u 0 --entrypoint sh thermograph-backend:ci \
-c "unset THERMOGRAPH_BASE; pip install -q --no-cache-dir pytest==8.4.1 && python -m pytest tests -q"