Let a server service carry helper scripts and timers, starting with UseSend's cert refresh

This commit is contained in:
Gabriel Brown committed 2026-10-30 13:44:29 -04:00
1 parent a987cbab66
commit 95fa480469
9 files changed
+304 -59

No files matched your search

+69 -30
View File
@@ -21,25 +21,69 @@ services:
tty: true
stdin_open: true
restart: unless-stopped
minio:
image: minio/minio
# S3-compatible storage for images uploaded in the email editor, following
# upstream's docker/prod/compose.yml (RustFS replaced MinIO, whose images are
# no longer published). The browser uploads straight to S3_COMPATIBLE_API_URL
# and sent emails link to S3_COMPATIBLE_PUBLIC_URL, so NPM proxies
# storage.usesend.gbrown.org -> http://usesend-storage:9000. No host ports:
# the console (9001) is only reachable from inside nginx-bridge.
# Pinned like upstream. Bump the tag deliberately when upstream does.
rustfs:
image: docker.io/rustfs/rustfs:1.0.4
container_name: usesend-storage
hostname: usesend-storage
networks:
- nginx-bridge
env_file: .env
# RustFS runs as uid 10001; keep-id keeps ./volumes/rustfs gib-owned (AGENTS.md §3.2)
userns_mode: keep-id:uid=10001,gid=10001
security_opt:
- no-new-privileges:true
environment:
MINIO_ROOT_USER: ${MINIO_ROOT_USER}
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD}
labels:
com.centurylinklabs.watchtower.enable: 'true'
RUSTFS_ACCESS_KEY: ${RUSTFS_ACCESS_KEY:?err}
RUSTFS_SECRET_KEY: ${RUSTFS_SECRET_KEY:?err}
RUSTFS_ADDRESS: 0.0.0.0:9000
RUSTFS_CONSOLE_ADDRESS: 0.0.0.0:9001
RUSTFS_CONSOLE_ENABLE: 'true'
RUSTFS_OBS_LOGGER_LEVEL: error
TZ: America/New_York
volumes:
- ./volumes/minio:/data:Z
entrypoint: sh
command: -c 'mkdir -p /data/unsend && minio server /data --console-address ':9001' --address ':9002''
tty: true
stdin_open: true
- ./volumes/rustfs:/data:Z
command: ["/data"]
healthcheck:
test: ["CMD", "curl", "-fsS", "http://127.0.0.1:9000/health"]
interval: 20s
timeout: 10s
retries: 5
start_period: 40s
restart: unless-stopped
# One-shot: creates the bucket, allows browser uploads from the app (CORS) and
# makes objects publicly readable so images load in sent emails. Reruns on
# every unit start, which is harmless.
rustfs-init:
image: docker.io/amazon/aws-cli:2.34.30
container_name: usesend-storage-init
networks:
- nginx-bridge
entrypoint: ["/bin/sh", "-ec"]
environment:
AWS_ACCESS_KEY_ID: ${RUSTFS_ACCESS_KEY:?err}
AWS_SECRET_ACCESS_KEY: ${RUSTFS_SECRET_KEY:?err}
AWS_DEFAULT_REGION: us-east-1
AWS_EC2_METADATA_DISABLED: 'true'
BUCKET: ${S3_COMPATIBLE_BUCKET:-unsend}
APP_ORIGIN: ${USESEND_URL:?err}
depends_on:
rustfs:
condition: service_healthy
command:
- |
s3="aws --endpoint-url http://usesend-storage:9000 s3api"
$$s3 head-bucket --bucket "$$BUCKET" >/dev/null 2>&1 || $$s3 create-bucket --bucket "$$BUCKET"
$$s3 put-bucket-cors --bucket "$$BUCKET" --cors-configuration \
'{"CORSRules":[{"AllowedOrigins":["'"$$APP_ORIGIN"'"],"AllowedMethods":["GET","HEAD","PUT"],"AllowedHeaders":["*"],"ExposeHeaders":["ETag"],"MaxAgeSeconds":3600}]}'
$$s3 put-bucket-policy --bucket "$$BUCKET" --policy \
'{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":"*","Action":["s3:GetObject"],"Resource":["arn:aws:s3:::'"$$BUCKET"'/*"]}]}'
restart: 'no'
smtp-server:
image: usesend/smtp-proxy:latest
container_name: usesend-smtp-server
@@ -47,26 +91,15 @@ services:
networks:
nginx-bridge:
# The proxy REQUIRES STARTTLS before it will accept AUTH, so clients must
# reach it by a name the certificate actually covers. The wildcard is
# *.gbrown.org, which matches ONE label -- hence smtp-usesend, not
# smtp.usesend.
# reach it by a name the certificate actually covers: smtp.usesend.gbrown.org,
# validated by the *.usesend.gbrown.org SAN on npm-43 (see certs/README.md).
#
# Resolution: podman's aardvark-dns answers this name authoritatively for
# containers ON nginx-bridge, handing back the container IP. NPM is not
# involved at all -- it only reverse-proxies HTTP(S), and SMTP ports are
# never published to the host, so the proxy is unreachable from outside.
#
# NOTE: there IS a wildcard *.gbrown.org record in Cloudflare, so this name
# also resolves publicly (to Cloudflare, which serves nothing for it). The
# consequence: if this container is STOPPED, aardvark-dns stops answering,
# the lookup falls through to that public record, and clients dial
# Cloudflare on 587 and hang until timeout instead of failing fast.
# involved at all -- it only reverse-proxies HTTP(S). Cloudflare is not
# involved either: there is deliberately no public DNS record for this name,
# so if the container is stopped, lookups fail fast with NXDOMAIN.
aliases:
# Both names resolve to this container and BOTH validate against npm-43,
# which carries *.gbrown.org and *.usesend.gbrown.org. smtp.usesend is the
# name UseSend's own UI advertises and is the target to standardise on;
# smtp-usesend stays until every consumer has been moved across.
- smtp-usesend.gbrown.org
- smtp.usesend.gbrown.org
env_file: .env
environment:
@@ -83,8 +116,8 @@ services:
# brute-force it, and contradicts the Cloudflare-only posture in §7.
# The `Home` wg interface sits in firewalld's `trusted` zone, so no rule is needed.
# Rootless can bind these because net.ipv4.ip_unprivileged_port_start = 80.
# Consumers on the home server reach it as smtp-usesend.gbrown.org (UniFi DNS maps
# that name to 192.168.2.2) so the *.gbrown.org cert still validates by hostname.
# Consumers on the home server reach it as smtp.usesend.gbrown.org (a UniFi DNS record
# maps that name to 192.168.2.2) so the cert still validates by hostname.
- "192.168.2.2:587:587"
- "192.168.2.2:465:465"
volumes:
@@ -121,6 +154,12 @@ services:
- API_RATE_LIMIT=${API_RATE_LIMIT:-1}
- SMTP_HOST=${SMTP_HOST:-smtp.usesend.gbrown.org}
- SMTP_USER=${SMTP_USER:-usesend}
# Editor image uploads (the rustfs service above). Uploads are disabled if any is unset.
- S3_COMPATIBLE_ACCESS_KEY=${RUSTFS_ACCESS_KEY:?err}
- S3_COMPATIBLE_SECRET_KEY=${RUSTFS_SECRET_KEY:?err}
- S3_COMPATIBLE_API_URL=${S3_COMPATIBLE_API_URL:?err}
- S3_COMPATIBLE_PUBLIC_URL=${S3_COMPATIBLE_PUBLIC_URL:?err}
- S3_COMPATIBLE_BUCKET=${S3_COMPATIBLE_BUCKET:-unsend}
labels:
com.centurylinklabs.watchtower.enable: 'true'
depends_on: