From 1af625f5c3d28e3dd40ec6039ed32752b994a4ee Mon Sep 17 00:00:00 2001 From: Adam French Date: Mon, 19 Oct 2026 20:04:49 +0100 Subject: [PATCH] Add a committed .env.dev with dummy values for the dev stack Starting the dev stack meant hand-building a .env, and the quick route of copying production's put real credentials on a dev machine: cookies were scoped to the live domain (so localhost login failed) and the mail, job-board and tunnel integrations ran against real accounts. .env.dev holds a dummy for every variable in .env.example, in whatever shape each service parses, with DOMAIN=localhost and the background jobs that touch real accounts switched off. It is copied over .env because several services read env_file: ./.env directly. OBSIDIAN_DIR points at a tracked dev/notes/ folder so the bind mount never gets created as root. Co-Authored-By: Claude Opus 5.5 --- .env.dev | 171 ++++++++++++++++++++++++++++++++++++++++++++ .env.example | 3 +- .gitignore | 3 + CLAUDE.md | 5 +- DEPLOYMENT.md | 9 +++ README.md | 1 + dev/notes/README.md | 8 +++ 7 files changed, 197 insertions(+), 3 deletions(-) create mode 100644 .env.dev create mode 100644 dev/notes/README.md diff --git a/.env.dev b/.env.dev new file mode 100644 index 0000000..dc0f60d --- /dev/null +++ b/.env.dev @@ -0,0 +1,171 @@ +# ============================================================================= +# .env.dev — COMMITTED settings for the local dev stack. EVERY VALUE IS A DUMMY. +# +# Use it by copying it over the gitignored .env, then starting the dev stack: +# cp .env.dev .env +# docker compose -f docker-compose.yml -f docker-compose.dev.yml up --build +# It has to BE .env, not be passed with --env-file: several services declare +# `env_file: ./.env`, which compose reads regardless (see check-compose in the +# Makefile). +# +# Nothing here is secret and nothing here may ever be used in production: the +# passwords and signing keys only guard containers on your own machine, and +# every third-party credential is fake, so those integrations fail at the +# provider instead of reaching a real account. The background jobs that would +# act on real accounts are switched off as well. +# +# Keep it in step with .env.example: a new variable goes in both. Settings that +# are not secrets (hosts, ports, timezone) keep .env.example's defaults; values +# a service parses (Garage's hex secrets, Gitea's base64 JWT keys, the S3 key +# id) are dummies in the exact shape it requires, or that service won't start. +# +# The dummy Postgres credentials only work on a database volume created with +# them: an existing dbdata volume keeps whatever password it was initialised +# with. Only POSTGRES_DB is created on a fresh volume; the gitea, jobs and +# tracker databases and roles still have to be created by hand (.env.example). +# ============================================================================= + +# --- Postgres ---------------------------------------------------------------- +POSTGRES_USER=dev +POSTGRES_PASSWORD=dev-postgres-password +POSTGRES_DB=site +POSTGRES_PORT=5432 +POSTGRES_HOST=db +POSTGRES_JOBS_DB=jobs +POSTGRES_JOBS_USER=jobs +POSTGRES_JOBS_PASSWORD=dev-jobs-password +POSTGRES_TRACKER_DB=tracker +POSTGRES_TRACKER_USER=tracker +POSTGRES_TRACKER_PASSWORD=dev-tracker-password + +# --- Gitea ------------------------------------------------------------------- +# The two JWT secrets must decode as base64url of 32 bytes; these decode to +# the text "dev-only-not-a-secret-0123456789". +GITEA_HOST=gitea +GITEA_PORT=3000 +GITEA_INTERNAL_TOKEN=dev-gitea-internal-token +GITEA_LFS_JWT_SECRET=ZGV2LW9ubHktbm90LWEtc2VjcmV0LTAxMjM0NTY3ODk +GITEA_OAUTH2_JWT_SECRET=ZGV2LW9ubHktbm90LWEtc2VjcmV0LTAxMjM0NTY3ODk +POSTGRES_GITEA_DB=gitea +# Blank means localhost. +GITEA_SSH_DOMAIN= + +# --- Gitea Actions runner ---------------------------------------------------- +# The runner is not part of the compose stack; nothing in dev reads these. +GITEA_RUNNER_HOST= +GITEA_RUNNER_NAME=dev-runner +GITEA_RUNNER_REGISTRATION_TOKEN=dev-dummy-runner-token + +# --- Email ingest (job tracker) ----------------------------------------------- +# Sync is off; the credentials are fake, so a manual sign-in fails at Microsoft. +EMAIL_BACKEND=graph +MSGRAPH_CLIENT_ID=00000000-0000-0000-0000-000000000000 +MSGRAPH_CLIENT_SECRET=dev-dummy-msgraph-secret +MSGRAPH_TENANT_ID=consumers +MSGRAPH_REDIRECT_URI=http://localhost/jobs/api/email/callback +IMAP_HOST=imap.invalid +IMAP_PORT=993 +IMAP_EMAIL=dev@example.invalid +IMAP_PASSWORD=dev-dummy-imap-password +EMAIL_SYNC_INTERVAL= +EMAIL_SYNC_ENABLED=false + +# --- Job leads (job tracker) -------------------------------------------------- +# The timer is off; "Check now" still works for the keyless board sources. +JOB_LEADS_ENABLED=false +JOB_LEADS_INTERVAL= +ADZUNA_APP_ID=dev-dummy-adzuna-id +ADZUNA_APP_KEY=dev-dummy-adzuna-key +REED_API_KEY=dev-dummy-reed-key + +# --- SilverBullet (notes) --------------------------------------------------- +SILVERBULLET_HOST=silverbullet +SILVERBULLET_PORT=3000 +SILVERBULLET_PUBLIC_HOST=silverbullet-public +SILVERBULLET_PUBLIC_PORT=3000 +SILVERBULLET_GIT_INTERVAL=300 + +# --- Go backend -------------------------------------------------------------- +# Must be at least 32 bytes or the backend refuses to start. +BACKEND_PORT=8080 +BACKEND_HOST=backend +BACKEND_SECRET=dev-only-jwt-signing-secret-not-for-production +BACKEND_ENDPOINT=/api + +# --- Obsidian vault ---------------------------------------------------------- +# A checked-in, mostly-gitignored folder, so the bind mount always has a +# source owned by you; a missing path would be created by Docker as root and +# SilverBullet (uid 1000) could not write to it. It is not a git repository, +# so silverbullet-git logs that and idles instead of pushing anywhere. +OBSIDIAN_DIR=./dev/notes + +# --- Spotify ----------------------------------------------------------------- +# docker-compose.dev.yml overrides the redirect URI. +SPOTIFY_CLIENT_ID=dev-dummy-spotify-client-id +SPOTIFY_CLIENT_SECRET=dev-dummy-spotify-client-secret +SPOTIFY_REDIRECT_URI= +SPOTIFY_AUTH_STATE=dev-dummy-spotify-state + +# --- Icecast / liquidsoap radio ---------------------------------------------- +ICECAST_SOURCE_PASSWORD=dev-icecast-source-password +ICECAST_RELAY_PASSWORD=dev-icecast-relay-password +ICECAST_ADMIN_USER=admin +ICECAST_ADMIN_PASSWORD=dev-icecast-admin-password +ICECAST_HOST=icecast2 +ICECAST_PORT=8000 +ICECAST_MOUNT=/stream +LIQUIDSOAP_HARBOR_MOUNT=/live +LIQUIDSOAP_HARBOR_PORT=8001 + +# --- TLS / identity ---------------------------------------------------------- +# DOMAIN is also the auth cookie's domain, so it must be the host the browser +# is on. certbot is disabled in dev, so EMAIL is never used. +DOMAIN=localhost +EMAIL=dev@example.invalid + +# --- Cloudflare Tunnel ------------------------------------------------------- +# cloudflared is disabled in dev and certbot with it. +CLOUDFLARE_TUNNEL_TOKEN=dev-dummy-tunnel-token +CLOUDFLARE_DNS_API_TOKEN=dev-dummy-dns-token + +# --- Third-party API keys ---------------------------------------------------- +# Fake keys: Claude calls (rowing photos, job posting reader) get a 401 from +# Anthropic, and the Steam widget gets nothing back. +CLAUDE_API_KEY=sk-ant-dev-dummy-key +CLAUDE_MODEL= +STEAM_API_KEY=DEVDUMMYSTEAMKEY +STEAM_ID=76561190000000000 + +# --- Development-only switch ------------------------------------------------- +SEED_DB=true + +# --- Python FastAPI service (/py/) ------------------------------------------- +PYTHON_HOST=python +PYTHON_PORT=8000 + +# --- Job tracker (/jobs/) ----------------------------------------------------- +JOBS_IMAGE_TAG= + +# --- USACO site (/usaco/) ------------------------------------------------------ +USACO_IMAGE_TAG= +USACO_GIT_TOKEN=dev-dummy-gitea-token +USACO_WEBHOOK_SECRET=dev-dummy-webhook-secret + +# --- Activity tracker (/tracker/) -------------------------------------------- +ACTIVITY_TRACKER_IMAGE_TAG= +TRACKER_TZ=Europe/London + +TFL_APP_KEY=dev-dummy-tfl-key + +# --- Garage object store (public /uploads/) ----------------------------------- +# Shapes Garage enforces: 64 hex for the RPC secret, "GK" + 24 hex for the key +# id, 64 hex for the secret. Uploads fall back to the `uploads` volume until +# garage/bootstrap.sh has imported this key and created the bucket. +GARAGE_RPC_SECRET=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef +GARAGE_ADMIN_TOKEN=dev-garage-admin-token +S3_ACCESS_KEY_ID=GK0123456789abcdef01234567 +S3_SECRET_ACCESS_KEY=fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210 +S3_ENDPOINT=http://garage:3900 +S3_REGION=garage +S3_BUCKET=uploads +GARAGE_CAPACITY=1G diff --git a/.env.example b/.env.example index 071bc1b..697c3a0 100644 --- a/.env.example +++ b/.env.example @@ -20,7 +20,8 @@ # docker compose up -d . # # ADDING A VARIABLE -# If the python or jobs service reads it, add it to that service's +# Add it to .env.dev as well, with a dummy value, so the dev stack keeps +# starting. If the python or jobs service reads it, add it to that service's # `environment:` list in docker-compose.yml too, or the container never # receives it. # diff --git a/.gitignore b/.gitignore index 623f4c8..574a733 100644 --- a/.gitignore +++ b/.gitignore @@ -76,3 +76,6 @@ TODO-NEXT.md # SilverBullet git deploy key (key material only; the README stays) silverbullet/ssh/* !silverbullet/ssh/README.md +# Dev notes vault (OBSIDIAN_DIR in .env.dev); only the README is tracked +dev/notes/* +!dev/notes/README.md diff --git a/CLAUDE.md b/CLAUDE.md index c63fe3b..ae060ca 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -15,10 +15,11 @@ Runs `go vet` + `go test` (backend), pytest in a venv built from `python/require ### Full stack (dev mode, HTTP only) ``` +cp .env.dev .env docker compose -f docker-compose.yml -f docker-compose.dev.yml up --build ``` -Dev mode seeds the database with test data (`SEED_DB=true`) and disables certbot/SSL. Visit `http://localhost`. +`.env.dev` is committed and every value in it is a dummy: local-only passwords, fake third-party keys, `DOMAIN=localhost`, background jobs that touch real accounts switched off. It has to be copied to `.env` because several services read `env_file: ./.env` directly. Never put a real credential in it. Dev mode seeds the database with test data (`SEED_DB=true`) and disables certbot/SSL. Visit `http://localhost`. ### Full stack (production, HTTPS) @@ -96,7 +97,7 @@ Dockerized multi-service personal website self-hosted on `stpvm` (an x86-64 Ubun - **GraphQL auth is declared in the schema.** The `/api/graphql` endpoint has no guarding middleware; `AuthContextMiddleware` only makes the user *available*. A field is protected by annotating it `@admin` or `@signedIn` in `graph/schema/*.graphql` (implemented in `graph/directives.go`). `graph/directives_test.go` fails if a mutation has neither directive and is not on its short public allow-list (`login`, `logout`, `refreshToken`), so a new mutation cannot ship unguarded by accident; a new *query* is public unless you annotate it. Finer rules (post ownership, hiding private messages) stay in the resolver. See `backend/graph/doc.go`. - **Adding a GraphQL entity**: model in `models/models.go` (and the AutoMigrate list), schema file with directives, mapping in `gqlgen.yml`, `make generate`, fill in the resolvers; on the frontend a store built with `createCrudStore`. Model `ID uint` binds directly via `graphql.UintID` — there are no hand-written ID resolvers. Full recipe in `backend/README.md`. - **Spotify tokens**: Persisted to `/backend/token/spotify_token.json` inside the container, surviving restarts. -- **Environment variables**: every variable goes in `.env.example`. One the Python service or the job tracker reads must also be added to the `python` or `jobs` service's explicit `environment:` list in `docker-compose.yml`, or the container never receives it. `.env` is edited by hand on the host; there is no admin-panel editor. +- **Environment variables**: every variable goes in `.env.example`, and a dummy value for it in `.env.dev`. One the Python service or the job tracker reads must also be added to the `python` or `jobs` service's explicit `environment:` list in `docker-compose.yml`, or the container never receives it. `.env` is edited by hand on the host; there is no admin-panel editor. - **Gitea feed**: Backend proxies and caches (1 min TTL) the Gitea activity feed API. - **All GORM models use soft delete** (`gorm.DeletedAt` field). Note that a `uniqueIndex` still collides with soft-deleted rows. diff --git a/DEPLOYMENT.md b/DEPLOYMENT.md index 4570449..6330442 100644 --- a/DEPLOYMENT.md +++ b/DEPLOYMENT.md @@ -162,9 +162,18 @@ validation — run it before pushing, since a red `test` job blocks the deploy. ### Development ``` +cp .env.dev .env docker compose -f docker-compose.yml -f docker-compose.dev.yml up --build ``` +`.env.dev` is committed and holds only dummy values, so the stack starts +without any real credential and cannot reach a real account. Features that +need one fail at the provider, which is the point. It must become `.env` +rather than be passed with `--env-file`, because several services read +`env_file: ./.env` directly. Its Postgres passwords only match a `dbdata` +volume created with them, and as in production only `POSTGRES_DB` is created +automatically. + The override layer changes five services and disables one: - **vue** — `npm run dev` instead of a one-shot build; `./vue` is bind-mounted diff --git a/README.md b/README.md index 7fa68bb..06fff49 100644 --- a/README.md +++ b/README.md @@ -303,6 +303,7 @@ Place at least one `.mp3` file in `icecast2/fallback_music/`. Liquidsoap plays t Run the full stack over plain HTTP without SSL certificates: ```sh +cp .env.dev .env # committed, dummy values only docker compose -f docker-compose.yml -f docker-compose.dev.yml up --build ``` diff --git a/dev/notes/README.md b/dev/notes/README.md new file mode 100644 index 0000000..0f0b9f8 --- /dev/null +++ b/dev/notes/README.md @@ -0,0 +1,8 @@ +# Dev notes vault + +`OBSIDIAN_DIR` in `.env.dev` points here, so the dev stack's SilverBullet +instances and the backend's `/notes` endpoint have a vault to mount. Anything +you write here is gitignored; only this README is tracked. + +It is deliberately not a git repository, so `silverbullet-git` logs that and +idles instead of syncing it anywhere.