services: app: image: ghcr.io/erp-mafia/gnubok:${IMAGE_TAG:-latest} env_file: .env # Bound to loopback by default: put a TLS-terminating reverse proxy in # front (see docker-compose.caddy.yml). Override PORT in .env to change # the host port, or use the caddy overlay to remove the host binding. ports: - "127.0.0.1:${PORT:-3000}:3000" security_opt: - no-new-privileges:true cap_drop: - ALL read_only: true init: true # tmpfs ordering matters: the parent /app/.next must be mounted before # any sub-mounts. The entrypoint cp's image-baked templates into these # mounts at startup, then sed-substitutes the NEXT_PUBLIC_* placeholders, # then drops the write bits. # # uid=1001 (nextjs), mode=750: the entrypoint runs UNPRIVILEGED as nextjs # and owns these mounts, so it can populate them with no CAP_CHOWN/CAP_SETUID, # which is what lets the container run under `cap_drop: ALL`. nodejs-group # members can read the served bundle; nothing else on the host can. tmpfs: - /tmp - /app/.next:uid=1001,gid=1001,mode=750,size=400m - /app/public:uid=1001,gid=1001,mode=750,size=200m # CPU limits are intentionally left to host tooling or a local override. # Some Compose builds bundled with NAS platforms reject the `cpus` key. mem_limit: 1g pids_limit: 200 restart: unless-stopped healthcheck: # 127.0.0.1, not localhost: the app binds 0.0.0.0 (IPv4) but localhost can # resolve to ::1 (IPv6), where nothing listens → false-unhealthy → the # cron service (depends_on healthy) never starts. test: ["CMD", "wget", "-q", "--spider", "http://127.0.0.1:3000/api/health"] interval: 30s timeout: 5s start_period: 30s # `start_interval` requires Docker Compose 2.20.2+ and Docker Engine 25.0+. # Omitting it keeps the base file usable with older NAS container stacks. retries: 3 logging: driver: json-file options: max-size: "10m" max-file: "5" cron: build: context: docker dockerfile: cron.Dockerfile depends_on: app: condition: service_healthy environment: - CRON_SECRET=${CRON_SECRET} - APP_URL=http://app:3000 volumes: - ./docker/crontab.self-hosted:/etc/supercronic/crontab:ro init: true security_opt: - no-new-privileges:true cap_drop: - ALL read_only: true tmpfs: - /tmp # 2026-11-15: pids_limit 30 gav "fork/exec /bin/sh: resource temporarily # unavailable" i 14,3 % av cron-körningarna (1 497 av 10 455 senaste dygnet) # när flera scheman (var 1/2/5/10 min) sammanföll — jobben hoppades över # utan larm. 200 pids och 256 MiB ger marginal; uppmätt behov är ~17 pids # och ~12 MiB i drift. mem_limit: 256m pids_limit: 200 healthcheck: # 2026-11-15: this used to be `ps ax | grep supercronic`, which stays green # while the scheduler process is up but ticks are being dropped — exactly # what happened when pids_limit 30 made 14,3 % of runs fail to fork (see # docker-compose.accounted.yml and the cron_heartbeats migration). Ask the # app instead: /api/cron/health answers 503 when any schedule has not run # within its own worst-case window, so a silent stop makes this container # unhealthy and reaches alerting. `$$` is required — a single `$` would be # interpolated by compose on the host instead of by the shell in here. test: - CMD-SHELL - 'curl -fsS -m 10 -o /dev/null -H "Authorization: Bearer $${CRON_SECRET}" "$${APP_URL}/api/cron/health"' interval: 60s timeout: 15s retries: 3 # The probe calls the app over HTTP, so it can only pass once the app # answers. 30 s was too tight for a cold `docker compose up` and produced # a false unhealthy. start_period: 120s restart: unless-stopped logging: driver: json-file options: max-size: "10m" max-file: "5"