diff --git a/.containerignore b/.containerignore deleted file mode 100644 index bef5e74..0000000 --- a/.containerignore +++ /dev/null @@ -1,8 +0,0 @@ -# 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/.env.example b/.env.example deleted file mode 100644 index 0e0728e..0000000 --- a/.env.example +++ /dev/null @@ -1,19 +0,0 @@ -# Optional settings for a standalone deploy (podman compose without the -# panel). Copy to .env next to compose.yaml and `chmod 600 .env`. Never -# commit .env. With the panel, set these in the app's Environment tab instead. -# Everything has a working default; see compose.yaml for what each one does. - -# Standalone HTTPS: public hostname with a DNS record pointing here. -DOMAIN=oweme.example.com - -#VAPID_SUBJECT=mailto:you@example.com -#MAX_PHOTO_BYTES=2097152 -#MAX_EVENT_BYTES=65536 -#MAX_GROUP_BYTES=209715200 -#GROUP_CREATE_PER_HOUR=10 -#PUSH_DISABLED=0 - -# Where the standalone Caddy listens. Defaults: all interfaces, ports 80/443. -#BIND_ADDR=0.0.0.0 -#HTTP_PORT=80 -#HTTPS_PORT=443 diff --git a/.gitignore b/.gitignore index d9fff82..a5781f9 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ node_modules/ dist/ data/ .env +deploy/.env test-results/ playwright-report/ *.log diff --git a/AGENTS.md b/AGENTS.md index 8e506b5..1ea0527 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -13,10 +13,7 @@ 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). -- `compose.yaml` (repo root) — the deployment; the panel needs it at the root. - Settings are `${VAR:-default}` there; push keys are generated into the volume. - Caddy is only in the `standalone` profile (the panel brings its own). -- `deploy/` — Containerfile, Caddyfile, deploy docs. +- `deploy/` — Containerfile, compose.yaml, Caddyfile, `.env.example`, deploy docs. - `e2e/` — Playwright tests against the production build. ## Run @@ -59,4 +56,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 `.env` for the standalone profile). + (`BIND_ADDR=127.0.0.1` in `deploy/.env`). diff --git a/SPEC.md b/SPEC.md index 3915948..4ba86e8 100644 --- a/SPEC.md +++ b/SPEC.md @@ -496,40 +496,52 @@ 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 -compose.yaml podman compose deployment (with .env.example) -deploy/ Containerfile, Caddyfile, README +deploy/ Containerfile, compose.yaml, Caddyfile, .env.example, README e2e/ Playwright tests ``` --- -## 13. Deployment (podman compose, with or without the panel) +## 13. Deployment (VPS, podman compose) -`compose.yaml` (repo root) runs the `app` service: the Node server, which -also serves the built static client, on port 8080 with its data in the -`oweme-data` volume. It works with **zero configuration**: VAPID keys are -generated on first start and stored in the volume (`vapid.json`, mode 600), -and the push contact defaults to `https://`. +`deploy/compose.yaml` runs two services: -Every setting is an optional environment variable, written in `compose.yaml` -as `${VAR:-default}` so it is visible and documented in one place: -`MAX_PHOTO_BYTES`, `MAX_EVENT_BYTES`, `MAX_GROUP_BYTES`, -`GROUP_CREATE_PER_HOUR`, `VAPID_SUBJECT`, `VAPID_PUBLIC_KEY` / -`VAPID_PRIVATE_KEY` (pin keys), `PUSH_DISABLED`. +- `app`: the Node server, which also serves the built static client. Listens + on the internal network only. +- `caddy`: TLS termination + reverse proxy, the only service publishing + ports (80/443). -- **With the panel** (the main target): the panel clones the repo, finds - `compose.yaml` at the root, routes the app's domain to `app:8080` through - its own Caddy (HTTPS) and passes the Environment tab's variables to - compose for `${VAR}` interpolation. "Pass to every container" must stay - off until the panel's injection override stops clashing with variables the - compose file sets (podman-compose: `can't merge value of [KEY]`). -- **Standalone**: `podman compose --profile standalone up -d` adds a Caddy - container with automatic HTTPS for `DOMAIN`, published on - `${BIND_ADDR}:${HTTP_PORT}/${HTTPS_PORT}` (defaults all interfaces, 80/443). - Settings come from `.env` next to `compose.yaml`. +Volumes: `oweme-data` (SQLite + blobs), `caddy-data` (certificates). -Step-by-step instructions, the full settings table, ports for rootless Podman -and backups are in `deploy/README.md`. +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 + `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 + `gen-vapid.ts` inside the built image, which writes them into `.env` + without printing them. +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`. +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`): + +| Variable | Required | Default | Purpose | +|---|---|---|---| +| `DOMAIN` | yes | — | Public hostname; Caddy site + TLS, share links | +| `VAPID_PUBLIC_KEY` / `VAPID_PRIVATE_KEY` | for push | — | Web Push (generated by script); empty = notifications off | +| `VAPID_SUBJECT` | for push | — | `mailto:` contact for push services | +| `MAX_PHOTO_BYTES` | no | `2097152` | Per-photo upload cap | +| `MAX_EVENT_BYTES` | no | `65536` | Per-event cap | +| `MAX_GROUP_BYTES` | no | `209715200` | Per-group storage cap | +| `GROUP_CREATE_PER_HOUR` | no | `10` | Group creations per IP per hour | +| `BIND_ADDR` | no | `0.0.0.0` | Address Caddy's ports are published on | +| `HTTP_PORT` / `HTTPS_PORT` | no | `80` / `443` | Host ports for Caddy | Development (on the dev box): servers bind `127.0.0.1` only; preview over an SSH tunnel. Ports and commands go in `AGENTS.md`. diff --git a/apps/server/src/app.ts b/apps/server/src/app.ts index 8d673a0..428be2c 100644 --- a/apps/server/src/app.ts +++ b/apps/server/src/app.ts @@ -6,7 +6,7 @@ import type { IncomingMessage, ServerResponse } from 'node:http'; import { extname, join, normalize, sep } from 'node:path'; import type { Config } from './config.ts'; import type { Store } from './db.ts'; -import { isAllowedEndpoint, loadVapidKeys, sendPush, type Vapid } from './push.ts'; +import { isAllowedEndpoint, sendPush, type Vapid } from './push.ts'; const ID_RE = /^[A-Za-z0-9_-]{22}$/; // 16 random bytes, base64url const EVENT_ID_RE = /^[A-Za-z0-9_-]{8,100}$/; @@ -114,9 +114,10 @@ export function createApp(cfg: Config, store: Store) { const streams = new Map>(); const createLimiter = new RateLimiter(cfg.groupCreatePerHour, 3600_000); const pushLimiter = new RateLimiter(60, 3600_000); - const keys = cfg.pushEnabled ? loadVapidKeys(cfg.dataDir, cfg.vapidPublicKey, cfg.vapidPrivateKey) : null; - if (keys) console.log(`push: VAPID keys from ${keys.source}`); - const vapid: Vapid | null = keys ? { publicKey: keys.publicKey, privateKey: keys.privateKey, subject: cfg.vapidSubject } : null; + const vapid: Vapid | null = + cfg.vapidPublicKey && cfg.vapidPrivateKey && cfg.vapidSubject + ? { publicKey: cfg.vapidPublicKey, privateKey: cfg.vapidPrivateKey, subject: cfg.vapidSubject } + : null; const blobDir = (g: string) => join(cfg.dataDir, 'blobs', g); function clientIp(req: IncomingMessage): string { @@ -140,18 +141,9 @@ export function createApp(cfg: Config, store: Store) { return g; } - // Push services want a contact URL in the VAPID token. Without - // VAPID_SUBJECT, use the public site address the requests arrive on. - function rememberOrigin(req: IncomingMessage) { - if (!vapid || cfg.vapidSubject) return; - const fwd = cfg.trustProxy ? req.headers['x-forwarded-host'] : undefined; - const host = String(fwd ?? req.headers.host ?? '').split(',')[0].trim().toLowerCase(); - if (/^[a-z0-9.-]+\.[a-z]{2,}(:\d+)?$/.test(host) && !host.startsWith('localhost')) vapid.subject = `https://${host}`; - } - function notify(groupId: string, seq: number, deviceId: string): void { for (const res of streams.get(groupId) ?? []) res.write(`data: ${seq}\n\n`); - if (!vapid?.subject) return; + if (!vapid) return; for (const sub of store.pushSubs(groupId)) { if (sub.deviceId === deviceId) continue; void sendPush(sub, { g: groupId }, vapid).then((r) => { @@ -344,7 +336,6 @@ export function createApp(cfg: Config, store: Store) { return send(res, 200, { vapidPublicKey: vapid?.publicKey ?? null, maxPhotoBytes: cfg.maxPhotoBytes, maxGroupBytes: cfg.maxGroupBytes }); if (p === '/api/rates' && m === 'GET') return rates(res, url); if (p === '/api/groups' && m === 'POST') return createGroup(req, res); - rememberOrigin(req); const g = /^\/api\/groups\/([^/]+)(\/.*)?$/.exec(p); if (g) { diff --git a/apps/server/src/config.ts b/apps/server/src/config.ts index c9f0f9c..c50144e 100644 --- a/apps/server/src/config.ts +++ b/apps/server/src/config.ts @@ -1,4 +1,4 @@ -// All configuration comes from environment variables (see .env.example). +// All configuration comes from environment variables (see deploy/.env.example). import { resolve } from 'node:path'; function int(env: NodeJS.ProcessEnv, name: string, def: number): number { @@ -23,7 +23,6 @@ export interface Config { vapidPublicKey: string; vapidPrivateKey: string; vapidSubject: string; - pushEnabled: boolean; ratesEnabled: boolean; ratesBaseUrl: string; } @@ -42,7 +41,6 @@ export function loadConfig(env = process.env): Config { vapidPublicKey: env.VAPID_PUBLIC_KEY || '', vapidPrivateKey: env.VAPID_PRIVATE_KEY || '', vapidSubject: env.VAPID_SUBJECT || '', - pushEnabled: env.PUSH_DISABLED !== '1', ratesEnabled: env.RATES_DISABLED !== '1', ratesBaseUrl: env.RATES_BASE_URL || 'https://www.ecb.europa.eu/stats/eurofxref', }; diff --git a/apps/server/src/gen-vapid.ts b/apps/server/src/gen-vapid.ts new file mode 100644 index 0000000..091d1e7 --- /dev/null +++ b/apps/server/src/gen-vapid.ts @@ -0,0 +1,28 @@ +// Generate VAPID keys and write them into an env file without printing the +// private key: `node apps/server/src/gen-vapid.ts deploy/.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'; +import { generateVapidKeys } from './push.ts'; + +const file = process.argv[2]; +const force = process.argv.includes('--force'); +if (!file) { + console.error('usage: node gen-vapid.ts [--force]'); + process.exit(2); +} + +const lines = existsSync(file) ? readFileSync(file, 'utf8').split('\n') : []; +const has = (k: string) => lines.some((l) => l.startsWith(`${k}=`) && l.length > k.length + 1); +if (has('VAPID_PUBLIC_KEY') && has('VAPID_PRIVATE_KEY') && !force) { + console.error(`${file} already has VAPID keys; leaving them alone (use --force to rotate).`); + process.exit(0); +} + +const { publicKey, privateKey } = generateVapidKeys(); +const kept = lines.filter((l) => !l.startsWith('VAPID_PUBLIC_KEY=') && !l.startsWith('VAPID_PRIVATE_KEY=')); +while (kept.length && kept[kept.length - 1] === '') kept.pop(); +kept.push(`VAPID_PUBLIC_KEY=${publicKey}`, `VAPID_PRIVATE_KEY=${privateKey}`, ''); +writeFileSync(file, kept.join('\n'), { mode: 0o600 }); +chmodSync(file, 0o600); +console.error(`Wrote VAPID keys to ${file} (private key ${privateKey.length} chars, not shown).`); diff --git a/apps/server/src/main.ts b/apps/server/src/main.ts index 3a43c48..f06049e 100644 --- a/apps/server/src/main.ts +++ b/apps/server/src/main.ts @@ -16,7 +16,7 @@ if (cfg.ratesEnabled) rates.start(); server.listen(cfg.port, cfg.host, () => { console.log(`oweme server on http://${cfg.host}:${cfg.port}` + (cfg.staticDir ? ` serving ${cfg.staticDir}` : ' (API only)')); - if (!cfg.pushEnabled) console.log('push notifications disabled (PUSH_DISABLED=1)'); + if (!cfg.vapidPublicKey) console.log('push notifications disabled: VAPID_* not set'); }); for (const sig of ['SIGINT', 'SIGTERM'] as const) { diff --git a/apps/server/src/push.ts b/apps/server/src/push.ts index fdc41b6..c37b77f 100644 --- a/apps/server/src/push.ts +++ b/apps/server/src/push.ts @@ -3,8 +3,6 @@ // the service worker fetches and decrypts the actual events itself, so the // push service never sees content (SPEC.md §7.7). import { createCipheriv, createECDH, createPrivateKey, hkdfSync, randomBytes, sign } from 'node:crypto'; -import { existsSync, readFileSync, writeFileSync } from 'node:fs'; -import { join } from 'node:path'; import type { PushSub } from './db.ts'; const b64u = (b: Buffer | Uint8Array) => Buffer.from(b).toString('base64url'); @@ -37,23 +35,6 @@ export function generateVapidKeys(): { publicKey: string; privateKey: string } { return { publicKey: b64u(ecdh.getPublicKey()), privateKey: b64u(ecdh.getPrivateKey()) }; } -/** - * VAPID keys from the environment if both are set, otherwise generated once - * and kept in the data directory, so push works without any configuration. - * Deleting vapid.json rotates them (and invalidates every subscription). - */ -export function loadVapidKeys(dataDir: string, envPublic: string, envPrivate: string): { publicKey: string; privateKey: string; source: string } { - if (envPublic && envPrivate) return { publicKey: envPublic, privateKey: envPrivate, source: 'environment' }; - const file = join(dataDir, 'vapid.json'); - if (existsSync(file)) { - const k = JSON.parse(readFileSync(file, 'utf8')); - if (typeof k.publicKey === 'string' && typeof k.privateKey === 'string') return { ...k, source: file }; - } - const k = generateVapidKeys(); - writeFileSync(file, JSON.stringify(k), { mode: 0o600, flag: 'wx' }); - return { ...k, source: `${file} (new)` }; -} - export interface Vapid { publicKey: string; privateKey: string; diff --git a/apps/server/test/server.test.ts b/apps/server/test/server.test.ts index 5728658..e8bfe0c 100644 --- a/apps/server/test/server.test.ts +++ b/apps/server/test/server.test.ts @@ -8,7 +8,7 @@ import { after, before, describe, it } from 'node:test'; import { createApp } from '../src/app.ts'; import { loadConfig } from '../src/config.ts'; import { Store } from '../src/db.ts'; -import { encryptPayload, isAllowedEndpoint, loadVapidKeys } from '../src/push.ts'; +import { encryptPayload, isAllowedEndpoint } from '../src/push.ts'; import { parseEcbXml } from '../src/rates.ts'; const b64u = (b: Buffer) => b.toString('base64url'); @@ -161,23 +161,6 @@ describe('rates and static', () => { }); }); -describe('vapid keys', () => { - it('generates keys once and keeps them in the data dir', () => { - const d = mkdtempSync(join(tmpdir(), 'oweme-vapid-')); - const a = loadVapidKeys(d, '', ''); - const b = loadVapidKeys(d, '', ''); - assert.equal(a.publicKey, b.publicKey); - assert.match(a.publicKey, /^[A-Za-z0-9_-]{87}$/); - assert.equal(loadVapidKeys(d, 'pub', 'priv').publicKey, 'pub'); // env wins - rmSync(d, { recursive: true, force: true }); - }); - - it('exposes the public key without any configuration', async () => { - const r = await api('GET', '/api/config'); - assert.match(r.data.vapidPublicKey, /^[A-Za-z0-9_-]{87}$/); - }); -}); - describe('web push encryption', () => { it('produces an RFC 8291 payload the browser side can decrypt', () => { // Play the browser: generate a subscription key pair and auth secret. diff --git a/compose.yaml b/compose.yaml deleted file mode 100644 index 89d7c22..0000000 --- a/compose.yaml +++ /dev/null @@ -1,75 +0,0 @@ -# OweMe. Works as-is with zero configuration; every setting below can be -# overridden with an environment variable (in the panel's Environment tab, -# or in a .env file next to this file). -# -# With the panel: point the app's domain at service `app`, port 8080. -# The panel's Caddy provides HTTPS. -# Standalone (no panel): set DOMAIN and run -# podman compose --profile standalone up -d --build -# which adds a Caddy container with automatic HTTPS. See deploy/README.md. -name: oweme - -services: - app: - build: - context: . - dockerfile: deploy/Containerfile - image: localhost/oweme:latest - restart: unless-stopped - environment: - # Max size of one uploaded (encrypted) photo, in bytes. Default 2 MB. - MAX_PHOTO_BYTES: ${MAX_PHOTO_BYTES:-2097152} - # Max size of one encrypted event, in bytes. Default 64 KB. - MAX_EVENT_BYTES: ${MAX_EVENT_BYTES:-65536} - # Storage cap per group (events + photos), in bytes. Default 200 MB. - MAX_GROUP_BYTES: ${MAX_GROUP_BYTES:-209715200} - # New groups per client IP per hour. - GROUP_CREATE_PER_HOUR: ${GROUP_CREATE_PER_HOUR:-10} - # Contact sent to push services, e.g. mailto:you@example.com. - # Empty = https://. - VAPID_SUBJECT: ${VAPID_SUBJECT:-} - # Push keys. Empty = generated on first start and kept in the data - # volume (recommended). Set both only to pin specific keys. - VAPID_PUBLIC_KEY: ${VAPID_PUBLIC_KEY:-} - VAPID_PRIVATE_KEY: ${VAPID_PRIVATE_KEY:-} - # 1 = turn push notifications off. - PUSH_DISABLED: ${PUSH_DISABLED:-0} - # Fixed for the container; no need to change these. - HOST: 0.0.0.0 - PORT: "8080" - DATA_DIR: /data - STATIC_DIR: /app/web - TRUST_PROXY: "1" - volumes: - - oweme-data:/data - healthcheck: - test: ["CMD", "wget", "-qO-", "http://127.0.0.1:8080/api/health"] - interval: 30s - timeout: 5s - # No ports: the panel publishes 8080 for its routes; standalone, only - # Caddy reaches the app. - - caddy: - profiles: [standalone] - image: docker.io/library/caddy:2.10.2-alpine - restart: unless-stopped - depends_on: - - app - environment: - # Public hostname for standalone HTTPS (needs a DNS record). - DOMAIN: ${DOMAIN:-localhost} - ports: - # Rootless Podman can't bind ports below 1024 by default; see - # deploy/README.md "Ports". - - "${BIND_ADDR:-0.0.0.0}:${HTTP_PORT:-80}:80" - - "${BIND_ADDR:-0.0.0.0}:${HTTPS_PORT:-443}:443" - - "${BIND_ADDR:-0.0.0.0}:${HTTPS_PORT:-443}:443/udp" - volumes: - - ./deploy/Caddyfile:/etc/caddy/Caddyfile:ro,Z - - caddy-data:/data - - caddy-config:/config - -volumes: - oweme-data: - caddy-data: - caddy-config: diff --git a/deploy/.env.example b/deploy/.env.example new file mode 100644 index 0000000..d40ace4 --- /dev/null +++ b/deploy/.env.example @@ -0,0 +1,23 @@ +# Copy to deploy/.env and `chmod 600 deploy/.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) +# Leave empty to disable notifications. +VAPID_SUBJECT=mailto:you@example.com +VAPID_PUBLIC_KEY= +VAPID_PRIVATE_KEY= + +# Limits (bytes). Defaults shown. +MAX_PHOTO_BYTES=2097152 +MAX_EVENT_BYTES=65536 +MAX_GROUP_BYTES=209715200 +GROUP_CREATE_PER_HOUR=10 + +# Where Caddy listens. Defaults: all interfaces, ports 80/443. +#BIND_ADDR=0.0.0.0 +#HTTP_PORT=80 +#HTTPS_PORT=443 diff --git a/deploy/README.md b/deploy/README.md index 41c1809..d07d670 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -1,48 +1,60 @@ -# Deploying OweMe +# Deploying OweMe on a VPS -`compose.yaml` (repo root) runs the **app** container: the Node server plus -the built web client, listening on port 8080, with its data in the -`oweme-data` volume. It needs **no configuration**: push keys are generated -on first start and kept in the volume. Every setting is an optional -environment variable, listed with its default in `compose.yaml`. +Two containers via `podman compose`: **app** (the Node server plus the built +web client) and **caddy** (HTTPS and reverse proxy). Only Caddy publishes ports. -HTTPS comes either from the panel's Caddy or, standalone, from a Caddy -container enabled with the `standalone` profile. +## Requirements -## With the panel +- Podman ≥ 4 with `podman compose` (podman-compose or docker-compose as the provider) +- A domain with an A/AAAA record pointing at the VPS +- Ports 80 and 443 (TCP, plus UDP 443 for HTTP/3) open in the firewall -1. **New app → Git repository**: this repo, branch `main`. The panel finds - `compose.yaml` in the repository root. -2. **Domain**: point it at service **`app`**, port **`8080`**. The panel - publishes the port on 127.0.0.1 and its Caddy serves HTTPS. -3. **Environment** (optional): any variable from `compose.yaml`, for example - `MAX_PHOTO_BYTES=5242880` or `VAPID_SUBJECT=mailto:you@example.com`. - Untick **Pass to every container**. `compose.yaml` already passes each - setting to the app, and the panel's per-container copy currently makes - podman-compose fail with `can't merge value of [KEY] …` for variables the - compose file also sets. -4. **Deploy.** Check `https:///api/health` → `{"ok":true}`. - -Changing a variable takes effect on the next deploy. Volume backups in the -panel include the `oweme-data` volume (database, encrypted photos, push keys). - -## Standalone (no panel) - -Requirements: Podman ≥ 4 with podman-compose ≥ 1.1 (for profiles), a domain -with an A/AAAA record pointing at the server, and ports 80 and 443 (TCP, plus -UDP 443 for HTTP/3) open. +## First deploy ```sh -git clone oweme && cd oweme -cp .env.example .env && chmod 600 .env -$EDITOR .env # set DOMAIN -podman compose --profile standalone up -d --build -podman compose logs -f # Caddy gets the certificate on the first request +git clone oweme && cd oweme/deploy + +cp .env.example .env +chmod 600 .env +$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 compose up -d +podman compose logs -f # Caddy obtains the certificate on first request ``` -Updating: `git pull && podman compose --profile standalone up -d --build`. +Open `https://$DOMAIN`. `curl https://$DOMAIN/api/health` should say `{"ok":true}`. -### Ports (rootless Podman) +## Updating + +```sh +cd oweme && git pull +cd deploy && podman compose up -d --build +``` + +Data lives in the `oweme-data` volume and survives rebuilds. + +## Configuration (`deploy/.env`) + +| Variable | Required | Default | Purpose | +|---|---|---|---| +| `DOMAIN` | yes | — | Public hostname; Caddy's site address and certificate | +| `VAPID_SUBJECT` | for push | — | `mailto:` contact sent to push services | +| `VAPID_PUBLIC_KEY` / `VAPID_PRIVATE_KEY` | for push | — | Generated by `gen-vapid.ts`; empty = notifications off | +| `MAX_PHOTO_BYTES` | no | `2097152` | Max size of one uploaded (encrypted) photo | +| `MAX_EVENT_BYTES` | no | `65536` | Max size of one encrypted event | +| `MAX_GROUP_BYTES` | no | `209715200` | Storage cap per group (events + photos) | +| `GROUP_CREATE_PER_HOUR` | no | `10` | Group creations per client IP per hour | +| `BIND_ADDR` | no | `0.0.0.0` | Address Caddy's ports are published on | +| `HTTP_PORT` / `HTTPS_PORT` | no | `80` / `443` | Host ports for Caddy | + +Rotating the VAPID keys (`gen-vapid.ts … --force`) silently invalidates every +push subscription; users have to toggle notifications off and on again. + +## Ports (rootless Podman) Rootless Podman can't bind ports below 1024 by default. Pick one: @@ -51,52 +63,30 @@ Rootless Podman can't bind ports below 1024 by default. Pick one: echo 'net.ipv4.ip_unprivileged_port_start=80' | sudo tee /etc/sysctl.d/90-unprivileged-ports.conf sudo sysctl --system ``` -2. Or publish high ports (`HTTP_PORT=8080`, `HTTPS_PORT=8443` in `.env`) and - redirect 80→8080 / 443→8443 in your firewall. +2. Or publish high ports (`HTTP_PORT=8080`, `HTTPS_PORT=8443`) and redirect + 80→8080 / 443→8443 in your firewall (e.g. nftables/UFW `nat` rules). With rootless Podman, published ports go through `rootlessport` and are subject to the host firewall. Rootful container networking can add its own firewall rules around UFW, so don't rely on UFW alone if you run rootful. -## Settings - -All optional. Set them in the panel's Environment tab, or in `.env` for a -standalone deploy. - -| Variable | Default | Purpose | -|---|---|---| -| `MAX_PHOTO_BYTES` | `2097152` | Max size of one uploaded (encrypted) photo | -| `MAX_EVENT_BYTES` | `65536` | Max size of one encrypted event | -| `MAX_GROUP_BYTES` | `209715200` | Storage cap per group (events + photos) | -| `GROUP_CREATE_PER_HOUR` | `10` | Group creations per client IP per hour | -| `VAPID_SUBJECT` | `https://` | Contact sent to push services | -| `VAPID_PUBLIC_KEY` / `VAPID_PRIVATE_KEY` | generated | Pin push keys (set both); otherwise kept in the volume as `vapid.json` | -| `PUSH_DISABLED` | `0` | `1` turns push notifications off | -| `DOMAIN` | `localhost` | Standalone only: Caddy's site address and certificate | -| `BIND_ADDR` | `0.0.0.0` | Standalone only: address Caddy's ports are published on | -| `HTTP_PORT` / `HTTPS_PORT` | `80` / `443` | Standalone only: host ports for Caddy | - -Deleting `vapid.json` from the volume (or changing pinned keys) invalidates -every push subscription; people then turn notifications off and on again. - ## Backups -The `oweme-data` volume holds everything (SQLite database, encrypted photos, -push keys). Its contents are end-to-end encrypted, so backups can be stored -anywhere. Standalone: +Back up the `oweme-data` volume (SQLite database + encrypted photos): ```sh podman volume export oweme_oweme-data > oweme-data-$(date +%F).tar ``` -People can also download per-group backup files in the app. +Everything in it is already end-to-end encrypted, so the backup can be stored +anywhere. Users can also download per-group backup files in the app. ## Testing a deployment From a machine with the repo and Node 24: ```sh -npm ci && E2E_BASE_URL=https:// npx playwright test e2e/app.spec.ts +npm ci && E2E_BASE_URL=https://$DOMAIN npx playwright test e2e/app.spec.ts ``` This creates a throwaway group on that server. diff --git a/deploy/compose.yaml b/deploy/compose.yaml new file mode 100644 index 0000000..c5ccc90 --- /dev/null +++ b/deploy/compose.yaml @@ -0,0 +1,49 @@ +# podman compose up -d --build (run from this directory; reads ./.env) +# See deploy/README.md for the full deploy steps. +name: oweme + +services: + app: + build: + context: .. + dockerfile: deploy/Containerfile + image: localhost/oweme:latest + restart: unless-stopped + env_file: .env + environment: + # fixed inside the container; everything else comes from .env + HOST: 0.0.0.0 + PORT: "8080" + DATA_DIR: /data + STATIC_DIR: /app/web + TRUST_PROXY: "1" + volumes: + - oweme-data:/data + healthcheck: + test: ["CMD", "wget", "-qO-", "http://127.0.0.1:8080/api/health"] + interval: 30s + timeout: 5s + # no published ports: only Caddy can reach the app + + caddy: + image: docker.io/library/caddy:2.10.2-alpine + restart: unless-stopped + depends_on: + - app + environment: + DOMAIN: ${DOMAIN:?set DOMAIN in deploy/.env} + ports: + # BIND_ADDR defaults to all interfaces (a public VPS). Rootless Podman + # can't bind ports below 1024 by default; see README "Ports". + - "${BIND_ADDR:-0.0.0.0}:${HTTP_PORT:-80}:80" + - "${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 + - caddy-data:/data + - caddy-config:/config + +volumes: + oweme-data: + caddy-data: + caddy-config: