From 1382e533596e0c681751f397209b67113d3b0c25 Mon Sep 17 00:00:00 2001 From: agent Date: Fri, 9 Oct 2026 20:45:28 +0000 Subject: [PATCH] Move compose.yaml and .env.example to the repo root Deploy is now `podman compose up -d` from the root. Add .containerignore so node_modules, local data and .env stay out of the build context, and mount only .env (not the whole tree) when generating VAPID keys. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013FYo6JSV1fDU1fm3LU77iF --- .containerignore | 8 ++++++++ deploy/.env.example => .env.example | 7 ++++--- .gitignore | 1 - AGENTS.md | 5 +++-- SPEC.md | 11 ++++++----- apps/server/src/config.ts | 2 +- apps/server/src/gen-vapid.ts | 2 +- deploy/compose.yaml => compose.yaml | 8 ++++---- deploy/README.md | 8 ++++---- 9 files changed, 31 insertions(+), 21 deletions(-) create mode 100644 .containerignore rename deploy/.env.example => .env.example (72%) rename deploy/compose.yaml => compose.yaml (86%) diff --git a/.containerignore b/.containerignore new file mode 100644 index 0000000..bef5e74 --- /dev/null +++ b/.containerignore @@ -0,0 +1,8 @@ +# Keep the image build context small and free of secrets/local data. +**/node_modules +**/dist +data +.env +test-results +playwright-report +.git diff --git a/deploy/.env.example b/.env.example similarity index 72% rename from deploy/.env.example rename to .env.example index d40ace4..d9cc843 100644 --- a/deploy/.env.example +++ b/.env.example @@ -1,11 +1,12 @@ -# Copy to deploy/.env and `chmod 600 deploy/.env`. Never commit .env. +# Copy to .env (repo root, next to compose.yaml) and `chmod 600 .env`. +# Never commit .env. # Required: public hostname, with a DNS A/AAAA record pointing at this server. DOMAIN=oweme.example.com # Web Push. Generate the keys with: -# podman run --rm --user root -v ./:/out:Z localhost/oweme:latest node server/gen-vapid.ts /out/.env -# (or, with Node 24 installed: node apps/server/src/gen-vapid.ts deploy/.env) +# podman run --rm --user root -v ./.env:/out/.env:Z localhost/oweme:latest node server/gen-vapid.ts /out/.env +# (or, with Node 24 installed: node apps/server/src/gen-vapid.ts .env) # Leave empty to disable notifications. VAPID_SUBJECT=mailto:you@example.com VAPID_PUBLIC_KEY= diff --git a/.gitignore b/.gitignore index a5781f9..d9fff82 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ node_modules/ dist/ data/ .env -deploy/.env test-results/ playwright-report/ *.log diff --git a/AGENTS.md b/AGENTS.md index 1ea0527..3c8a211 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -13,7 +13,8 @@ End-to-end encrypted group expense splitter (a Settle Up clone). Read that way unless there's a strong reason. - `apps/web/` — Svelte 5 SPA + service worker (`src/sw.ts`, built separately by `vite.sw.config.ts` as a classic script). -- `deploy/` — Containerfile, compose.yaml, Caddyfile, `.env.example`, deploy docs. +- `compose.yaml` + `.env.example` (repo root) — the podman compose deployment. +- `deploy/` — Containerfile, Caddyfile, deploy docs. - `e2e/` — Playwright tests against the production build. ## Run @@ -56,4 +57,4 @@ notifications. Push payloads carry only the group id. 7. Strict CSP: no inline scripts, no third-party origins. 8. Containers: rootless Podman; for local testing publish to `127.0.0.1` only - (`BIND_ADDR=127.0.0.1` in `deploy/.env`). + (`BIND_ADDR=127.0.0.1` in `.env`). diff --git a/SPEC.md b/SPEC.md index 4ba86e8..b575d88 100644 --- a/SPEC.md +++ b/SPEC.md @@ -496,7 +496,8 @@ Repo layout (monorepo): apps/web Svelte client + service worker apps/server Node API (no dependencies) packages/core shared: types, event schema, money math, replay, settle-up, recurring, stats, CSV -deploy/ Containerfile, compose.yaml, Caddyfile, .env.example, README +compose.yaml podman compose deployment (with .env.example) +deploy/ Containerfile, Caddyfile, README e2e/ Playwright tests ``` @@ -504,7 +505,7 @@ e2e/ Playwright tests ## 13. Deployment (VPS, podman compose) -`deploy/compose.yaml` runs two services: +`compose.yaml` (repo root) runs two services: - `app`: the Node server, which also serves the built static client. Listens on the internal network only. @@ -516,7 +517,7 @@ Volumes: `oweme-data` (SQLite + blobs), `caddy-data` (certificates). Deploy steps (documented in `deploy/README.md`): 1. Point a DNS A/AAAA record at the VPS. -2. `cp deploy/.env.example deploy/.env && chmod 600 deploy/.env`, then set +2. `cp .env.example .env && chmod 600 .env`, then set `DOMAIN` (e.g. `oweme.example.com`); Caddy uses it for the site address and certificate. (The app itself needs no domain: share links use the page's own origin and the CSP is `'self'`.) Generate VAPID keys with @@ -525,11 +526,11 @@ Deploy steps (documented in `deploy/README.md`): 3. Rootless Podman cannot bind ports < 1024 by default: either set `net.ipv4.ip_unprivileged_port_start=80` via sysctl, or publish 8080/8443 and redirect with the firewall — both documented. -4. `cd deploy && podman compose up -d`. Updates: `git pull && podman compose up -d --build`. +4. `podman compose up -d` from the repo root. Updates: `git pull && podman compose up -d --build`. 5. Backups: copy the data volume. All contents are already encrypted, so backups can be stored anywhere. -Environment variables (`deploy/.env`, read by `compose.yaml`): +Environment variables (`.env`, read by `compose.yaml`): | Variable | Required | Default | Purpose | |---|---|---|---| diff --git a/apps/server/src/config.ts b/apps/server/src/config.ts index c50144e..b86aee1 100644 --- a/apps/server/src/config.ts +++ b/apps/server/src/config.ts @@ -1,4 +1,4 @@ -// All configuration comes from environment variables (see deploy/.env.example). +// All configuration comes from environment variables (see .env.example). import { resolve } from 'node:path'; function int(env: NodeJS.ProcessEnv, name: string, def: number): number { diff --git a/apps/server/src/gen-vapid.ts b/apps/server/src/gen-vapid.ts index 091d1e7..273fe79 100644 --- a/apps/server/src/gen-vapid.ts +++ b/apps/server/src/gen-vapid.ts @@ -1,5 +1,5 @@ // Generate VAPID keys and write them into an env file without printing the -// private key: `node apps/server/src/gen-vapid.ts deploy/.env`. +// private key: `node apps/server/src/gen-vapid.ts .env`. // Existing VAPID_PUBLIC_KEY / VAPID_PRIVATE_KEY lines are kept unless // --force is given (rotating keys invalidates every push subscription). import { chmodSync, existsSync, readFileSync, writeFileSync } from 'node:fs'; diff --git a/deploy/compose.yaml b/compose.yaml similarity index 86% rename from deploy/compose.yaml rename to compose.yaml index c5ccc90..1d1461d 100644 --- a/deploy/compose.yaml +++ b/compose.yaml @@ -1,11 +1,11 @@ -# podman compose up -d --build (run from this directory; reads ./.env) +# podman compose up -d --build (run from the repo root; reads ./.env) # See deploy/README.md for the full deploy steps. name: oweme services: app: build: - context: .. + context: . dockerfile: deploy/Containerfile image: localhost/oweme:latest restart: unless-stopped @@ -31,7 +31,7 @@ services: depends_on: - app environment: - DOMAIN: ${DOMAIN:?set DOMAIN in deploy/.env} + DOMAIN: ${DOMAIN:?set DOMAIN in .env} ports: # BIND_ADDR defaults to all interfaces (a public VPS). Rootless Podman # can't bind ports below 1024 by default; see README "Ports". @@ -39,7 +39,7 @@ services: - "${BIND_ADDR:-0.0.0.0}:${HTTPS_PORT:-443}:443" - "${BIND_ADDR:-0.0.0.0}:${HTTPS_PORT:-443}:443/udp" volumes: - - ./Caddyfile:/etc/caddy/Caddyfile:ro,Z + - ./deploy/Caddyfile:/etc/caddy/Caddyfile:ro,Z - caddy-data:/data - caddy-config:/config diff --git a/deploy/README.md b/deploy/README.md index d07d670..e13d598 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -12,7 +12,7 @@ web client) and **caddy** (HTTPS and reverse proxy). Only Caddy publishes ports. ## First deploy ```sh -git clone oweme && cd oweme/deploy +git clone oweme && cd oweme cp .env.example .env chmod 600 .env @@ -20,7 +20,7 @@ $EDITOR .env # set DOMAIN and VAPID_SUBJECT (mailto:) podman compose build # builds localhost/oweme:latest # Web Push keys: written into .env, private key never printed. -podman run --rm --user root -v ./:/out:Z localhost/oweme:latest node server/gen-vapid.ts /out/.env +podman run --rm --user root -v ./.env:/out/.env:Z localhost/oweme:latest node server/gen-vapid.ts /out/.env podman compose up -d podman compose logs -f # Caddy obtains the certificate on first request @@ -32,12 +32,12 @@ Open `https://$DOMAIN`. `curl https://$DOMAIN/api/health` should say `{"ok":true ```sh cd oweme && git pull -cd deploy && podman compose up -d --build +podman compose up -d --build ``` Data lives in the `oweme-data` volume and survives rebuilds. -## Configuration (`deploy/.env`) +## Configuration (`.env`) | Variable | Required | Default | Purpose | |---|---|---|---|