Compare commits

..

No commits in common. "9cd4c8211811734e897d66b9d60c9288e7dcc4a6" and "41b3487a5a19dd679209b82439783d7c1318248a" have entirely different histories.

15 changed files with 203 additions and 252 deletions

View file

@ -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

View file

@ -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

1
.gitignore vendored
View file

@ -2,6 +2,7 @@ node_modules/
dist/ dist/
data/ data/
.env .env
deploy/.env
test-results/ test-results/
playwright-report/ playwright-report/
*.log *.log

View file

@ -13,10 +13,7 @@ End-to-end encrypted group expense splitter (a Settle Up clone). Read
that way unless there's a strong reason. that way unless there's a strong reason.
- `apps/web/` — Svelte 5 SPA + service worker (`src/sw.ts`, built separately - `apps/web/` — Svelte 5 SPA + service worker (`src/sw.ts`, built separately
by `vite.sw.config.ts` as a classic script). by `vite.sw.config.ts` as a classic script).
- `compose.yaml` (repo root) — the deployment; the panel needs it at the root. - `deploy/` — Containerfile, compose.yaml, Caddyfile, `.env.example`, deploy docs.
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.
- `e2e/` — Playwright tests against the production build. - `e2e/` — Playwright tests against the production build.
## Run ## Run
@ -59,4 +56,4 @@ notifications.
Push payloads carry only the group id. Push payloads carry only the group id.
7. Strict CSP: no inline scripts, no third-party origins. 7. Strict CSP: no inline scripts, no third-party origins.
8. Containers: rootless Podman; for local testing publish to `127.0.0.1` only 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`).

62
SPEC.md
View file

@ -496,40 +496,52 @@ Repo layout (monorepo):
apps/web Svelte client + service worker apps/web Svelte client + service worker
apps/server Node API (no dependencies) apps/server Node API (no dependencies)
packages/core shared: types, event schema, money math, replay, settle-up, recurring, stats, CSV packages/core shared: types, event schema, money math, replay, settle-up, recurring, stats, CSV
compose.yaml podman compose deployment (with .env.example) deploy/ Containerfile, compose.yaml, Caddyfile, .env.example, README
deploy/ Containerfile, Caddyfile, README
e2e/ Playwright tests 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 `deploy/compose.yaml` runs two services:
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://<site domain>`.
Every setting is an optional environment variable, written in `compose.yaml` - `app`: the Node server, which also serves the built static client. Listens
as `${VAR:-default}` so it is visible and documented in one place: on the internal network only.
`MAX_PHOTO_BYTES`, `MAX_EVENT_BYTES`, `MAX_GROUP_BYTES`, - `caddy`: TLS termination + reverse proxy, the only service publishing
`GROUP_CREATE_PER_HOUR`, `VAPID_SUBJECT`, `VAPID_PUBLIC_KEY` / ports (80/443).
`VAPID_PRIVATE_KEY` (pin keys), `PUSH_DISABLED`.
- **With the panel** (the main target): the panel clones the repo, finds Volumes: `oweme-data` (SQLite + blobs), `caddy-data` (certificates).
`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`.
Step-by-step instructions, the full settings table, ports for rootless Podman Deploy steps (documented in `deploy/README.md`):
and backups are 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 Development (on the dev box): servers bind `127.0.0.1` only; preview over an
SSH tunnel. Ports and commands go in `AGENTS.md`. SSH tunnel. Ports and commands go in `AGENTS.md`.

View file

@ -6,7 +6,7 @@ import type { IncomingMessage, ServerResponse } from 'node:http';
import { extname, join, normalize, sep } from 'node:path'; import { extname, join, normalize, sep } from 'node:path';
import type { Config } from './config.ts'; import type { Config } from './config.ts';
import type { Store } from './db.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 ID_RE = /^[A-Za-z0-9_-]{22}$/; // 16 random bytes, base64url
const EVENT_ID_RE = /^[A-Za-z0-9_-]{8,100}$/; 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<string, Set<ServerResponse>>(); const streams = new Map<string, Set<ServerResponse>>();
const createLimiter = new RateLimiter(cfg.groupCreatePerHour, 3600_000); const createLimiter = new RateLimiter(cfg.groupCreatePerHour, 3600_000);
const pushLimiter = new RateLimiter(60, 3600_000); const pushLimiter = new RateLimiter(60, 3600_000);
const keys = cfg.pushEnabled ? loadVapidKeys(cfg.dataDir, cfg.vapidPublicKey, cfg.vapidPrivateKey) : null; const vapid: Vapid | null =
if (keys) console.log(`push: VAPID keys from ${keys.source}`); cfg.vapidPublicKey && cfg.vapidPrivateKey && cfg.vapidSubject
const vapid: Vapid | null = keys ? { publicKey: keys.publicKey, privateKey: keys.privateKey, subject: cfg.vapidSubject } : null; ? { publicKey: cfg.vapidPublicKey, privateKey: cfg.vapidPrivateKey, subject: cfg.vapidSubject }
: null;
const blobDir = (g: string) => join(cfg.dataDir, 'blobs', g); const blobDir = (g: string) => join(cfg.dataDir, 'blobs', g);
function clientIp(req: IncomingMessage): string { function clientIp(req: IncomingMessage): string {
@ -140,18 +141,9 @@ export function createApp(cfg: Config, store: Store) {
return g; 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 { function notify(groupId: string, seq: number, deviceId: string): void {
for (const res of streams.get(groupId) ?? []) res.write(`data: ${seq}\n\n`); 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)) { for (const sub of store.pushSubs(groupId)) {
if (sub.deviceId === deviceId) continue; if (sub.deviceId === deviceId) continue;
void sendPush(sub, { g: groupId }, vapid).then((r) => { 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 }); 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/rates' && m === 'GET') return rates(res, url);
if (p === '/api/groups' && m === 'POST') return createGroup(req, res); if (p === '/api/groups' && m === 'POST') return createGroup(req, res);
rememberOrigin(req);
const g = /^\/api\/groups\/([^/]+)(\/.*)?$/.exec(p); const g = /^\/api\/groups\/([^/]+)(\/.*)?$/.exec(p);
if (g) { if (g) {

View file

@ -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'; import { resolve } from 'node:path';
function int(env: NodeJS.ProcessEnv, name: string, def: number): number { function int(env: NodeJS.ProcessEnv, name: string, def: number): number {
@ -23,7 +23,6 @@ export interface Config {
vapidPublicKey: string; vapidPublicKey: string;
vapidPrivateKey: string; vapidPrivateKey: string;
vapidSubject: string; vapidSubject: string;
pushEnabled: boolean;
ratesEnabled: boolean; ratesEnabled: boolean;
ratesBaseUrl: string; ratesBaseUrl: string;
} }
@ -42,7 +41,6 @@ export function loadConfig(env = process.env): Config {
vapidPublicKey: env.VAPID_PUBLIC_KEY || '', vapidPublicKey: env.VAPID_PUBLIC_KEY || '',
vapidPrivateKey: env.VAPID_PRIVATE_KEY || '', vapidPrivateKey: env.VAPID_PRIVATE_KEY || '',
vapidSubject: env.VAPID_SUBJECT || '', vapidSubject: env.VAPID_SUBJECT || '',
pushEnabled: env.PUSH_DISABLED !== '1',
ratesEnabled: env.RATES_DISABLED !== '1', ratesEnabled: env.RATES_DISABLED !== '1',
ratesBaseUrl: env.RATES_BASE_URL || 'https://www.ecb.europa.eu/stats/eurofxref', ratesBaseUrl: env.RATES_BASE_URL || 'https://www.ecb.europa.eu/stats/eurofxref',
}; };

View file

@ -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 <env-file> [--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).`);

View file

@ -16,7 +16,7 @@ if (cfg.ratesEnabled) rates.start();
server.listen(cfg.port, cfg.host, () => { server.listen(cfg.port, cfg.host, () => {
console.log(`oweme server on http://${cfg.host}:${cfg.port}` + (cfg.staticDir ? ` serving ${cfg.staticDir}` : ' (API only)')); 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) { for (const sig of ['SIGINT', 'SIGTERM'] as const) {

View file

@ -3,8 +3,6 @@
// the service worker fetches and decrypts the actual events itself, so the // the service worker fetches and decrypts the actual events itself, so the
// push service never sees content (SPEC.md §7.7). // push service never sees content (SPEC.md §7.7).
import { createCipheriv, createECDH, createPrivateKey, hkdfSync, randomBytes, sign } from 'node:crypto'; 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'; import type { PushSub } from './db.ts';
const b64u = (b: Buffer | Uint8Array) => Buffer.from(b).toString('base64url'); 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()) }; 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 { export interface Vapid {
publicKey: string; publicKey: string;
privateKey: string; privateKey: string;

View file

@ -8,7 +8,7 @@ import { after, before, describe, it } from 'node:test';
import { createApp } from '../src/app.ts'; import { createApp } from '../src/app.ts';
import { loadConfig } from '../src/config.ts'; import { loadConfig } from '../src/config.ts';
import { Store } from '../src/db.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'; import { parseEcbXml } from '../src/rates.ts';
const b64u = (b: Buffer) => b.toString('base64url'); 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', () => { describe('web push encryption', () => {
it('produces an RFC 8291 payload the browser side can decrypt', () => { it('produces an RFC 8291 payload the browser side can decrypt', () => {
// Play the browser: generate a subscription key pair and auth secret. // Play the browser: generate a subscription key pair and auth secret.

View file

@ -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://<the site's domain>.
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:

23
deploy/.env.example Normal file
View file

@ -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

View file

@ -1,48 +1,60 @@
# Deploying OweMe # Deploying OweMe on a VPS
`compose.yaml` (repo root) runs the **app** container: the Node server plus Two containers via `podman compose`: **app** (the Node server plus the built
the built web client, listening on port 8080, with its data in the web client) and **caddy** (HTTPS and reverse proxy). Only Caddy publishes ports.
`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`.
HTTPS comes either from the panel's Caddy or, standalone, from a Caddy ## Requirements
container enabled with the `standalone` profile.
## 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 ## First deploy
`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://<domain>/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.
```sh ```sh
git clone <repo> oweme && cd oweme git clone <repo> oweme && cd oweme/deploy
cp .env.example .env && chmod 600 .env
$EDITOR .env # set DOMAIN cp .env.example .env
podman compose --profile standalone up -d --build chmod 600 .env
podman compose logs -f # Caddy gets the certificate on the first request $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: 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 echo 'net.ipv4.ip_unprivileged_port_start=80' | sudo tee /etc/sysctl.d/90-unprivileged-ports.conf
sudo sysctl --system sudo sysctl --system
``` ```
2. Or publish high ports (`HTTP_PORT=8080`, `HTTPS_PORT=8443` in `.env`) and 2. Or publish high ports (`HTTP_PORT=8080`, `HTTPS_PORT=8443`) and redirect
redirect 80→8080 / 443→8443 in your firewall. 80→8080 / 443→8443 in your firewall (e.g. nftables/UFW `nat` rules).
With rootless Podman, published ports go through `rootlessport` and are With rootless Podman, published ports go through `rootlessport` and are
subject to the host firewall. Rootful container networking can add its own 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. 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://<site domain>` | 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 ## Backups
The `oweme-data` volume holds everything (SQLite database, encrypted photos, Back up the `oweme-data` volume (SQLite database + encrypted photos):
push keys). Its contents are end-to-end encrypted, so backups can be stored
anywhere. Standalone:
```sh ```sh
podman volume export oweme_oweme-data > oweme-data-$(date +%F).tar 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 ## Testing a deployment
From a machine with the repo and Node 24: From a machine with the repo and Node 24:
```sh ```sh
npm ci && E2E_BASE_URL=https://<domain> 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. This creates a throwaway group on that server.

49
deploy/compose.yaml Normal file
View file

@ -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: