Add podman compose deployment, dev script and docs
Containerfile + compose (app + Caddy with automatic HTTPS), env-driven domain/limits/ports, VAPID key generation that never prints the key. SPEC updated to match the implementation (Node stdlib server, Svelte SPA, revert by event id, backup contents, push options). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013FYo6JSV1fDU1fm3LU77iF
This commit is contained in:
parent
a78d855886
commit
8c4e37ce4b
9 changed files with 365 additions and 42 deletions
23
deploy/.env.example
Normal file
23
deploy/.env.example
Normal 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
|
||||
10
deploy/Caddyfile
Normal file
10
deploy/Caddyfile
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# Automatic HTTPS for $DOMAIN (Let's Encrypt / ZeroSSL). HTTPS is required:
|
||||
# WebCrypto, service workers and push only work in a secure context.
|
||||
# Security headers (CSP etc.) are set by the app itself.
|
||||
{$DOMAIN} {
|
||||
encode zstd gzip
|
||||
reverse_proxy app:8080 {
|
||||
# Server-Sent Events: don't buffer
|
||||
flush_interval -1
|
||||
}
|
||||
}
|
||||
29
deploy/Containerfile
Normal file
29
deploy/Containerfile
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
# OweMe: one image with the server (Node standard library only, no
|
||||
# node_modules) and the built web client. Build context: the repo root.
|
||||
|
||||
FROM docker.io/library/node:24.21.0-alpine AS build
|
||||
WORKDIR /src
|
||||
COPY package.json package-lock.json ./
|
||||
COPY packages/core/package.json packages/core/
|
||||
COPY apps/web/package.json apps/web/
|
||||
# --ignore-scripts: no install hooks from dependencies run during the build.
|
||||
RUN npm ci --no-audit --no-fund --ignore-scripts
|
||||
COPY packages/core packages/core
|
||||
COPY apps/web apps/web
|
||||
RUN npm run build -w apps/web
|
||||
|
||||
FROM docker.io/library/node:24.21.0-alpine
|
||||
WORKDIR /app
|
||||
ENV NODE_ENV=production \
|
||||
HOST=0.0.0.0 \
|
||||
PORT=8080 \
|
||||
DATA_DIR=/data \
|
||||
STATIC_DIR=/app/web \
|
||||
TRUST_PROXY=1
|
||||
COPY apps/server/src ./server
|
||||
COPY --from=build /src/apps/web/dist ./web
|
||||
RUN mkdir -p /data && chown node:node /data
|
||||
USER node
|
||||
VOLUME /data
|
||||
EXPOSE 8080
|
||||
CMD ["node", "--disable-warning=ExperimentalWarning", "server/main.ts"]
|
||||
92
deploy/README.md
Normal file
92
deploy/README.md
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
# Deploying OweMe on a VPS
|
||||
|
||||
Two containers via `podman compose`: **app** (the Node server plus the built
|
||||
web client) and **caddy** (HTTPS and reverse proxy). Only Caddy publishes ports.
|
||||
|
||||
## Requirements
|
||||
|
||||
- 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
|
||||
|
||||
## First deploy
|
||||
|
||||
```sh
|
||||
git clone <repo> 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
|
||||
```
|
||||
|
||||
Open `https://$DOMAIN`. `curl https://$DOMAIN/api/health` should say `{"ok":true}`.
|
||||
|
||||
## 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:
|
||||
|
||||
1. Allow it (simplest):
|
||||
```sh
|
||||
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`) 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.
|
||||
|
||||
## Backups
|
||||
|
||||
Back up the `oweme-data` volume (SQLite database + encrypted photos):
|
||||
|
||||
```sh
|
||||
podman volume export oweme_oweme-data > oweme-data-$(date +%F).tar
|
||||
```
|
||||
|
||||
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://$DOMAIN npx playwright test e2e/app.spec.ts
|
||||
```
|
||||
|
||||
This creates a throwaway group on that server.
|
||||
49
deploy/compose.yaml
Normal file
49
deploy/compose.yaml
Normal 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:
|
||||
Loading…
Add table
Add a link
Reference in a new issue