From f7a2ded6801ef06b8030567351e1814a6b22d9d2 Mon Sep 17 00:00:00 2001 From: tajniak81 <13187254+tajniak81@users.noreply.github.com> Date: Wed, 18 Nov 2026 19:29:46 +0100 Subject: [PATCH] Give the all-in-one setup every storage shape, from source and baked in Docker-AIO now has one compose file per storage shape for each way of getting the image, each with an .env template of the same name: - From source: docker-compose.yml (now with .env.example), docker-compose.s3.yml, docker-compose.seaweedfs.yml and docker-compose.seaweedfs.split.yml. The SeaweedFS ones run it in containers beside the plain image, as the prod files did before. - Production: docker-compose.prod.seaweedfs*.yml now run one container from new images with SeaweedFS built in. Dockerfile.seaweedfs runs `weed server -s3`; Dockerfile.seaweedfs.split runs master, volume, filer, S3 gateway and admin UI as separate processes, and seeds PocketBase's key into the filer's IAM store so the admin UI cannot displace it. SeaweedFS listens on the container's loopback (volume server on 8081, as docwell-server has 8080); only the split image's admin UI is published, on loopback by default. start.sh now also watches the processes a wrapper started, so the container restarts as a whole when any SeaweedFS role stops. The release workflow publishes the two new images, docwell-seaweedfs and docwell-seaweedfs-split. Existing SeaweedFS installs keep their data: every file uses the `weed server -dir` layout. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 8 + Docker-AIO/.env.example | 75 +++++ Docker-AIO/.env.prod.seaweedfs.example | 23 +- Docker-AIO/.env.prod.seaweedfs.split.example | 24 +- Docker-AIO/.env.s3.example | 96 ++++++ Docker-AIO/.env.seaweedfs.example | 94 ++++++ Docker-AIO/.env.seaweedfs.split.example | 107 +++++++ Docker-AIO/Dockerfile.seaweedfs | 112 +++++++ Docker-AIO/Dockerfile.seaweedfs.split | 120 ++++++++ Docker-AIO/README.md | 69 ++++- .../docker-compose.prod.seaweedfs.split.yml | 288 +++++------------- Docker-AIO/docker-compose.prod.seaweedfs.yml | 148 ++++----- Docker-AIO/docker-compose.s3.yml | 106 +++++++ Docker-AIO/docker-compose.seaweedfs.split.yml | 277 +++++++++++++++++ Docker-AIO/docker-compose.seaweedfs.yml | 152 +++++++++ Docker-AIO/docker-compose.yml | 20 +- Docker-AIO/start-seaweedfs-split.sh | 99 ++++++ Docker-AIO/start-seaweedfs.sh | 49 +++ Docker-AIO/start.sh | 20 +- 19 files changed, 1549 insertions(+), 338 deletions(-) create mode 100644 Docker-AIO/.env.example create mode 100644 Docker-AIO/.env.s3.example create mode 100644 Docker-AIO/.env.seaweedfs.example create mode 100644 Docker-AIO/.env.seaweedfs.split.example create mode 100644 Docker-AIO/Dockerfile.seaweedfs create mode 100644 Docker-AIO/Dockerfile.seaweedfs.split create mode 100644 Docker-AIO/docker-compose.s3.yml create mode 100644 Docker-AIO/docker-compose.seaweedfs.split.yml create mode 100644 Docker-AIO/docker-compose.seaweedfs.yml create mode 100644 Docker-AIO/start-seaweedfs-split.sh create mode 100644 Docker-AIO/start-seaweedfs.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dac6424..1b1dbf3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -56,6 +56,14 @@ jobs: - name: docwell context: . dockerfile: Docker-AIO/Dockerfile + # The all-in-one with SeaweedFS built in, for + # Docker-AIO/docker-compose.prod.seaweedfs*.yml. + - name: docwell-seaweedfs + context: . + dockerfile: Docker-AIO/Dockerfile.seaweedfs + - name: docwell-seaweedfs-split + context: . + dockerfile: Docker-AIO/Dockerfile.seaweedfs.split steps: - uses: actions/checkout@v4 diff --git a/Docker-AIO/.env.example b/Docker-AIO/.env.example new file mode 100644 index 0000000..5cfedf0 --- /dev/null +++ b/Docker-AIO/.env.example @@ -0,0 +1,75 @@ +# Docwell all-in-one, built from this checkout (Docker-AIO/docker-compose.yml). +# Copy to .env and fill in, then: +# docker compose up -d --build + +# --- Image ------------------------------------------------------------------- +# `up -d --build` builds this checkout and tags it with this name; without +# --build the released image is pulled. For images released on a Gitea server, +# DOCWELL_REGISTRY=/. +DOCWELL_REGISTRY=ghcr.io/docwell +DOCWELL_VERSION=latest + +# --- PocketBase superuser ---------------------------------------------------- +# Created or updated on every boot; the bundled server signs in with it. +# REQUIRED. +PB_ADMIN_EMAIL=admin@example.com +PB_ADMIN_PASSWORD=change-me-long-password + +# Encrypts PocketBase's stored settings (SMTP password, S3 secret). Exactly 32 +# characters, e.g. `openssl rand -hex 16`. Blank = off. Set it before the first +# boot and keep a copy: the settings cannot be read without it. +PB_ENCRYPTION_KEY= + +# --- Public address ---------------------------------------------------------- +# Where browsers reach Docwell. Behind a reverse proxy, the https:// name. +DOCWELL_WEB_URL=http://localhost:3000 + +# Name shown in emails and the browser tab. Blank = Docwell. +DOCWELL_APP_NAME= + +# The Draw.io editor to embed. Blank = https://embed.diagrams.net; point it at +# a self-hosted jgraph/drawio to keep drawings on your network. +DOCWELL_DRAWIO_URL= + +# --- Accounts ---------------------------------------------------------------- +# Sign-up defaults until a superadmin changes them in the admin panel. The +# first account can always sign up and becomes the instance admin. +DOCWELL_SIGNUP_ENABLED=true +# Comma-separated email domains allowed to sign up (blank = any). +DOCWELL_SIGNUP_DOMAINS= + +# Optional: the first account, created as superadmin on start while the +# instance has no accounts. Later starts leave it alone (change it in the +# admin panel). Password: 8 characters or more. Blank = first sign-up wins. +DOCWELL_ADMIN_EMAIL= +DOCWELL_ADMIN_PASSWORD= +DOCWELL_ADMIN_NAME= + +# Largest attachment in MB (1-100). +DOCWELL_MAX_UPLOAD_MB=50 +# Days to keep audit log entries. Blank = 365, 0 = forever. +DOCWELL_AUDIT_RETENTION_DAYS= + +# --- Email ------------------------------------------------------------------- +# Verification, password reset and sign-in codes, sent by PocketBase. Blank +# host = email off (and the admin panel's Mail screen stays in charge). +DOCWELL_SMTP_HOST= +DOCWELL_SMTP_PORT=587 +DOCWELL_SMTP_USERNAME= +DOCWELL_SMTP_PASSWORD= +DOCWELL_SMTP_TLS=false +DOCWELL_MAIL_FROM=no-reply@example.com + +# --- Port -------------------------------------------------------------------- +# The single published port. Behind a reverse proxy on this host, bind it to +# 127.0.0.1. +WEB_BIND=0.0.0.0 +WEB_PORT=3000 + +# --- Storage ----------------------------------------------------------------- +# Docker-managed named volumes by default; set absolute host paths for bind +# mounts, e.g. PB_DATA=/srv/docwell/pb_data. +# PB_DATA: database, uploaded files, PocketBase backups. Back this up. +PB_DATA=pb_data +# SERVER_DATA: the search index, rebuilt from the database when missing. +SERVER_DATA=server_data diff --git a/Docker-AIO/.env.prod.seaweedfs.example b/Docker-AIO/.env.prod.seaweedfs.example index 0b8ded5..e15c594 100644 --- a/Docker-AIO/.env.prod.seaweedfs.example +++ b/Docker-AIO/.env.prod.seaweedfs.example @@ -1,15 +1,17 @@ # Docwell all-in-one: production config (Docker-AIO/docker-compose.prod.seaweedfs.yml). # Copy to .env and fill in, then: -# docker compose -f docker-compose.prod.seaweedfs.yml pull +# docker compose -f docker-compose.prod.seaweedfs.yml pull (or build, with this checkout) # docker compose -f docker-compose.prod.seaweedfs.yml up -d # --- Image ------------------------------------------------------------------- -# For images released on a Gitea server, DOCWELL_REGISTRY=/. -# Pin a version in production. +# The docwell-seaweedfs image: the all-in-one with SeaweedFS built in. For images +# released on a Gitea server, DOCWELL_REGISTRY=/. Pin a +# version in production. DOCWELL_REGISTRY=ghcr.io/docwell DOCWELL_VERSION=latest -# Or name the image outright (a mirror, a hotfix tag): -# AIO_IMAGE=ghcr.io/docwell/docwell:1.0.0 +# Or name the image outright (a mirror, a hotfix tag, where `build` + `push` +# should put it): +# AIO_IMAGE=ghcr.io/docwell/docwell-seaweedfs:1.0.0 # --- PocketBase superuser ---------------------------------------------------- # Created or updated on every boot; the bundled server signs in with it. @@ -77,11 +79,12 @@ PB_DATA=pb_data SERVER_DATA=server_data # --- File storage: SeaweedFS ------------------------------------------------- -# Uploaded files go to a SeaweedFS bucket in this stack instead of PB_DATA; the -# database and PocketBase's backups stay where they are. +# Uploaded files go to a SeaweedFS bucket inside the container instead of +# PB_DATA; the database and PocketBase's backups stay where they are. # # One key pair, used by both sides: SeaweedFS accepts it and PocketBase signs -# in with it. Generate long random values, e.g. `openssl rand -hex 20`. +# in with it. REQUIRED: the container refuses to start without it. Generate +# long random values, e.g. `openssl rand -hex 20`. DOCWELL_S3_ACCESS_KEY= DOCWELL_S3_SECRET= DOCWELL_S3_BUCKET=docwell @@ -90,7 +93,9 @@ DOCWELL_S3_REGION=us-east-1 # SEAWEED_DATA: where SeaweedFS keeps the files. Named volume by default, or an # absolute host path. Back it up together with PB_DATA. SEAWEED_DATA=seaweed_data -# SEAWEED_IMAGE=chrislusf/seaweedfs:4.45 +# SeaweedFS version built into the image when you `build`; left commented out, +# the Dockerfile's pin holds. A new one means a rebuild. +# SEAWEED_VERSION=4.45 # Existing uploads are NOT copied when this is switched on. See README.md, # "Switching an existing install to S3". diff --git a/Docker-AIO/.env.prod.seaweedfs.split.example b/Docker-AIO/.env.prod.seaweedfs.split.example index e40352c..81e5bc9 100644 --- a/Docker-AIO/.env.prod.seaweedfs.split.example +++ b/Docker-AIO/.env.prod.seaweedfs.split.example @@ -1,15 +1,17 @@ # Docwell all-in-one: production config (Docker-AIO/docker-compose.prod.seaweedfs.split.yml). # Copy to .env and fill in, then: -# docker compose -f docker-compose.prod.seaweedfs.split.yml pull +# docker compose -f docker-compose.prod.seaweedfs.split.yml pull (or build, with this checkout) # docker compose -f docker-compose.prod.seaweedfs.split.yml up -d # --- Image ------------------------------------------------------------------- -# For images released on a Gitea server, DOCWELL_REGISTRY=/. -# Pin a version in production. +# The docwell-seaweedfs-split image: the all-in-one with SeaweedFS built in. For images +# released on a Gitea server, DOCWELL_REGISTRY=/. Pin a +# version in production. DOCWELL_REGISTRY=ghcr.io/docwell DOCWELL_VERSION=latest -# Or name the image outright (a mirror, a hotfix tag): -# AIO_IMAGE=ghcr.io/docwell/docwell:1.0.0 +# Or name the image outright (a mirror, a hotfix tag, where `build` + `push` +# should put it): +# AIO_IMAGE=ghcr.io/docwell/docwell-seaweedfs-split:1.0.0 # --- PocketBase superuser ---------------------------------------------------- # Created or updated on every boot; the bundled server signs in with it. @@ -77,11 +79,12 @@ PB_DATA=pb_data SERVER_DATA=server_data # --- File storage: SeaweedFS ------------------------------------------------- -# Uploaded files go to a SeaweedFS bucket in this stack instead of PB_DATA; the -# database and PocketBase's backups stay where they are. +# Uploaded files go to a SeaweedFS bucket inside the container instead of +# PB_DATA; the database and PocketBase's backups stay where they are. # # One key pair, used by both sides: SeaweedFS accepts it and PocketBase signs -# in with it. Generate long random values, e.g. `openssl rand -hex 20`. +# in with it. REQUIRED: the container refuses to start without it. Generate +# long random values, e.g. `openssl rand -hex 20`. DOCWELL_S3_ACCESS_KEY= DOCWELL_S3_SECRET= DOCWELL_S3_BUCKET=docwell @@ -90,7 +93,9 @@ DOCWELL_S3_REGION=us-east-1 # SEAWEED_DATA: where SeaweedFS keeps the files. Named volume by default, or an # absolute host path. Back it up together with PB_DATA. SEAWEED_DATA=seaweed_data -# SEAWEED_IMAGE=chrislusf/seaweedfs:4.45 +# SeaweedFS version built into the image when you `build`; left commented out, +# the Dockerfile's pin holds. A new one means a rebuild. +# SEAWEED_VERSION=4.45 # Existing uploads are NOT copied when this is switched on. See README.md, # "Switching an existing install to S3". @@ -106,4 +111,5 @@ SEAWEED_ADMIN_READONLY_PASSWORD= # Loopback by default; open http://localhost:23646 on the host or tunnel to it. SEAWEED_ADMIN_BIND=127.0.0.1 SEAWEED_ADMIN_PORT=23646 +# The admin UI's session key and maintenance settings. SEAWEED_ADMIN_DATA=seaweed_admin diff --git a/Docker-AIO/.env.s3.example b/Docker-AIO/.env.s3.example new file mode 100644 index 0000000..91dcf10 --- /dev/null +++ b/Docker-AIO/.env.s3.example @@ -0,0 +1,96 @@ +# Docwell all-in-one, built from this checkout (Docker-AIO/docker-compose.s3.yml). +# Copy to .env and fill in, then: +# docker compose -f docker-compose.s3.yml up -d --build + +# --- Image ------------------------------------------------------------------- +# `up -d --build` builds this checkout and tags it with this name; without +# --build the released image is pulled. For images released on a Gitea server, +# DOCWELL_REGISTRY=/. +DOCWELL_REGISTRY=ghcr.io/docwell +DOCWELL_VERSION=latest + +# --- PocketBase superuser ---------------------------------------------------- +# Created or updated on every boot; the bundled server signs in with it. +# REQUIRED. +PB_ADMIN_EMAIL=admin@example.com +PB_ADMIN_PASSWORD=change-me-long-password + +# Encrypts PocketBase's stored settings (SMTP password, S3 secret). Exactly 32 +# characters, e.g. `openssl rand -hex 16`. Blank = off. Set it before the first +# boot and keep a copy: the settings cannot be read without it. +PB_ENCRYPTION_KEY= + +# --- Public address ---------------------------------------------------------- +# Where browsers reach Docwell. Behind a reverse proxy, the https:// name. +DOCWELL_WEB_URL=http://localhost:3000 + +# Name shown in emails and the browser tab. Blank = Docwell. +DOCWELL_APP_NAME= + +# The Draw.io editor to embed. Blank = https://embed.diagrams.net; point it at +# a self-hosted jgraph/drawio to keep drawings on your network. +DOCWELL_DRAWIO_URL= + +# --- Accounts ---------------------------------------------------------------- +# Sign-up defaults until a superadmin changes them in the admin panel. The +# first account can always sign up and becomes the instance admin. +DOCWELL_SIGNUP_ENABLED=true +# Comma-separated email domains allowed to sign up (blank = any). +DOCWELL_SIGNUP_DOMAINS= + +# Optional: the first account, created as superadmin on start while the +# instance has no accounts. Later starts leave it alone (change it in the +# admin panel). Password: 8 characters or more. Blank = first sign-up wins. +DOCWELL_ADMIN_EMAIL= +DOCWELL_ADMIN_PASSWORD= +DOCWELL_ADMIN_NAME= + +# Largest attachment in MB (1-100). +DOCWELL_MAX_UPLOAD_MB=50 +# Days to keep audit log entries. Blank = 365, 0 = forever. +DOCWELL_AUDIT_RETENTION_DAYS= + +# --- Email ------------------------------------------------------------------- +# Verification, password reset and sign-in codes, sent by PocketBase. Blank +# host = email off (and the admin panel's Mail screen stays in charge). +DOCWELL_SMTP_HOST= +DOCWELL_SMTP_PORT=587 +DOCWELL_SMTP_USERNAME= +DOCWELL_SMTP_PASSWORD= +DOCWELL_SMTP_TLS=false +DOCWELL_MAIL_FROM=no-reply@example.com + +# --- Port -------------------------------------------------------------------- +# The single published port. Behind a reverse proxy on this host, bind it to +# 127.0.0.1. +WEB_BIND=0.0.0.0 +WEB_PORT=3000 + +# --- Storage ----------------------------------------------------------------- +# Docker-managed named volumes by default; set absolute host paths for bind +# mounts, e.g. PB_DATA=/srv/docwell/pb_data. +# PB_DATA: database, uploaded files, PocketBase backups. Back this up. +PB_DATA=pb_data +# SERVER_DATA: the search index, rebuilt from the database when missing. +SERVER_DATA=server_data + +# --- File storage: external S3 ----------------------------------------------- +# Uploaded files go to this bucket instead of PB_DATA; the database and +# PocketBase's backups stay where they are. These are applied on every boot and +# win over the admin panel's Storage screen. +# +# Nothing in this stack runs a gateway: the endpoint and the bucket must +# already exist. For a gateway on this Docker host use +# http://host.docker.internal:8333 (the compose file maps that name). +DOCWELL_S3_ENDPOINT=https://s3.eu-central-1.amazonaws.com +DOCWELL_S3_BUCKET=docwell +DOCWELL_S3_ACCESS_KEY= +DOCWELL_S3_SECRET= +# SeaweedFS and MinIO ignore the region; PocketBase needs one anyway. +DOCWELL_S3_REGION=us-east-1 +# true for SeaweedFS and MinIO, false for AWS S3 proper. +DOCWELL_S3_FORCE_PATH_STYLE=true + +# Existing uploads are NOT copied when this is switched on: attachments made +# before the switch stop resolving until you copy pb_data/storage into the +# bucket. See README.md, "Switching an existing install to S3". diff --git a/Docker-AIO/.env.seaweedfs.example b/Docker-AIO/.env.seaweedfs.example new file mode 100644 index 0000000..a6ebd27 --- /dev/null +++ b/Docker-AIO/.env.seaweedfs.example @@ -0,0 +1,94 @@ +# Docwell all-in-one, built from this checkout (Docker-AIO/docker-compose.seaweedfs.yml). +# Copy to .env and fill in, then: +# docker compose -f docker-compose.seaweedfs.yml up -d --build + +# --- Image ------------------------------------------------------------------- +# `up -d --build` builds this checkout and tags it with this name; without +# --build the released image is pulled. For images released on a Gitea server, +# DOCWELL_REGISTRY=/. +DOCWELL_REGISTRY=ghcr.io/docwell +DOCWELL_VERSION=latest + +# --- PocketBase superuser ---------------------------------------------------- +# Created or updated on every boot; the bundled server signs in with it. +# REQUIRED. +PB_ADMIN_EMAIL=admin@example.com +PB_ADMIN_PASSWORD=change-me-long-password + +# Encrypts PocketBase's stored settings (SMTP password, S3 secret). Exactly 32 +# characters, e.g. `openssl rand -hex 16`. Blank = off. Set it before the first +# boot and keep a copy: the settings cannot be read without it. +PB_ENCRYPTION_KEY= + +# --- Public address ---------------------------------------------------------- +# Where browsers reach Docwell. Behind a reverse proxy, the https:// name. +DOCWELL_WEB_URL=http://localhost:3000 + +# Name shown in emails and the browser tab. Blank = Docwell. +DOCWELL_APP_NAME= + +# The Draw.io editor to embed. Blank = https://embed.diagrams.net; point it at +# a self-hosted jgraph/drawio to keep drawings on your network. +DOCWELL_DRAWIO_URL= + +# --- Accounts ---------------------------------------------------------------- +# Sign-up defaults until a superadmin changes them in the admin panel. The +# first account can always sign up and becomes the instance admin. +DOCWELL_SIGNUP_ENABLED=true +# Comma-separated email domains allowed to sign up (blank = any). +DOCWELL_SIGNUP_DOMAINS= + +# Optional: the first account, created as superadmin on start while the +# instance has no accounts. Later starts leave it alone (change it in the +# admin panel). Password: 8 characters or more. Blank = first sign-up wins. +DOCWELL_ADMIN_EMAIL= +DOCWELL_ADMIN_PASSWORD= +DOCWELL_ADMIN_NAME= + +# Largest attachment in MB (1-100). +DOCWELL_MAX_UPLOAD_MB=50 +# Days to keep audit log entries. Blank = 365, 0 = forever. +DOCWELL_AUDIT_RETENTION_DAYS= + +# --- Email ------------------------------------------------------------------- +# Verification, password reset and sign-in codes, sent by PocketBase. Blank +# host = email off (and the admin panel's Mail screen stays in charge). +DOCWELL_SMTP_HOST= +DOCWELL_SMTP_PORT=587 +DOCWELL_SMTP_USERNAME= +DOCWELL_SMTP_PASSWORD= +DOCWELL_SMTP_TLS=false +DOCWELL_MAIL_FROM=no-reply@example.com + +# --- Port -------------------------------------------------------------------- +# The single published port. Behind a reverse proxy on this host, bind it to +# 127.0.0.1. +WEB_BIND=0.0.0.0 +WEB_PORT=3000 + +# --- Storage ----------------------------------------------------------------- +# Docker-managed named volumes by default; set absolute host paths for bind +# mounts, e.g. PB_DATA=/srv/docwell/pb_data. +# PB_DATA: database, uploaded files, PocketBase backups. Back this up. +PB_DATA=pb_data +# SERVER_DATA: the search index, rebuilt from the database when missing. +SERVER_DATA=server_data + +# --- File storage: SeaweedFS ------------------------------------------------- +# Uploaded files go to a SeaweedFS bucket in this stack instead of PB_DATA; the +# database and PocketBase's backups stay where they are. +# +# One key pair, used by both sides: SeaweedFS accepts it and PocketBase signs +# in with it. Generate long random values, e.g. `openssl rand -hex 20`. +DOCWELL_S3_ACCESS_KEY= +DOCWELL_S3_SECRET= +DOCWELL_S3_BUCKET=docwell +DOCWELL_S3_REGION=us-east-1 + +# SEAWEED_DATA: where SeaweedFS keeps the files. Named volume by default, or an +# absolute host path. Back it up together with PB_DATA. +SEAWEED_DATA=seaweed_data +# SEAWEED_IMAGE=chrislusf/seaweedfs:4.45 + +# Existing uploads are NOT copied when this is switched on. See README.md, +# "Switching an existing install to S3". diff --git a/Docker-AIO/.env.seaweedfs.split.example b/Docker-AIO/.env.seaweedfs.split.example new file mode 100644 index 0000000..56c4066 --- /dev/null +++ b/Docker-AIO/.env.seaweedfs.split.example @@ -0,0 +1,107 @@ +# Docwell all-in-one, built from this checkout (Docker-AIO/docker-compose.seaweedfs.split.yml). +# Copy to .env and fill in, then: +# docker compose -f docker-compose.seaweedfs.split.yml up -d --build + +# --- Image ------------------------------------------------------------------- +# `up -d --build` builds this checkout and tags it with this name; without +# --build the released image is pulled. For images released on a Gitea server, +# DOCWELL_REGISTRY=/. +DOCWELL_REGISTRY=ghcr.io/docwell +DOCWELL_VERSION=latest + +# --- PocketBase superuser ---------------------------------------------------- +# Created or updated on every boot; the bundled server signs in with it. +# REQUIRED. +PB_ADMIN_EMAIL=admin@example.com +PB_ADMIN_PASSWORD=change-me-long-password + +# Encrypts PocketBase's stored settings (SMTP password, S3 secret). Exactly 32 +# characters, e.g. `openssl rand -hex 16`. Blank = off. Set it before the first +# boot and keep a copy: the settings cannot be read without it. +PB_ENCRYPTION_KEY= + +# --- Public address ---------------------------------------------------------- +# Where browsers reach Docwell. Behind a reverse proxy, the https:// name. +DOCWELL_WEB_URL=http://localhost:3000 + +# Name shown in emails and the browser tab. Blank = Docwell. +DOCWELL_APP_NAME= + +# The Draw.io editor to embed. Blank = https://embed.diagrams.net; point it at +# a self-hosted jgraph/drawio to keep drawings on your network. +DOCWELL_DRAWIO_URL= + +# --- Accounts ---------------------------------------------------------------- +# Sign-up defaults until a superadmin changes them in the admin panel. The +# first account can always sign up and becomes the instance admin. +DOCWELL_SIGNUP_ENABLED=true +# Comma-separated email domains allowed to sign up (blank = any). +DOCWELL_SIGNUP_DOMAINS= + +# Optional: the first account, created as superadmin on start while the +# instance has no accounts. Later starts leave it alone (change it in the +# admin panel). Password: 8 characters or more. Blank = first sign-up wins. +DOCWELL_ADMIN_EMAIL= +DOCWELL_ADMIN_PASSWORD= +DOCWELL_ADMIN_NAME= + +# Largest attachment in MB (1-100). +DOCWELL_MAX_UPLOAD_MB=50 +# Days to keep audit log entries. Blank = 365, 0 = forever. +DOCWELL_AUDIT_RETENTION_DAYS= + +# --- Email ------------------------------------------------------------------- +# Verification, password reset and sign-in codes, sent by PocketBase. Blank +# host = email off (and the admin panel's Mail screen stays in charge). +DOCWELL_SMTP_HOST= +DOCWELL_SMTP_PORT=587 +DOCWELL_SMTP_USERNAME= +DOCWELL_SMTP_PASSWORD= +DOCWELL_SMTP_TLS=false +DOCWELL_MAIL_FROM=no-reply@example.com + +# --- Port -------------------------------------------------------------------- +# The single published port. Behind a reverse proxy on this host, bind it to +# 127.0.0.1. +WEB_BIND=0.0.0.0 +WEB_PORT=3000 + +# --- Storage ----------------------------------------------------------------- +# Docker-managed named volumes by default; set absolute host paths for bind +# mounts, e.g. PB_DATA=/srv/docwell/pb_data. +# PB_DATA: database, uploaded files, PocketBase backups. Back this up. +PB_DATA=pb_data +# SERVER_DATA: the search index, rebuilt from the database when missing. +SERVER_DATA=server_data + +# --- File storage: SeaweedFS ------------------------------------------------- +# Uploaded files go to a SeaweedFS bucket in this stack instead of PB_DATA; the +# database and PocketBase's backups stay where they are. +# +# One key pair, used by both sides: SeaweedFS accepts it and PocketBase signs +# in with it. Generate long random values, e.g. `openssl rand -hex 20`. +DOCWELL_S3_ACCESS_KEY= +DOCWELL_S3_SECRET= +DOCWELL_S3_BUCKET=docwell +DOCWELL_S3_REGION=us-east-1 + +# SEAWEED_DATA: where SeaweedFS keeps the files. Named volume by default, or an +# absolute host path. Back it up together with PB_DATA. +SEAWEED_DATA=seaweed_data +# SEAWEED_IMAGE=chrislusf/seaweedfs:4.45 + +# Existing uploads are NOT copied when this is switched on. See README.md, +# "Switching an existing install to S3". + +# --- SeaweedFS admin UI ------------------------------------------------------ +# Cluster view and Object Store -> Users (mint and revoke S3 keys). REQUIRED: +# the panel can hand out keys to the bucket, so it never runs without a login. +SEAWEED_ADMIN_USER=admin +SEAWEED_ADMIN_PASSWORD= +# Optional view-only login. +SEAWEED_ADMIN_READONLY_USER= +SEAWEED_ADMIN_READONLY_PASSWORD= +# Loopback by default; open http://localhost:23646 on the host or tunnel to it. +SEAWEED_ADMIN_BIND=127.0.0.1 +SEAWEED_ADMIN_PORT=23646 +SEAWEED_ADMIN_DATA=seaweed_admin diff --git a/Docker-AIO/Dockerfile.seaweedfs b/Docker-AIO/Dockerfile.seaweedfs new file mode 100644 index 0000000..8b43756 --- /dev/null +++ b/Docker-AIO/Dockerfile.seaweedfs @@ -0,0 +1,112 @@ +# Docwell all-in-one WITH the object store inside: PocketBase + docwell-server +# + docwell-web, plus SeaweedFS as one `weed server -s3` process (master, +# volume, filer and S3 gateway as goroutines) in the same container. +# +# This is Dockerfile with the two SeaweedFS containers of +# docker-compose.seaweedfs.yml folded in. Those keep SeaweedFS outside the +# image so it can be upgraded with a tag change; this file trades that for one +# image and one container. What it costs: a new SeaweedFS is a rebuild +# (--build-arg SEAWEED_VERSION). For the admin UI and per-role metrics, see +# Dockerfile.seaweedfs.split. +# +# Build from the repository root: +# docker build -f Docker-AIO/Dockerfile.seaweedfs -t docwell-aio-seaweedfs . +# +# Run it: +# docker run -d -p 3000:3000 \ +# -e PB_ADMIN_EMAIL=admin@example.com -e PB_ADMIN_PASSWORD=change-me \ +# -e DOCWELL_S3_ACCESS_KEY=... -e DOCWELL_S3_SECRET=... \ +# -v docwell_pb:/pb_data -v docwell_seaweed:/seaweed/data docwell-aio-seaweedfs +# +# Ports inside the container (only 3000 is meant to be published; SeaweedFS +# listens on loopback): +# 3000 docwell-web (app, /api, /collab, /admin) +# 8070 PocketBase (loopback) +# 8080 docwell-server (loopback) <- why the volume server is on 8081 +# 8081 SeaweedFS volume (loopback; serves files by id, no auth) +# 8333 SeaweedFS S3 gateway (loopback; PocketBase's endpoint) +# 8888 SeaweedFS filer (loopback) +# 9333 SeaweedFS master (loopback) +# Multi-arch: build stages run on the build machine's platform and Go +# cross-compiles, so arm64 images build without emulation. + +# SeaweedFS to bake in, pinned so a rebuild later brings up the same one; the +# same tag the compose files run as SEAWEED_IMAGE. Declared before the first +# FROM because a FROM can only use a global ARG. +ARG SEAWEED_VERSION=4.45 + +FROM --platform=$BUILDPLATFORM node:24-alpine AS ui +WORKDIR /src +COPY package.json package-lock.json tsconfig.base.json ./ +COPY Packages/ Packages/ +COPY Server/admin/ Server/admin/ +COPY Web-App/frontend/ Web-App/frontend/ +COPY Desktop-App/frontend/package.json Desktop-App/frontend/ +RUN npm ci --no-audit --no-fund +RUN mkdir -p Server/internal/admin/dist Web-App/internal/spa/dist \ + && npm run build -w @docwell/admin \ + && npm run build -w @docwell/web-app + +# yrs (Rust Yjs) compiled to WebAssembly; the server embeds it (ADR-3). +FROM --platform=$BUILDPLATFORM rust:1-alpine AS yrs +RUN rustup target add wasm32-wasip1 +WORKDIR /src +COPY Server/ycrdt-wasm/ ./ +RUN cargo build --locked --release --target wasm32-wasip1 + +FROM --platform=$BUILDPLATFORM golang:1.26-alpine AS build +ARG TARGETOS TARGETARCH +WORKDIR /src +COPY Server/ Server/ +COPY Web-App/ Web-App/ +COPY --from=ui /src/Server/internal/admin/dist Server/internal/admin/dist +COPY --from=yrs /src/target/wasm32-wasip1/release/docwell_yrs.wasm Server/internal/ycrdt/docwell_yrs.wasm +COPY --from=ui /src/Web-App/internal/spa/dist Web-App/internal/spa/dist +ARG VERSION=dev +ENV CGO_ENABLED=0 GOWORK=off GOOS=$TARGETOS GOARCH=$TARGETARCH +RUN cd Server && go build -trimpath -ldflags "-s -w -X main.Version=${VERSION}" -o /out/docwell-server ./cmd/docwell-server +RUN cd Web-App && go build -trimpath -ldflags "-s -w -X main.Version=${VERSION}" -o /out/docwell-web ./cmd/docwell-web + +# The one static weed binary from the official image, for the target platform. +FROM chrislusf/seaweedfs:${SEAWEED_VERSION} AS seaweed + +FROM alpine:3.22 +ARG PB_VERSION=0.40.6 +ARG TARGETARCH +# ffmpeg cuts long recordings for transcription (ADR-15). +RUN apk add --no-cache ca-certificates unzip wget ffmpeg \ + && wget -q "https://github.com/pocketbase/pocketbase/releases/download/v${PB_VERSION}/pocketbase_${PB_VERSION}_linux_${TARGETARCH:-amd64}.zip" -O /tmp/pb.zip \ + && unzip /tmp/pb.zip pocketbase -d /usr/local/bin && rm /tmp/pb.zip && apk del unzip +COPY --from=build /out/ /usr/local/bin/ +COPY --from=seaweed /usr/bin/weed /usr/local/bin/weed +# No migrations or hooks: docwell-server applies Docwell's schema and the +# DOCWELL_* settings to PocketBase when it starts. start-seaweedfs.sh starts SeaweedFS, +# then execs start.sh, which runs the rest and watches every process. +COPY Docker-AIO/start.sh /start.sh +COPY Docker-AIO/start-seaweedfs.sh /start-seaweedfs.sh +RUN chmod +x /start.sh /start-seaweedfs.sh && mkdir -p /data /seaweed/data + +# /data holds the search index, which is rebuilt from PocketBase when missing. +# +# File storage is on by construction: the gateway is in this image at a fixed +# loopback address, path style because a self-hosted gateway has no per-bucket +# DNS. docwell-server writes these into PocketBase on every start. Only uploaded +# files move to the bucket; the database and PocketBase's backups stay in +# /pb_data. Required at runtime: PB_ADMIN_EMAIL, PB_ADMIN_PASSWORD, +# DOCWELL_S3_ACCESS_KEY and DOCWELL_S3_SECRET. +ENV DOCWELL_DATA_DIR=/data \ + DOCWELL_S3_ENABLED=true \ + DOCWELL_S3_ENDPOINT=http://127.0.0.1:8333 \ + DOCWELL_S3_BUCKET=docwell \ + DOCWELL_S3_REGION=us-east-1 \ + DOCWELL_S3_FORCE_PATH_STYLE=true +# /seaweed/data is the `weed server -dir` layout, shared by master, volume and +# filer, so a volume moves between Dockerfile.seaweedfs, Dockerfile.seaweedfs.split +# and the compose files' SeaweedFS containers unchanged. +VOLUME /pb_data /data /seaweed/data +EXPOSE 3000 +HEALTHCHECK --interval=10s --timeout=5s --start-period=60s --retries=5 \ + CMD wget -qO- http://127.0.0.1:9333/cluster/status >/dev/null \ + && wget -qO- http://127.0.0.1:8333/healthz >/dev/null \ + && wget -qO- http://127.0.0.1:3000/api/v1/version >/dev/null || exit 1 +ENTRYPOINT ["/start-seaweedfs.sh"] diff --git a/Docker-AIO/Dockerfile.seaweedfs.split b/Docker-AIO/Dockerfile.seaweedfs.split new file mode 100644 index 0000000..9d31c99 --- /dev/null +++ b/Docker-AIO/Dockerfile.seaweedfs.split @@ -0,0 +1,120 @@ +# Docwell all-in-one WITH the object store inside: PocketBase + docwell-server +# + docwell-web, plus SeaweedFS split into its roles (master, volume, filer, S3 +# gateway and the admin UI), each its own process in the same container. +# +# This is Dockerfile with the six SeaweedFS containers of +# docker-compose.seaweedfs.split.yml folded in. Those keep SeaweedFS outside the +# image so it can be upgraded with a tag change; this file trades that for one +# image and one container. What the split still buys in here: per-role metrics +# ports and the admin UI, where S3 identities are minted and revoked. What it +# costs: a new SeaweedFS is a rebuild (--build-arg SEAWEED_VERSION). +# +# Build from the repository root: +# docker build -f Docker-AIO/Dockerfile.seaweedfs.split -t docwell-aio-seaweedfs-split . +# +# Run it: +# docker run -d -p 3000:3000 -p 127.0.0.1:23646:23646 \ +# -e PB_ADMIN_EMAIL=admin@example.com -e PB_ADMIN_PASSWORD=change-me \ +# -e DOCWELL_S3_ACCESS_KEY=... -e DOCWELL_S3_SECRET=... \ +# -e WEED_ADMIN_PASSWORD=change-me \ +# -v docwell_pb:/pb_data -v docwell_seaweed:/seaweed/data \ +# -v docwell_seaweed_admin:/seaweed/admin docwell-aio-seaweedfs-split +# +# Ports inside the container (only 3000 and 23646 are meant to be published; +# every SeaweedFS role but the admin UI listens on loopback): +# 3000 docwell-web (app, /api, /collab, /admin) +# 8070 PocketBase (loopback) +# 8080 docwell-server (loopback) <- why the volume server is on 8081 +# 8081 SeaweedFS volume (loopback; serves files by id, no auth) +# 8333 SeaweedFS S3 gateway (loopback; PocketBase's endpoint) +# 8888 SeaweedFS filer (loopback) +# 9333 SeaweedFS master (loopback) +# 23646 SeaweedFS admin UI +# Multi-arch: build stages run on the build machine's platform and Go +# cross-compiles, so arm64 images build without emulation. + +# SeaweedFS to bake in, pinned so a rebuild later brings up the same one; the +# same tag the compose files run as SEAWEED_IMAGE. Declared before the first +# FROM because a FROM can only use a global ARG. +ARG SEAWEED_VERSION=4.45 + +FROM --platform=$BUILDPLATFORM node:24-alpine AS ui +WORKDIR /src +COPY package.json package-lock.json tsconfig.base.json ./ +COPY Packages/ Packages/ +COPY Server/admin/ Server/admin/ +COPY Web-App/frontend/ Web-App/frontend/ +COPY Desktop-App/frontend/package.json Desktop-App/frontend/ +RUN npm ci --no-audit --no-fund +RUN mkdir -p Server/internal/admin/dist Web-App/internal/spa/dist \ + && npm run build -w @docwell/admin \ + && npm run build -w @docwell/web-app + +# yrs (Rust Yjs) compiled to WebAssembly; the server embeds it (ADR-3). +FROM --platform=$BUILDPLATFORM rust:1-alpine AS yrs +RUN rustup target add wasm32-wasip1 +WORKDIR /src +COPY Server/ycrdt-wasm/ ./ +RUN cargo build --locked --release --target wasm32-wasip1 + +FROM --platform=$BUILDPLATFORM golang:1.26-alpine AS build +ARG TARGETOS TARGETARCH +WORKDIR /src +COPY Server/ Server/ +COPY Web-App/ Web-App/ +COPY --from=ui /src/Server/internal/admin/dist Server/internal/admin/dist +COPY --from=yrs /src/target/wasm32-wasip1/release/docwell_yrs.wasm Server/internal/ycrdt/docwell_yrs.wasm +COPY --from=ui /src/Web-App/internal/spa/dist Web-App/internal/spa/dist +ARG VERSION=dev +ENV CGO_ENABLED=0 GOWORK=off GOOS=$TARGETOS GOARCH=$TARGETARCH +RUN cd Server && go build -trimpath -ldflags "-s -w -X main.Version=${VERSION}" -o /out/docwell-server ./cmd/docwell-server +RUN cd Web-App && go build -trimpath -ldflags "-s -w -X main.Version=${VERSION}" -o /out/docwell-web ./cmd/docwell-web + +# The one static weed binary from the official image, for the target platform. +FROM chrislusf/seaweedfs:${SEAWEED_VERSION} AS seaweed + +FROM alpine:3.22 +ARG PB_VERSION=0.40.6 +ARG TARGETARCH +# ffmpeg cuts long recordings for transcription (ADR-15). +RUN apk add --no-cache ca-certificates unzip wget ffmpeg \ + && wget -q "https://github.com/pocketbase/pocketbase/releases/download/v${PB_VERSION}/pocketbase_${PB_VERSION}_linux_${TARGETARCH:-amd64}.zip" -O /tmp/pb.zip \ + && unzip /tmp/pb.zip pocketbase -d /usr/local/bin && rm /tmp/pb.zip && apk del unzip +COPY --from=build /out/ /usr/local/bin/ +COPY --from=seaweed /usr/bin/weed /usr/local/bin/weed +# No migrations or hooks: docwell-server applies Docwell's schema and the +# DOCWELL_* settings to PocketBase when it starts. start-seaweedfs-split.sh starts SeaweedFS, +# then execs start.sh, which runs the rest and watches every process. +COPY Docker-AIO/start.sh /start.sh +COPY Docker-AIO/start-seaweedfs-split.sh /start-seaweedfs-split.sh +RUN chmod +x /start.sh /start-seaweedfs-split.sh && mkdir -p /data /seaweed/data /seaweed/admin + +# /data holds the search index, which is rebuilt from PocketBase when missing. +# +# File storage is on by construction: the gateway is in this image at a fixed +# loopback address, path style because a self-hosted gateway has no per-bucket +# DNS. docwell-server writes these into PocketBase on every start. Only uploaded +# files move to the bucket; the database and PocketBase's backups stay in +# /pb_data. Required at runtime: PB_ADMIN_EMAIL, PB_ADMIN_PASSWORD, +# DOCWELL_S3_ACCESS_KEY, DOCWELL_S3_SECRET and WEED_ADMIN_PASSWORD. +ENV DOCWELL_DATA_DIR=/data \ + DOCWELL_S3_ENABLED=true \ + DOCWELL_S3_ENDPOINT=http://127.0.0.1:8333 \ + DOCWELL_S3_BUCKET=docwell \ + DOCWELL_S3_REGION=us-east-1 \ + DOCWELL_S3_FORCE_PATH_STYLE=true \ + WEED_ADMIN_USER=admin +# /seaweed/data is the `weed server -dir` layout, shared by master, volume and +# filer, so a volume moves between Dockerfile.seaweedfs, Dockerfile.seaweedfs.split +# and the compose files' SeaweedFS containers unchanged. +# /seaweed/admin: the admin UI's session key and maintenance settings. +VOLUME /pb_data /data /seaweed/data /seaweed/admin +EXPOSE 3000 23646 +HEALTHCHECK --interval=10s --timeout=5s --start-period=60s --retries=5 \ + CMD wget -qO- http://127.0.0.1:9333/cluster/status >/dev/null \ + && wget -qO- http://127.0.0.1:8081/healthz >/dev/null \ + && wget -qO- http://127.0.0.1:8888/healthz >/dev/null \ + && wget -qO- http://127.0.0.1:8333/healthz >/dev/null \ + && wget -qO- http://127.0.0.1:23646/health >/dev/null \ + && wget -qO- http://127.0.0.1:3000/api/v1/version >/dev/null || exit 1 +ENTRYPOINT ["/start-seaweedfs-split.sh"] diff --git a/Docker-AIO/README.md b/Docker-AIO/README.md index cc89daa..b21354a 100644 --- a/Docker-AIO/README.md +++ b/Docker-AIO/README.md @@ -3,13 +3,16 @@ PocketBase, docwell-server and docwell-web in one container, behind one port. For small self-hosted installs; for separate, individually scalable services see [`../Docker`](../Docker/README.md). -| Compose file | Env template | Uploaded files live in | Use it for | +Each shape of storage has one self-contained compose file per way of getting the image, and an `.env` template of +the same name (`docker-compose.s3.yml` takes `.env.s3.example`, `docker-compose.prod.seaweedfs.yml` takes +`.env.prod.seaweedfs.example`, and so on): + +| Uploaded files live in | From source (`up -d --build`) | Production (`pull`) | Image | |---|---|---|---| -| `docker-compose.yml` | none (variables inline) | the `pb_data` volume | trying it out; `--build` builds this checkout | -| `docker-compose.prod.yml` | `.env.prod.example` | the `pb_data` volume | production, released image | -| `docker-compose.prod.s3.yml` | `.env.prod.s3.example` | an S3 bucket that already exists elsewhere | production with AWS S3, MinIO, an existing SeaweedFS... | -| `docker-compose.prod.seaweedfs.yml` | `.env.prod.seaweedfs.example` | SeaweedFS next to the container, one container | production, self-hosted object store | -| `docker-compose.prod.seaweedfs.split.yml` | `.env.prod.seaweedfs.split.example` | SeaweedFS next to the container, one container per role + admin UI | the same, with the SeaweedFS admin UI | +| the `pb_data` volume | `docker-compose.yml` | `docker-compose.prod.yml` | `Dockerfile` | +| an S3 bucket that already exists elsewhere (AWS S3, MinIO, another SeaweedFS...) | `docker-compose.s3.yml` | `docker-compose.prod.s3.yml` | `Dockerfile` | +| SeaweedFS, one `weed server -s3` process | `docker-compose.seaweedfs.yml`: in a container beside this one | `docker-compose.prod.seaweedfs.yml`: built into the image | `Dockerfile` / `Dockerfile.seaweedfs` | +| SeaweedFS, one process per role, plus its admin UI | `docker-compose.seaweedfs.split.yml`: in containers beside this one | `docker-compose.prod.seaweedfs.split.yml`: built into the image | `Dockerfile` / `Dockerfile.seaweedfs.split` | ```bash cp .env.prod.example .env # then edit: passwords, DOCWELL_WEB_URL @@ -17,11 +20,58 @@ docker compose -f docker-compose.prod.yml pull docker compose -f docker-compose.prod.yml up -d ``` +From source, from this directory: + +```bash +cp .env.example .env # then edit +docker compose up -d --build +``` + +`docker-compose.yml` also runs without a `.env`: `PB_ADMIN_PASSWORD=... docker compose up -d` pulls the released +image with every other setting at its default. + Open `DOCWELL_WEB_URL` (http://localhost:3000); the admin panel is at `/admin/`. **The first account that signs up becomes the instance admin.** -The SeaweedFS variants keep the Docwell image unchanged and run SeaweedFS in containers of their own beside it, so -adding or dropping the object store needs no rebuild. +## SeaweedFS: beside the container or inside it + +The from-source SeaweedFS files keep the Docwell image unchanged and run SeaweedFS in containers of their own beside +it, plus a one-shot `seaweedfs-init` that creates the bucket (PocketBase never creates one). Adding or dropping the +object store needs no rebuild, and a SeaweedFS upgrade is a change of `SEAWEED_IMAGE`. + +The production SeaweedFS files go the other way and **build it into the image**: one service, one container. + +- `Dockerfile.seaweedfs` (image `docwell-seaweedfs`) copies the `weed` binary from the official image, pinned by the + `SEAWEED_VERSION` build arg, and [`start-seaweedfs.sh`](start-seaweedfs.sh) runs `weed server -s3` and creates the + bucket before handing over to [`start.sh`](start.sh). Volumes: `PB_DATA`, `SERVER_DATA`, `SEAWEED_DATA`. +- `Dockerfile.seaweedfs.split` (image `docwell-seaweedfs-split`) runs master, volume, filer, S3 gateway and the admin + UI as separate processes from [`start-seaweedfs-split.sh`](start-seaweedfs-split.sh), which also seeds the bucket + and PocketBase's identity. Volumes: the three above plus `SEAWEED_ADMIN_DATA`. What survives of "split" in one + container is per-role metrics ports and the admin UI; what does not is restarting or spreading the roles one by + one. + +Inside, every SeaweedFS role listens on the container's loopback, the volume server on **8081** because 8080 is +docwell-server. Nothing of SeaweedFS is published except the split image's admin UI, on loopback by default. +`start.sh` watches the SeaweedFS processes with its own three, so the container exits and restarts as a whole if any +of them stops. The cost of baking it in: a new SeaweedFS means a new image. The release workflow publishes both +images next to `docwell`, so `pull` works as it does for `docker-compose.prod.yml`; on a host with this checkout, +`docker compose -f docker-compose.prod.seaweedfs.yml build` builds it instead, and `push` sends it to `AIO_IMAGE`. + +Switching between any of the SeaweedFS files needs no migration: master, volume and filer share one data mount +(`/data` in the side containers, `/seaweed/data` in the baked-in images) in exactly the layout `weed server -dir` +writes. + +### Identities in the split files + +SeaweedFS reads credentials from, in descending priority, an `-s3.config` file, the filer's IAM store, then +`AWS_ACCESS_KEY_ID` / `AWS_SECRET_ACCESS_KEY`, and a higher source *replaces* a lower one. The single-process files +use the environment variables, so nothing else may write identities there: the first user added in a panel would +displace PocketBase's key. The split files seed PocketBase's identity into the filer's store instead, the same store +the admin UI writes, and refuse to start the gateway if it is not there. Rotating `DOCWELL_S3_SECRET` in `.env` and +restarting updates that identity in place. + +Set `SEAWEED_ADMIN_PASSWORD`: `weed admin` serves the panel with no login when it is empty, and a panel that can mint +bucket credentials is the bucket. The split files and image refuse to start without it. ## How it differs from `Docker/` @@ -32,7 +82,8 @@ adding or dropping the object store needs no rebuild. - **PocketBase binary.** The image downloads the PocketBase release itself (`PB_VERSION` in the [`Dockerfile`](Dockerfile)) rather than using `tajniak81/pocketbase-docker-root`, because that image is amd64-only and the all-in-one image is published for amd64 and arm64. -- Data lives in `/pb_data` (database, uploads, backups) and `/data` (search index) in the container. +- Data lives in `/pb_data` (database, uploads, backups) and `/data` (search index) in the container, plus + `/seaweed/data` (and `/seaweed/admin`) in the SeaweedFS images. `PB_ENCRYPTION_KEY` (exactly 32 characters, `openssl rand -hex 16`) turns on PocketBase's settings encryption. Set it before the first start and keep a copy. diff --git a/Docker-AIO/docker-compose.prod.seaweedfs.split.yml b/Docker-AIO/docker-compose.prod.seaweedfs.split.yml index 0f95bbf..bd725e4 100644 --- a/Docker-AIO/docker-compose.prod.seaweedfs.split.yml +++ b/Docker-AIO/docker-compose.prod.seaweedfs.split.yml @@ -1,220 +1,59 @@ name: docwell-aio -# Production Docwell all-in-one, with SeaweedFS split into its roles. +# Production Docwell all-in-one with SeaweedFS split into its roles, all built +# into ONE image: Dockerfile.seaweedfs.split runs master, volume, filer, S3 +# gateway and the SeaweedFS admin UI as separate processes in the same +# container as PocketBase, docwell-server and docwell-web. One service, one +# container, four volumes. What the split still buys in here: the admin UI +# (Object Store -> Users mints and revokes S3 keys) and per-role metrics ports. +# For SeaweedFS in containers of its own (upgrade by tag, per-role restart), +# use docker-compose.seaweedfs.split.yml; the data volume is interchangeable. # -# One container runs PocketBase, docwell-server and docwell-web, from the -# prebuilt image pulled from the registry instead of built from this checkout. # Self-contained: one file, no overlays. Everything an operator needs to set # lives in .env. # -# 1. cp .env.prod.seaweedfs.split.example .env (then edit it: passwords, URL, port) +# 1. cp .env.prod.seaweedfs.split.example .env (then edit it: passwords, URL, S3 keys) # 2. docker compose -f docker-compose.prod.seaweedfs.split.yml pull +# (or `build`, on a host with this checkout) # 3. docker compose -f docker-compose.prod.seaweedfs.split.yml up -d # -# This is docker-compose.prod.seaweedfs.yml with SeaweedFS taken apart into its -# roles, each its own container: master, volume, filer, S3 gateway, plus the -# SeaweedFS admin UI. What that buys: +# `image:` and `build:` are both set, so the same file pulls the released +# docwell-seaweedfs-split image or builds it; a built one can be `push`ed to AIO_IMAGE and +# pulled elsewhere. What baking SeaweedFS in costs: a new SeaweedFS is a new +# image (SEAWEED_VERSION), not a tag change. # -# • the admin UI (weed admin): a cluster view, and Object Store -> Users, -# where S3 identities are created and revoked without touching a file; -# • per-role restart, upgrade and Prometheus metrics; -# • room for a second volume server later, on this host or another. -# -# What it costs: six SeaweedFS containers instead of one. If none of the above -# is wanted, use docker-compose.prod.seaweedfs.yml; the S3 behaviour is the -# same. Master, volume and filer share one /data mount, laid out exactly as -# `weed server -dir` lays it out, so the two files share SEAWEED_DATA with no -# migration either way. -# -# Only the admin UI publishes a port (loopback by default). The volume server -# serves file content by id with no authentication, so it is never published. +# PocketBase keeps uploaded files (attachments, images, avatars) in the bucket +# instead of on the pb_data volume; the database and PocketBase's own backups +# stay on PB_DATA. Clients cannot tell: files are always fetched through +# docwell-server, never from a bucket URL. # # Before switching a stack that already has uploads: PocketBase does NOT copy # existing files into the bucket. See README.md. # -# SeaweedFS runs in containers of its own next to the all-in-one container, -# which is the same image as in docker-compose.prod.yml: no rebuild to add or -# drop the object store, and a SeaweedFS upgrade is a tag change. -# # Traffic flow (browser): one port. docwell-web serves the app and proxies # /api, /collab and /admin to docwell-server inside the container; PocketBase -# listens on the container's loopback only. +# and every SeaweedFS role but the admin UI listen on the container's loopback. # -# On every boot the container creates or updates the PocketBase superuser -# from PB_ADMIN_* (a changed password is applied); docwell-server then brings +# On every boot the container creates the bucket and seeds the S3 identity, creates or +# updates the PocketBase superuser from PB_ADMIN_*, and docwell-server brings # the collections up to Docwell's schema and writes the env-driven settings -# (mail, app URL, file storage). All idempotent, so restarts -# and upgrades are safe. +# (mail, app URL, file storage). All idempotent, so restarts and upgrades are +# safe. services: - # --- SeaweedFS: master ----------------------------------------------------- - # Keeps the volume topology and hands out file ids. -ip is the name the other - # roles reach it by, so it is the service name, not the container IP. - seaweedfs-master: - image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" - container_name: docwell-aio-seaweedfs-master - restart: unless-stopped - command: > - master -ip=seaweedfs-master -ip.bind=0.0.0.0 -mdir=/data - -volumeSizeLimitMB=1024 -metricsPort=9324 - volumes: - # Named volume by default; set SEAWEED_DATA to a host path in .env for a - # bind mount. Back it up alongside PB_DATA: the attachments live here. - - "${SEAWEED_DATA:-seaweed_data}:/data" - healthcheck: - test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:9333/cluster/status || exit 1"] - interval: 10s - timeout: 3s - retries: 12 - start_period: 15s - - # --- SeaweedFS: volume server --------------------------------------------- - # Where the bytes land. -max=0 sizes it from free disk instead of the default - # cap of 8 volumes. - seaweedfs-volume: - image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" - container_name: docwell-aio-seaweedfs-volume - restart: unless-stopped - command: > - volume -master=seaweedfs-master:9333 -ip=seaweedfs-volume -ip.bind=0.0.0.0 - -port=8080 -dir=/data -max=0 -metricsPort=9325 - depends_on: - seaweedfs-master: - condition: service_healthy - volumes: - - "${SEAWEED_DATA:-seaweed_data}:/data" - # Never publish this one: port 8080 serves file content by file id with NO - # authentication. Publishing it would publish every attachment. - healthcheck: - test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8080/healthz || exit 1"] - interval: 10s - timeout: 3s - retries: 12 - start_period: 15s - - # --- SeaweedFS: filer ------------------------------------------------------ - # Gives the volume store a directory tree (buckets, object keys) and holds - # the S3 identities. -defaultStoreDir puts its leveldb on the volume, so the - # identities survive a recreate. - seaweedfs-filer: - image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" - container_name: docwell-aio-seaweedfs-filer - restart: unless-stopped - command: > - filer -master=seaweedfs-master:9333 -ip=seaweedfs-filer -ip.bind=0.0.0.0 - -port=8888 -defaultStoreDir=/data -metricsPort=9326 - depends_on: - seaweedfs-volume: - condition: service_healthy - volumes: - - "${SEAWEED_DATA:-seaweed_data}:/data" - healthcheck: - test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8888/healthz || exit 1"] - interval: 10s - timeout: 3s - retries: 12 - start_period: 15s - - # --- SeaweedFS: bucket and identity seed ---------------------------------- - # Runs once and exits, before the gateway starts: creates the bucket and - # writes PocketBase's S3 identity into the filer's IAM store, the same store - # the admin UI edits (env-var credentials would be silently displaced by the - # first user added there). Both commands update in place, so every boot - # re-applies .env, which is also how a rotated DOCWELL_S3_SECRET arrives. - # The closing grep is the gate: with an empty IAM store the gateway would - # allow anyone, so this fails loudly and the gateway never starts. - seaweedfs-init: - image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" - container_name: docwell-aio-seaweedfs-init - restart: "no" - depends_on: - seaweedfs-filer: - condition: service_healthy - environment: - # Expanded by the shell inside the container: the secret stays off argv. - DOCWELL_S3_BUCKET: "${DOCWELL_S3_BUCKET:-docwell}" - DOCWELL_S3_ACCESS_KEY: "${DOCWELL_S3_ACCESS_KEY:?set DOCWELL_S3_ACCESS_KEY in .env}" - DOCWELL_S3_SECRET: "${DOCWELL_S3_SECRET:?set DOCWELL_S3_SECRET in .env}" - entrypoint: ["/bin/sh", "-c"] - command: - - | - set -e - printf '%s\n' \ - "s3.bucket.create -name $$DOCWELL_S3_BUCKET" \ - "s3.configure -user docwell -access_key $$DOCWELL_S3_ACCESS_KEY -secret_key $$DOCWELL_S3_SECRET -actions Admin -apply" \ - | weed shell -master=seaweedfs-master:9333 -filer=seaweedfs-filer:8888 - echo "s3.configure" \ - | weed shell -master=seaweedfs-master:9333 -filer=seaweedfs-filer:8888 \ - | grep -q "$$DOCWELL_S3_ACCESS_KEY" - - # --- SeaweedFS: S3 gateway ------------------------------------------------- - # The endpoint PocketBase talks to. No -config file: credentials come from - # the filer's IAM store, so the admin UI can add and revoke identities - # without a restart. - seaweedfs-s3: - image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" - container_name: docwell-aio-seaweedfs-s3 - restart: unless-stopped - command: > - s3 -filer=seaweedfs-filer:8888 -ip.bind=0.0.0.0 -port=8333 - -metricsPort=9327 - depends_on: - seaweedfs-filer: - condition: service_healthy - # Never serve before an identity exists; see seaweedfs-init. - seaweedfs-init: - condition: service_completed_successfully - # No published port: the stack reaches the gateway over the compose network. - healthcheck: - test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8333/healthz || exit 1"] - interval: 10s - timeout: 3s - retries: 12 - start_period: 15s - - # --- SeaweedFS: admin UI --------------------------------------------------- - # Cluster view, buckets, maintenance, and Object Store -> Users, where S3 - # access keys are minted and revoked. A panel that can mint keys for the - # bucket is the bucket, so its password is required (weed turns auth off when - # it is empty). Read from WEED_ADMIN_*, which keeps it off the command line. - # Bound to loopback by default; set SEAWEED_ADMIN_BIND=0.0.0.0 only behind a - # reverse proxy. - seaweedfs-admin: - image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" - container_name: docwell-aio-seaweedfs-admin - restart: unless-stopped - command: > - admin -port=23646 -master=seaweedfs-master:9333 -dataDir=/data - -metricsPort=9328 - depends_on: - seaweedfs-master: - condition: service_healthy - environment: - WEED_ADMIN_USER: "${SEAWEED_ADMIN_USER:-admin}" - WEED_ADMIN_PASSWORD: "${SEAWEED_ADMIN_PASSWORD:?set SEAWEED_ADMIN_PASSWORD in .env}" - # Optional view-only login. - WEED_ADMIN_READONLY_USER: "${SEAWEED_ADMIN_READONLY_USER:-}" - WEED_ADMIN_READONLY_PASSWORD: "${SEAWEED_ADMIN_READONLY_PASSWORD:-}" - volumes: - # Session key and maintenance settings; no object data. - - "${SEAWEED_ADMIN_DATA:-seaweed_admin}:/data" - ports: - - "${SEAWEED_ADMIN_BIND:-127.0.0.1}:${SEAWEED_ADMIN_PORT:-23646}:23646" - healthcheck: - test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:23646/health || exit 1"] - interval: 10s - timeout: 3s - retries: 12 - start_period: 15s - docwell: - image: "${AIO_IMAGE:-${DOCWELL_REGISTRY:-ghcr.io/docwell}/docwell:${DOCWELL_VERSION:-latest}}" + build: + # The repository root (one level up from this compose file). + context: .. + dockerfile: Docker-AIO/Dockerfile.seaweedfs.split + args: + # Bare names: passed only when set, so an unset one keeps the + # Dockerfile's pin. + - PB_VERSION + - SEAWEED_VERSION + image: "${AIO_IMAGE:-${DOCWELL_REGISTRY:-ghcr.io/docwell}/docwell-seaweedfs-split:${DOCWELL_VERSION:-latest}}" container_name: docwell-aio restart: unless-stopped - depends_on: - # PocketBase reads and writes the objects, so the gateway must be serving. - seaweedfs-s3: - condition: service_healthy environment: # The PocketBase superuser the bundled server signs in with. REQUIRED. PB_ADMIN_EMAIL: "${PB_ADMIN_EMAIL:?set PB_ADMIN_EMAIL in .env}" @@ -245,42 +84,63 @@ services: DOCWELL_SMTP_USERNAME: "${DOCWELL_SMTP_USERNAME:-}" DOCWELL_SMTP_PASSWORD: "${DOCWELL_SMTP_PASSWORD:-}" DOCWELL_SMTP_TLS: "${DOCWELL_SMTP_TLS:-false}" - # --- File storage: the SeaweedFS in this stack ------------------------ - # Applied by docwell-server on every start, so these win over - # the admin panel's Storage screen. Only uploaded files move to the - # bucket; the database and PocketBase's backups stay on PB_DATA. - DOCWELL_S3_ENABLED: "true" - # The service name: a container-to-container call on the compose network. - DOCWELL_S3_ENDPOINT: "http://seaweedfs-s3:8333" + # --- File storage: the SeaweedFS inside this container ----------------- + # The image fixes the rest (DOCWELL_S3_ENABLED, the loopback endpoint, + # path style, the region). Applied by docwell-server on every start, so + # these win over the admin panel's Storage screen. + # + # The key pair does double duty: it is the gateway's identity, which + # takes it out of its default allow-anyone mode, and what PocketBase + # signs in with. No safe defaults: without it the container refuses to + # start. DOCWELL_S3_BUCKET: "${DOCWELL_S3_BUCKET:-docwell}" - # SeaweedFS ignores the region; PocketBase insists on having one. - DOCWELL_S3_REGION: "${DOCWELL_S3_REGION:-us-east-1}" DOCWELL_S3_ACCESS_KEY: "${DOCWELL_S3_ACCESS_KEY:?set DOCWELL_S3_ACCESS_KEY in .env}" DOCWELL_S3_SECRET: "${DOCWELL_S3_SECRET:?set DOCWELL_S3_SECRET in .env}" - # Path style: a self-hosted gateway has no per-bucket DNS names. - DOCWELL_S3_FORCE_PATH_STYLE: "true" + # --- SeaweedFS admin UI ------------------------------------------------ + # Cluster view and Object Store -> Users, where S3 keys are minted and + # revoked. It can hand out keys to the bucket, so its password is + # required (weed turns the login off when it is empty, and the container + # refuses to start without one). + WEED_ADMIN_USER: "${SEAWEED_ADMIN_USER:-admin}" + WEED_ADMIN_PASSWORD: "${SEAWEED_ADMIN_PASSWORD:?set SEAWEED_ADMIN_PASSWORD in .env}" + # Optional view-only login. + WEED_ADMIN_READONLY_USER: "${SEAWEED_ADMIN_READONLY_USER:-}" + WEED_ADMIN_READONLY_PASSWORD: "${SEAWEED_ADMIN_READONLY_PASSWORD:-}" volumes: - # Named volumes by default; set PB_DATA / SERVER_DATA to host paths in - # .env for bind mounts. - # Database, uploaded files, PocketBase backups: back this one up. + # Named volumes by default; set them to host paths in .env for bind + # mounts. + # Database, uploads made before S3 was on, PocketBase backups. - "${PB_DATA:-pb_data}:/pb_data" # The search index, rebuilt from the database when missing. - "${SERVER_DATA:-server_data}:/data" + # SeaweedFS: from here on the attachments live here. Back it up + # together with PB_DATA. + - "${SEAWEED_DATA:-seaweed_data}:/seaweed/data" + # The admin UI's session key and maintenance settings; no object data. + - "${SEAWEED_ADMIN_DATA:-seaweed_admin}:/seaweed/admin" ports: - # The only port: app, API, /collab websocket and /admin panel. + # The app: API, /collab websocket and /admin panel. - "${WEB_BIND:-0.0.0.0}:${WEB_PORT:-3000}:3000" + # The SeaweedFS admin UI. Loopback by default: it is storage plumbing, + # not one of the app's panels. Set SEAWEED_ADMIN_BIND=0.0.0.0 only + # behind a reverse proxy. + - "${SEAWEED_ADMIN_BIND:-127.0.0.1}:${SEAWEED_ADMIN_PORT:-23646}:23646" + # Nothing else of SeaweedFS is published: PocketBase reaches the gateway + # inside the container, and the volume server serves file content by id + # with no authentication. healthcheck: # Declared here as well as in the image, so it holds for any image tag. - # The version endpoint answers through docwell-web's proxy, so it only - # passes when all three processes are up. - test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:3000/api/v1/version >/dev/null || exit 1"] + # Every SeaweedFS role and the app (the version endpoint answers through + # docwell-web's proxy, so all three app processes) must answer. + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:9333/cluster/status >/dev/null && wget -qO- http://127.0.0.1:8081/healthz >/dev/null && wget -qO- http://127.0.0.1:8888/healthz >/dev/null && wget -qO- http://127.0.0.1:8333/healthz >/dev/null && wget -qO- http://127.0.0.1:23646/health >/dev/null && wget -qO- http://127.0.0.1:3000/api/v1/version >/dev/null || exit 1"] interval: 10s - timeout: 3s + timeout: 5s retries: 12 - start_period: 20s + start_period: 60s volumes: pb_data: server_data: + # The `weed server -dir` layout, shared with every other SeaweedFS file here. seaweed_data: seaweed_admin: diff --git a/Docker-AIO/docker-compose.prod.seaweedfs.yml b/Docker-AIO/docker-compose.prod.seaweedfs.yml index bfd612d..02b4704 100644 --- a/Docker-AIO/docker-compose.prod.seaweedfs.yml +++ b/Docker-AIO/docker-compose.prod.seaweedfs.yml @@ -1,96 +1,59 @@ name: docwell-aio -# Production Docwell all-in-one, with SeaweedFS. +# Production Docwell all-in-one with SeaweedFS built into ONE image: +# Dockerfile.seaweedfs bakes `weed server -s3` (master, volume, filer and S3 +# gateway in one process) into the same container as PocketBase, docwell-server +# and docwell-web. One service, one container, three volumes. For the admin UI +# and per-role metrics, see docker-compose.prod.seaweedfs.split.yml; for +# SeaweedFS in a container of its own (upgrade by tag), use +# docker-compose.seaweedfs.yml. The data volume is interchangeable between all +# of them (each writes the `weed server -dir` layout). # -# One container runs PocketBase, docwell-server and docwell-web, from the -# prebuilt image pulled from the registry instead of built from this checkout. # Self-contained: one file, no overlays. Everything an operator needs to set # lives in .env. # -# 1. cp .env.prod.seaweedfs.example .env (then edit it: passwords, URL, port) +# 1. cp .env.prod.seaweedfs.example .env (then edit it: passwords, URL, S3 keys) # 2. docker compose -f docker-compose.prod.seaweedfs.yml pull +# (or `build`, on a host with this checkout) # 3. docker compose -f docker-compose.prod.seaweedfs.yml up -d # -# This is docker-compose.prod.yml plus an S3 object store: PocketBase keeps -# uploaded files (attachments, images, avatars) in a SeaweedFS bucket instead -# of on the pb_data volume; the database and PocketBase's own backups stay on -# PB_DATA. Clients cannot tell: files are always fetched through -# docwell-server, never from a bucket URL. +# `image:` and `build:` are both set, so the same file pulls the released +# docwell-seaweedfs image or builds it; a built one can be `push`ed to AIO_IMAGE and +# pulled elsewhere. What baking SeaweedFS in costs: a new SeaweedFS is a new +# image (SEAWEED_VERSION), not a tag change. # -# SeaweedFS runs as one process here (`weed server -s3`). For separate master, -# volume, filer and gateway containers plus the SeaweedFS admin UI, use -# docker-compose.prod.seaweedfs.split.yml; the on-disk layout is the same, so -# SEAWEED_DATA moves between the two files unchanged. +# PocketBase keeps uploaded files (attachments, images, avatars) in the bucket +# instead of on the pb_data volume; the database and PocketBase's own backups +# stay on PB_DATA. Clients cannot tell: files are always fetched through +# docwell-server, never from a bucket URL. # # Before switching a stack that already has uploads: PocketBase does NOT copy # existing files into the bucket. See README.md. # -# SeaweedFS runs in containers of its own next to the all-in-one container, -# which is the same image as in docker-compose.prod.yml: no rebuild to add or -# drop the object store, and a SeaweedFS upgrade is a tag change. -# # Traffic flow (browser): one port. docwell-web serves the app and proxies # /api, /collab and /admin to docwell-server inside the container; PocketBase -# listens on the container's loopback only. +# and every SeaweedFS role but the admin UI listen on the container's loopback. # -# On every boot the container creates or updates the PocketBase superuser -# from PB_ADMIN_* (a changed password is applied); docwell-server then brings +# On every boot the container creates the bucket, creates or +# updates the PocketBase superuser from PB_ADMIN_*, and docwell-server brings # the collections up to Docwell's schema and writes the env-driven settings -# (mail, app URL, file storage). All idempotent, so restarts -# and upgrades are safe. +# (mail, app URL, file storage). All idempotent, so restarts and upgrades are +# safe. services: - seaweedfs: - image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" - container_name: docwell-aio-seaweedfs - restart: unless-stopped - # One process, four roles: master, volume, filer and the S3 gateway. -dir - # is the only state it keeps. - command: server -dir=/data -s3 -master.volumeSizeLimitMB=1024 - environment: - # Read when SeaweedFS starts without an -s3.config file. One identity is - # what takes the S3 gateway out of its default allow-anyone mode; it is - # the same pair PocketBase signs in with, so there is one pair to set. - AWS_ACCESS_KEY_ID: "${DOCWELL_S3_ACCESS_KEY:?set DOCWELL_S3_ACCESS_KEY in .env}" - AWS_SECRET_ACCESS_KEY: "${DOCWELL_S3_SECRET:?set DOCWELL_S3_SECRET in .env}" - volumes: - # Named volume by default; set SEAWEED_DATA to a host path in .env for a - # bind mount. Back it up alongside PB_DATA: the attachments live here. - - "${SEAWEED_DATA:-seaweed_data}:/data" - # No published port: the stack reaches the gateway over the compose network. - healthcheck: - test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:9333/cluster/status || exit 1"] - interval: 10s - timeout: 3s - retries: 12 - start_period: 20s - - seaweedfs-init: - image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" - container_name: docwell-aio-seaweedfs-init - # Runs once and exits. PocketBase never creates a bucket of its own and - # SeaweedFS does not make one on first upload, so this does. Creating a - # bucket that already exists is a no-op, so later boots pass straight - # through; `|| true` keeps a hiccup here from blocking a restart (the - # admin panel's "Test the saved bucket" reports a missing bucket). - restart: "no" - depends_on: - seaweedfs: - condition: service_healthy - environment: - DOCWELL_S3_BUCKET: "${DOCWELL_S3_BUCKET:-docwell}" - entrypoint: ["/bin/sh", "-c"] - command: - - 'echo "s3.bucket.create -name $$DOCWELL_S3_BUCKET" | weed shell -master=seaweedfs:9333 || true' - docwell: - image: "${AIO_IMAGE:-${DOCWELL_REGISTRY:-ghcr.io/docwell}/docwell:${DOCWELL_VERSION:-latest}}" + build: + # The repository root (one level up from this compose file). + context: .. + dockerfile: Docker-AIO/Dockerfile.seaweedfs + args: + # Bare names: passed only when set, so an unset one keeps the + # Dockerfile's pin. + - PB_VERSION + - SEAWEED_VERSION + image: "${AIO_IMAGE:-${DOCWELL_REGISTRY:-ghcr.io/docwell}/docwell-seaweedfs:${DOCWELL_VERSION:-latest}}" container_name: docwell-aio restart: unless-stopped - depends_on: - # PocketBase reads and writes the objects, so the bucket must exist first. - seaweedfs-init: - condition: service_completed_successfully environment: # The PocketBase superuser the bundled server signs in with. REQUIRED. PB_ADMIN_EMAIL: "${PB_ADMIN_EMAIL:?set PB_ADMIN_EMAIL in .env}" @@ -121,41 +84,46 @@ services: DOCWELL_SMTP_USERNAME: "${DOCWELL_SMTP_USERNAME:-}" DOCWELL_SMTP_PASSWORD: "${DOCWELL_SMTP_PASSWORD:-}" DOCWELL_SMTP_TLS: "${DOCWELL_SMTP_TLS:-false}" - # --- File storage: the SeaweedFS in this stack ------------------------ - # Applied by docwell-server on every start, so these win over - # the admin panel's Storage screen. Only uploaded files move to the - # bucket; the database and PocketBase's backups stay on PB_DATA. - DOCWELL_S3_ENABLED: "true" - # The service name: a container-to-container call on the compose network. - DOCWELL_S3_ENDPOINT: "http://seaweedfs:8333" + # --- File storage: the SeaweedFS inside this container ----------------- + # The image fixes the rest (DOCWELL_S3_ENABLED, the loopback endpoint, + # path style, the region). Applied by docwell-server on every start, so + # these win over the admin panel's Storage screen. + # + # The key pair does double duty: it is the gateway's identity, which + # takes it out of its default allow-anyone mode, and what PocketBase + # signs in with. No safe defaults: without it the container refuses to + # start. DOCWELL_S3_BUCKET: "${DOCWELL_S3_BUCKET:-docwell}" - # SeaweedFS ignores the region; PocketBase insists on having one. - DOCWELL_S3_REGION: "${DOCWELL_S3_REGION:-us-east-1}" DOCWELL_S3_ACCESS_KEY: "${DOCWELL_S3_ACCESS_KEY:?set DOCWELL_S3_ACCESS_KEY in .env}" DOCWELL_S3_SECRET: "${DOCWELL_S3_SECRET:?set DOCWELL_S3_SECRET in .env}" - # Path style: a self-hosted gateway has no per-bucket DNS names. - DOCWELL_S3_FORCE_PATH_STYLE: "true" volumes: - # Named volumes by default; set PB_DATA / SERVER_DATA to host paths in - # .env for bind mounts. - # Database, uploaded files, PocketBase backups: back this one up. + # Named volumes by default; set them to host paths in .env for bind + # mounts. + # Database, uploads made before S3 was on, PocketBase backups. - "${PB_DATA:-pb_data}:/pb_data" # The search index, rebuilt from the database when missing. - "${SERVER_DATA:-server_data}:/data" + # SeaweedFS: from here on the attachments live here. Back it up + # together with PB_DATA. + - "${SEAWEED_DATA:-seaweed_data}:/seaweed/data" ports: - # The only port: app, API, /collab websocket and /admin panel. + # The app: API, /collab websocket and /admin panel. - "${WEB_BIND:-0.0.0.0}:${WEB_PORT:-3000}:3000" + # Nothing else of SeaweedFS is published: PocketBase reaches the gateway + # inside the container, and the volume server serves file content by id + # with no authentication. healthcheck: # Declared here as well as in the image, so it holds for any image tag. - # The version endpoint answers through docwell-web's proxy, so it only - # passes when all three processes are up. - test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:3000/api/v1/version >/dev/null || exit 1"] + # Every SeaweedFS role and the app (the version endpoint answers through + # docwell-web's proxy, so all three app processes) must answer. + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:9333/cluster/status >/dev/null && wget -qO- http://127.0.0.1:8333/healthz >/dev/null && wget -qO- http://127.0.0.1:3000/api/v1/version >/dev/null || exit 1"] interval: 10s - timeout: 3s + timeout: 5s retries: 12 - start_period: 20s + start_period: 60s volumes: pb_data: server_data: + # The `weed server -dir` layout, shared with every other SeaweedFS file here. seaweed_data: diff --git a/Docker-AIO/docker-compose.s3.yml b/Docker-AIO/docker-compose.s3.yml new file mode 100644 index 0000000..d83b05e --- /dev/null +++ b/Docker-AIO/docker-compose.s3.yml @@ -0,0 +1,106 @@ +name: docwell-aio + +# Docwell all-in-one, with external S3, built from this checkout. +# +# One container runs PocketBase, docwell-server and docwell-web. Self-contained: +# one file, no overlays. Everything to set lives in .env. +# +# cp .env.s3.example .env (then edit it) +# docker compose -f docker-compose.s3.yml up -d --build +# +# Without --build it pulls the released image instead. For production with a +# released image, use the docker-compose.prod.* twin of this file. +# +# This is docker-compose.yml pointed at an S3 bucket that already exists +# somewhere else: AWS, a MinIO or SeaweedFS on another host, any S3-compatible +# service. PocketBase keeps uploaded files there instead of on the pb_data +# volume; the database and PocketBase's own backups stay on PB_DATA. The bucket +# must already exist; for a SeaweedFS that comes up with the stack, use +# docker-compose.seaweedfs.yml. +# +# Before switching a stack that already has uploads: PocketBase does NOT copy +# existing files into the bucket. See README.md. +# +# Traffic flow (browser): one port. docwell-web serves the app and proxies +# /api, /collab and /admin to docwell-server inside the container; PocketBase +# listens on the container's loopback only. + +services: + docwell: + image: "${DOCWELL_REGISTRY:-ghcr.io/docwell}/docwell:${DOCWELL_VERSION:-latest}" + build: + # The repository root (one level up from this compose file). + context: .. + dockerfile: Docker-AIO/Dockerfile + container_name: docwell-aio + restart: unless-stopped + extra_hosts: + # Lets DOCWELL_S3_ENDPOINT name the Docker host as host.docker.internal. + # Harmless when the endpoint is somewhere else. + - "host.docker.internal:host-gateway" + environment: + # The PocketBase superuser the bundled server signs in with. REQUIRED. + PB_ADMIN_EMAIL: "${PB_ADMIN_EMAIL:?set PB_ADMIN_EMAIL in .env}" + PB_ADMIN_PASSWORD: "${PB_ADMIN_PASSWORD:?set PB_ADMIN_PASSWORD in .env}" + # Encrypts PocketBase's stored settings (SMTP password, S3 secret). + # Exactly 32 characters; blank = off. Set it before the first boot and + # never lose it: the settings cannot be read without it. + PB_ENCRYPTION_KEY: "${PB_ENCRYPTION_KEY:-}" + # The public address: links in auth emails and share links point here. + DOCWELL_WEB_URL: "${DOCWELL_WEB_URL:-http://localhost:3000}" + DOCWELL_PUBLIC_URL: "${DOCWELL_WEB_URL:-http://localhost:3000}" + DOCWELL_CORS_ORIGINS: "${DOCWELL_WEB_URL:-http://localhost:3000}" + DOCWELL_APP_NAME: "${DOCWELL_APP_NAME:-}" + DOCWELL_DRAWIO_URL: "${DOCWELL_DRAWIO_URL:-}" + # Defaults until a superadmin saves sign-up rules in the admin panel. + DOCWELL_SIGNUP_ENABLED: "${DOCWELL_SIGNUP_ENABLED:-true}" + # Optional: creates the first account as superadmin while there are no accounts. + DOCWELL_ADMIN_EMAIL: "${DOCWELL_ADMIN_EMAIL:-}" + DOCWELL_ADMIN_PASSWORD: "${DOCWELL_ADMIN_PASSWORD:-}" + DOCWELL_ADMIN_NAME: "${DOCWELL_ADMIN_NAME:-}" + DOCWELL_SIGNUP_DOMAINS: "${DOCWELL_SIGNUP_DOMAINS:-}" + DOCWELL_MAX_UPLOAD_MB: "${DOCWELL_MAX_UPLOAD_MB:-50}" + DOCWELL_AUDIT_RETENTION_DAYS: "${DOCWELL_AUDIT_RETENTION_DAYS:-}" + # Verification, password reset and sign-in codes, sent by PocketBase. + DOCWELL_MAIL_FROM: "${DOCWELL_MAIL_FROM:-}" + DOCWELL_SMTP_HOST: "${DOCWELL_SMTP_HOST:-}" + DOCWELL_SMTP_PORT: "${DOCWELL_SMTP_PORT:-587}" + DOCWELL_SMTP_USERNAME: "${DOCWELL_SMTP_USERNAME:-}" + DOCWELL_SMTP_PASSWORD: "${DOCWELL_SMTP_PASSWORD:-}" + DOCWELL_SMTP_TLS: "${DOCWELL_SMTP_TLS:-false}" + # --- File storage: external S3 -------------------------------------- + # Applied by docwell-server on every start, so these win over the + # admin panel's Storage screen. Only uploaded files move to the bucket; + # the database and PocketBase's backups stay on PB_DATA. The bucket must + # already exist: nothing here creates it. + DOCWELL_S3_ENABLED: "true" + DOCWELL_S3_ENDPOINT: "${DOCWELL_S3_ENDPOINT:?set DOCWELL_S3_ENDPOINT in .env}" + DOCWELL_S3_BUCKET: "${DOCWELL_S3_BUCKET:-docwell}" + DOCWELL_S3_REGION: "${DOCWELL_S3_REGION:-us-east-1}" + DOCWELL_S3_ACCESS_KEY: "${DOCWELL_S3_ACCESS_KEY:?set DOCWELL_S3_ACCESS_KEY in .env}" + DOCWELL_S3_SECRET: "${DOCWELL_S3_SECRET:?set DOCWELL_S3_SECRET in .env}" + # true for SeaweedFS and MinIO, false for AWS S3 proper. + DOCWELL_S3_FORCE_PATH_STYLE: "${DOCWELL_S3_FORCE_PATH_STYLE:-true}" + volumes: + # Named volumes by default; set PB_DATA / SERVER_DATA to host paths in + # .env for bind mounts. + # Database, uploaded files, PocketBase backups: back this one up. + - "${PB_DATA:-pb_data}:/pb_data" + # The search index, rebuilt from the database when missing. + - "${SERVER_DATA:-server_data}:/data" + ports: + # The only port: app, API, /collab websocket and /admin panel. + - "${WEB_BIND:-0.0.0.0}:${WEB_PORT:-3000}:3000" + healthcheck: + # Declared here as well as in the image, so it holds for any image tag. + # The version endpoint answers through docwell-web's proxy, so it only + # passes when all three processes are up. + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:3000/api/v1/version >/dev/null || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 20s + +volumes: + pb_data: + server_data: diff --git a/Docker-AIO/docker-compose.seaweedfs.split.yml b/Docker-AIO/docker-compose.seaweedfs.split.yml new file mode 100644 index 0000000..3ae688a --- /dev/null +++ b/Docker-AIO/docker-compose.seaweedfs.split.yml @@ -0,0 +1,277 @@ +name: docwell-aio + +# Docwell all-in-one, with SeaweedFS split into its roles, built from this checkout. +# +# One container runs PocketBase, docwell-server and docwell-web. Self-contained: +# one file, no overlays. Everything to set lives in .env. +# +# cp .env.seaweedfs.split.example .env (then edit it) +# docker compose -f docker-compose.seaweedfs.split.yml up -d --build +# +# Without --build it pulls the released image instead. For production with a +# released image, use the docker-compose.prod.* twin of this file. +# +# This is docker-compose.seaweedfs.yml with SeaweedFS taken apart into its +# roles, each its own container: master, volume, filer, S3 gateway, plus the +# SeaweedFS admin UI. What that buys: +# +# - the admin UI (weed admin): a cluster view, and Object Store -> Users, +# where S3 identities are created and revoked without touching a file; +# - per-role restart, upgrade and Prometheus metrics; +# - room for a second volume server later, on this host or another. +# +# Master, volume and filer share one /data mount, laid out exactly as +# `weed server -dir` lays it out, so every SeaweedFS file here shares +# SEAWEED_DATA with no migration either way. Only the admin UI publishes a port +# (loopback by default); the volume server serves file content by id with no +# authentication, so it is never published. +# +# Before switching a stack that already has uploads: PocketBase does NOT copy +# existing files into the bucket. See README.md. +# +# Traffic flow (browser): one port. docwell-web serves the app and proxies +# /api, /collab and /admin to docwell-server inside the container; PocketBase +# listens on the container's loopback only. + +services: + # --- SeaweedFS: master ----------------------------------------------------- + # Keeps the volume topology and hands out file ids. -ip is the name the other + # roles reach it by, so it is the service name, not the container IP. + seaweedfs-master: + image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" + container_name: docwell-aio-seaweedfs-master + restart: unless-stopped + command: > + master -ip=seaweedfs-master -ip.bind=0.0.0.0 -mdir=/data + -volumeSizeLimitMB=1024 -metricsPort=9324 + volumes: + # Named volume by default; set SEAWEED_DATA to a host path in .env for a + # bind mount. Back it up alongside PB_DATA: the attachments live here. + - "${SEAWEED_DATA:-seaweed_data}:/data" + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:9333/cluster/status || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 15s + + # --- SeaweedFS: volume server --------------------------------------------- + # Where the bytes land. -max=0 sizes it from free disk instead of the default + # cap of 8 volumes. + seaweedfs-volume: + image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" + container_name: docwell-aio-seaweedfs-volume + restart: unless-stopped + command: > + volume -master=seaweedfs-master:9333 -ip=seaweedfs-volume -ip.bind=0.0.0.0 + -port=8080 -dir=/data -max=0 -metricsPort=9325 + depends_on: + seaweedfs-master: + condition: service_healthy + volumes: + - "${SEAWEED_DATA:-seaweed_data}:/data" + # Never publish this one: port 8080 serves file content by file id with NO + # authentication. Publishing it would publish every attachment. + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8080/healthz || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 15s + + # --- SeaweedFS: filer ------------------------------------------------------ + # Gives the volume store a directory tree (buckets, object keys) and holds + # the S3 identities. -defaultStoreDir puts its leveldb on the volume, so the + # identities survive a recreate. + seaweedfs-filer: + image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" + container_name: docwell-aio-seaweedfs-filer + restart: unless-stopped + command: > + filer -master=seaweedfs-master:9333 -ip=seaweedfs-filer -ip.bind=0.0.0.0 + -port=8888 -defaultStoreDir=/data -metricsPort=9326 + depends_on: + seaweedfs-volume: + condition: service_healthy + volumes: + - "${SEAWEED_DATA:-seaweed_data}:/data" + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8888/healthz || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 15s + + # --- SeaweedFS: bucket and identity seed ---------------------------------- + # Runs once and exits, before the gateway starts: creates the bucket and + # writes PocketBase's S3 identity into the filer's IAM store, the same store + # the admin UI edits (env-var credentials would be silently displaced by the + # first user added there). Both commands update in place, so every boot + # re-applies .env, which is also how a rotated DOCWELL_S3_SECRET arrives. + # The closing grep is the gate: with an empty IAM store the gateway would + # allow anyone, so this fails loudly and the gateway never starts. + seaweedfs-init: + image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" + container_name: docwell-aio-seaweedfs-init + restart: "no" + depends_on: + seaweedfs-filer: + condition: service_healthy + environment: + # Expanded by the shell inside the container: the secret stays off argv. + DOCWELL_S3_BUCKET: "${DOCWELL_S3_BUCKET:-docwell}" + DOCWELL_S3_ACCESS_KEY: "${DOCWELL_S3_ACCESS_KEY:?set DOCWELL_S3_ACCESS_KEY in .env}" + DOCWELL_S3_SECRET: "${DOCWELL_S3_SECRET:?set DOCWELL_S3_SECRET in .env}" + entrypoint: ["/bin/sh", "-c"] + command: + - | + set -e + printf '%s\n' \ + "s3.bucket.create -name $$DOCWELL_S3_BUCKET" \ + "s3.configure -user docwell -access_key $$DOCWELL_S3_ACCESS_KEY -secret_key $$DOCWELL_S3_SECRET -actions Admin -apply" \ + | weed shell -master=seaweedfs-master:9333 -filer=seaweedfs-filer:8888 + echo "s3.configure" \ + | weed shell -master=seaweedfs-master:9333 -filer=seaweedfs-filer:8888 \ + | grep -q "$$DOCWELL_S3_ACCESS_KEY" + + # --- SeaweedFS: S3 gateway ------------------------------------------------- + # The endpoint PocketBase talks to. No -config file: credentials come from + # the filer's IAM store, so the admin UI can add and revoke identities + # without a restart. + seaweedfs-s3: + image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" + container_name: docwell-aio-seaweedfs-s3 + restart: unless-stopped + command: > + s3 -filer=seaweedfs-filer:8888 -ip.bind=0.0.0.0 -port=8333 + -metricsPort=9327 + depends_on: + seaweedfs-filer: + condition: service_healthy + # Never serve before an identity exists; see seaweedfs-init. + seaweedfs-init: + condition: service_completed_successfully + # No published port: the stack reaches the gateway over the compose network. + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8333/healthz || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 15s + + # --- SeaweedFS: admin UI --------------------------------------------------- + # Cluster view, buckets, maintenance, and Object Store -> Users, where S3 + # access keys are minted and revoked. A panel that can mint keys for the + # bucket is the bucket, so its password is required (weed turns auth off when + # it is empty). Read from WEED_ADMIN_*, which keeps it off the command line. + # Bound to loopback by default; set SEAWEED_ADMIN_BIND=0.0.0.0 only behind a + # reverse proxy. + seaweedfs-admin: + image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" + container_name: docwell-aio-seaweedfs-admin + restart: unless-stopped + command: > + admin -port=23646 -master=seaweedfs-master:9333 -dataDir=/data + -metricsPort=9328 + depends_on: + seaweedfs-master: + condition: service_healthy + environment: + WEED_ADMIN_USER: "${SEAWEED_ADMIN_USER:-admin}" + WEED_ADMIN_PASSWORD: "${SEAWEED_ADMIN_PASSWORD:?set SEAWEED_ADMIN_PASSWORD in .env}" + # Optional view-only login. + WEED_ADMIN_READONLY_USER: "${SEAWEED_ADMIN_READONLY_USER:-}" + WEED_ADMIN_READONLY_PASSWORD: "${SEAWEED_ADMIN_READONLY_PASSWORD:-}" + volumes: + # Session key and maintenance settings; no object data. + - "${SEAWEED_ADMIN_DATA:-seaweed_admin}:/data" + ports: + - "${SEAWEED_ADMIN_BIND:-127.0.0.1}:${SEAWEED_ADMIN_PORT:-23646}:23646" + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:23646/health || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 15s + + docwell: + image: "${DOCWELL_REGISTRY:-ghcr.io/docwell}/docwell:${DOCWELL_VERSION:-latest}" + build: + # The repository root (one level up from this compose file). + context: .. + dockerfile: Docker-AIO/Dockerfile + container_name: docwell-aio + restart: unless-stopped + depends_on: + # PocketBase reads and writes the objects, so the gateway must be serving. + seaweedfs-s3: + condition: service_healthy + environment: + # The PocketBase superuser the bundled server signs in with. REQUIRED. + PB_ADMIN_EMAIL: "${PB_ADMIN_EMAIL:?set PB_ADMIN_EMAIL in .env}" + PB_ADMIN_PASSWORD: "${PB_ADMIN_PASSWORD:?set PB_ADMIN_PASSWORD in .env}" + # Encrypts PocketBase's stored settings (SMTP password, S3 secret). + # Exactly 32 characters; blank = off. Set it before the first boot and + # never lose it: the settings cannot be read without it. + PB_ENCRYPTION_KEY: "${PB_ENCRYPTION_KEY:-}" + # The public address: links in auth emails and share links point here. + DOCWELL_WEB_URL: "${DOCWELL_WEB_URL:-http://localhost:3000}" + DOCWELL_PUBLIC_URL: "${DOCWELL_WEB_URL:-http://localhost:3000}" + DOCWELL_CORS_ORIGINS: "${DOCWELL_WEB_URL:-http://localhost:3000}" + DOCWELL_APP_NAME: "${DOCWELL_APP_NAME:-}" + DOCWELL_DRAWIO_URL: "${DOCWELL_DRAWIO_URL:-}" + # Defaults until a superadmin saves sign-up rules in the admin panel. + DOCWELL_SIGNUP_ENABLED: "${DOCWELL_SIGNUP_ENABLED:-true}" + # Optional: creates the first account as superadmin while there are no accounts. + DOCWELL_ADMIN_EMAIL: "${DOCWELL_ADMIN_EMAIL:-}" + DOCWELL_ADMIN_PASSWORD: "${DOCWELL_ADMIN_PASSWORD:-}" + DOCWELL_ADMIN_NAME: "${DOCWELL_ADMIN_NAME:-}" + DOCWELL_SIGNUP_DOMAINS: "${DOCWELL_SIGNUP_DOMAINS:-}" + DOCWELL_MAX_UPLOAD_MB: "${DOCWELL_MAX_UPLOAD_MB:-50}" + DOCWELL_AUDIT_RETENTION_DAYS: "${DOCWELL_AUDIT_RETENTION_DAYS:-}" + # Verification, password reset and sign-in codes, sent by PocketBase. + DOCWELL_MAIL_FROM: "${DOCWELL_MAIL_FROM:-}" + DOCWELL_SMTP_HOST: "${DOCWELL_SMTP_HOST:-}" + DOCWELL_SMTP_PORT: "${DOCWELL_SMTP_PORT:-587}" + DOCWELL_SMTP_USERNAME: "${DOCWELL_SMTP_USERNAME:-}" + DOCWELL_SMTP_PASSWORD: "${DOCWELL_SMTP_PASSWORD:-}" + DOCWELL_SMTP_TLS: "${DOCWELL_SMTP_TLS:-false}" + # --- File storage: the SeaweedFS in this stack ------------------------ + # Applied by docwell-server on every start, so these win over + # the admin panel's Storage screen. Only uploaded files move to the + # bucket; the database and PocketBase's backups stay on PB_DATA. + DOCWELL_S3_ENABLED: "true" + # The service name: a container-to-container call on the compose network. + DOCWELL_S3_ENDPOINT: "http://seaweedfs-s3:8333" + DOCWELL_S3_BUCKET: "${DOCWELL_S3_BUCKET:-docwell}" + # SeaweedFS ignores the region; PocketBase insists on having one. + DOCWELL_S3_REGION: "${DOCWELL_S3_REGION:-us-east-1}" + DOCWELL_S3_ACCESS_KEY: "${DOCWELL_S3_ACCESS_KEY:?set DOCWELL_S3_ACCESS_KEY in .env}" + DOCWELL_S3_SECRET: "${DOCWELL_S3_SECRET:?set DOCWELL_S3_SECRET in .env}" + # Path style: a self-hosted gateway has no per-bucket DNS names. + DOCWELL_S3_FORCE_PATH_STYLE: "true" + volumes: + # Named volumes by default; set PB_DATA / SERVER_DATA to host paths in + # .env for bind mounts. + # Database, uploaded files, PocketBase backups: back this one up. + - "${PB_DATA:-pb_data}:/pb_data" + # The search index, rebuilt from the database when missing. + - "${SERVER_DATA:-server_data}:/data" + ports: + # The only port: app, API, /collab websocket and /admin panel. + - "${WEB_BIND:-0.0.0.0}:${WEB_PORT:-3000}:3000" + healthcheck: + # Declared here as well as in the image, so it holds for any image tag. + # The version endpoint answers through docwell-web's proxy, so it only + # passes when all three processes are up. + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:3000/api/v1/version >/dev/null || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 20s + +volumes: + pb_data: + server_data: + seaweed_data: + seaweed_admin: diff --git a/Docker-AIO/docker-compose.seaweedfs.yml b/Docker-AIO/docker-compose.seaweedfs.yml new file mode 100644 index 0000000..08cb663 --- /dev/null +++ b/Docker-AIO/docker-compose.seaweedfs.yml @@ -0,0 +1,152 @@ +name: docwell-aio + +# Docwell all-in-one, with SeaweedFS, built from this checkout. +# +# One container runs PocketBase, docwell-server and docwell-web. Self-contained: +# one file, no overlays. Everything to set lives in .env. +# +# cp .env.seaweedfs.example .env (then edit it) +# docker compose -f docker-compose.seaweedfs.yml up -d --build +# +# Without --build it pulls the released image instead. For production with a +# released image, use the docker-compose.prod.* twin of this file. +# +# This is docker-compose.yml plus an S3 object store: PocketBase keeps uploaded +# files in a SeaweedFS bucket instead of on the pb_data volume; the database and +# PocketBase's own backups stay on PB_DATA. SeaweedFS runs as one process +# (`weed server -s3`) in a container of its own next to the all-in-one one, so +# the Docwell image stays the plain one and a SeaweedFS upgrade is a tag change. +# docker-compose.prod.seaweedfs.yml bakes the same SeaweedFS into the image +# instead (Dockerfile.seaweedfs); SEAWEED_DATA moves between them unchanged. +# +# Before switching a stack that already has uploads: PocketBase does NOT copy +# existing files into the bucket. See README.md. +# +# Traffic flow (browser): one port. docwell-web serves the app and proxies +# /api, /collab and /admin to docwell-server inside the container; PocketBase +# listens on the container's loopback only. + +services: + seaweedfs: + image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" + container_name: docwell-aio-seaweedfs + restart: unless-stopped + # One process, four roles: master, volume, filer and the S3 gateway. -dir + # is the only state it keeps. + command: server -dir=/data -s3 -master.volumeSizeLimitMB=1024 + environment: + # Read when SeaweedFS starts without an -s3.config file. One identity is + # what takes the S3 gateway out of its default allow-anyone mode; it is + # the same pair PocketBase signs in with, so there is one pair to set. + AWS_ACCESS_KEY_ID: "${DOCWELL_S3_ACCESS_KEY:?set DOCWELL_S3_ACCESS_KEY in .env}" + AWS_SECRET_ACCESS_KEY: "${DOCWELL_S3_SECRET:?set DOCWELL_S3_SECRET in .env}" + volumes: + # Named volume by default; set SEAWEED_DATA to a host path in .env for a + # bind mount. Back it up alongside PB_DATA: the attachments live here. + - "${SEAWEED_DATA:-seaweed_data}:/data" + # No published port: the stack reaches the gateway over the compose network. + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:9333/cluster/status || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 20s + + seaweedfs-init: + image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" + container_name: docwell-aio-seaweedfs-init + # Runs once and exits. PocketBase never creates a bucket of its own and + # SeaweedFS does not make one on first upload, so this does. Creating a + # bucket that already exists is a no-op, so later boots pass straight + # through; `|| true` keeps a hiccup here from blocking a restart (the + # admin panel's "Test the saved bucket" reports a missing bucket). + restart: "no" + depends_on: + seaweedfs: + condition: service_healthy + environment: + DOCWELL_S3_BUCKET: "${DOCWELL_S3_BUCKET:-docwell}" + entrypoint: ["/bin/sh", "-c"] + command: + - 'echo "s3.bucket.create -name $$DOCWELL_S3_BUCKET" | weed shell -master=seaweedfs:9333 || true' + + docwell: + image: "${DOCWELL_REGISTRY:-ghcr.io/docwell}/docwell:${DOCWELL_VERSION:-latest}" + build: + # The repository root (one level up from this compose file). + context: .. + dockerfile: Docker-AIO/Dockerfile + container_name: docwell-aio + restart: unless-stopped + depends_on: + # PocketBase reads and writes the objects, so the bucket must exist first. + seaweedfs-init: + condition: service_completed_successfully + environment: + # The PocketBase superuser the bundled server signs in with. REQUIRED. + PB_ADMIN_EMAIL: "${PB_ADMIN_EMAIL:?set PB_ADMIN_EMAIL in .env}" + PB_ADMIN_PASSWORD: "${PB_ADMIN_PASSWORD:?set PB_ADMIN_PASSWORD in .env}" + # Encrypts PocketBase's stored settings (SMTP password, S3 secret). + # Exactly 32 characters; blank = off. Set it before the first boot and + # never lose it: the settings cannot be read without it. + PB_ENCRYPTION_KEY: "${PB_ENCRYPTION_KEY:-}" + # The public address: links in auth emails and share links point here. + DOCWELL_WEB_URL: "${DOCWELL_WEB_URL:-http://localhost:3000}" + DOCWELL_PUBLIC_URL: "${DOCWELL_WEB_URL:-http://localhost:3000}" + DOCWELL_CORS_ORIGINS: "${DOCWELL_WEB_URL:-http://localhost:3000}" + DOCWELL_APP_NAME: "${DOCWELL_APP_NAME:-}" + DOCWELL_DRAWIO_URL: "${DOCWELL_DRAWIO_URL:-}" + # Defaults until a superadmin saves sign-up rules in the admin panel. + DOCWELL_SIGNUP_ENABLED: "${DOCWELL_SIGNUP_ENABLED:-true}" + # Optional: creates the first account as superadmin while there are no accounts. + DOCWELL_ADMIN_EMAIL: "${DOCWELL_ADMIN_EMAIL:-}" + DOCWELL_ADMIN_PASSWORD: "${DOCWELL_ADMIN_PASSWORD:-}" + DOCWELL_ADMIN_NAME: "${DOCWELL_ADMIN_NAME:-}" + DOCWELL_SIGNUP_DOMAINS: "${DOCWELL_SIGNUP_DOMAINS:-}" + DOCWELL_MAX_UPLOAD_MB: "${DOCWELL_MAX_UPLOAD_MB:-50}" + DOCWELL_AUDIT_RETENTION_DAYS: "${DOCWELL_AUDIT_RETENTION_DAYS:-}" + # Verification, password reset and sign-in codes, sent by PocketBase. + DOCWELL_MAIL_FROM: "${DOCWELL_MAIL_FROM:-}" + DOCWELL_SMTP_HOST: "${DOCWELL_SMTP_HOST:-}" + DOCWELL_SMTP_PORT: "${DOCWELL_SMTP_PORT:-587}" + DOCWELL_SMTP_USERNAME: "${DOCWELL_SMTP_USERNAME:-}" + DOCWELL_SMTP_PASSWORD: "${DOCWELL_SMTP_PASSWORD:-}" + DOCWELL_SMTP_TLS: "${DOCWELL_SMTP_TLS:-false}" + # --- File storage: the SeaweedFS in this stack ------------------------ + # Applied by docwell-server on every start, so these win over + # the admin panel's Storage screen. Only uploaded files move to the + # bucket; the database and PocketBase's backups stay on PB_DATA. + DOCWELL_S3_ENABLED: "true" + # The service name: a container-to-container call on the compose network. + DOCWELL_S3_ENDPOINT: "http://seaweedfs:8333" + DOCWELL_S3_BUCKET: "${DOCWELL_S3_BUCKET:-docwell}" + # SeaweedFS ignores the region; PocketBase insists on having one. + DOCWELL_S3_REGION: "${DOCWELL_S3_REGION:-us-east-1}" + DOCWELL_S3_ACCESS_KEY: "${DOCWELL_S3_ACCESS_KEY:?set DOCWELL_S3_ACCESS_KEY in .env}" + DOCWELL_S3_SECRET: "${DOCWELL_S3_SECRET:?set DOCWELL_S3_SECRET in .env}" + # Path style: a self-hosted gateway has no per-bucket DNS names. + DOCWELL_S3_FORCE_PATH_STYLE: "true" + volumes: + # Named volumes by default; set PB_DATA / SERVER_DATA to host paths in + # .env for bind mounts. + # Database, uploaded files, PocketBase backups: back this one up. + - "${PB_DATA:-pb_data}:/pb_data" + # The search index, rebuilt from the database when missing. + - "${SERVER_DATA:-server_data}:/data" + ports: + # The only port: app, API, /collab websocket and /admin panel. + - "${WEB_BIND:-0.0.0.0}:${WEB_PORT:-3000}:3000" + healthcheck: + # Declared here as well as in the image, so it holds for any image tag. + # The version endpoint answers through docwell-web's proxy, so it only + # passes when all three processes are up. + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:3000/api/v1/version >/dev/null || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 20s + +volumes: + pb_data: + server_data: + seaweed_data: diff --git a/Docker-AIO/docker-compose.yml b/Docker-AIO/docker-compose.yml index 7196058..82ddfd9 100644 --- a/Docker-AIO/docker-compose.yml +++ b/Docker-AIO/docker-compose.yml @@ -1,7 +1,12 @@ # Docwell all-in-one container. # PB_ADMIN_PASSWORD=... docker compose up -d # released image # PB_ADMIN_PASSWORD=... docker compose up --build # or build from this checkout +# Or cp .env.example .env, edit it, and drop the PB_ADMIN_PASSWORD=... prefix. # Open http://localhost:3000 (admin panel: http://localhost:3000/admin/) +# +# Uploaded files stay on the pb_data volume. For S3: docker-compose.s3.yml +# (a bucket elsewhere), docker-compose.seaweedfs.yml (SeaweedFS beside this +# container) or docker-compose.seaweedfs.split.yml (the same, with its admin UI). name: docwell-aio @@ -15,8 +20,14 @@ services: environment: PB_ADMIN_EMAIL: ${PB_ADMIN_EMAIL:-admin@docwell.test} PB_ADMIN_PASSWORD: ${PB_ADMIN_PASSWORD:?set PB_ADMIN_PASSWORD} - # Links in auth emails point here. + # Optional settings encryption: exactly 32 characters, blank = off. + PB_ENCRYPTION_KEY: ${PB_ENCRYPTION_KEY:-} + # Links in auth emails and share links point here. DOCWELL_WEB_URL: ${DOCWELL_WEB_URL:-http://localhost:3000} + DOCWELL_PUBLIC_URL: ${DOCWELL_WEB_URL:-http://localhost:3000} + DOCWELL_CORS_ORIGINS: ${DOCWELL_WEB_URL:-http://localhost:3000} + DOCWELL_APP_NAME: ${DOCWELL_APP_NAME:-} + DOCWELL_DRAWIO_URL: ${DOCWELL_DRAWIO_URL:-} DOCWELL_SIGNUP_ENABLED: ${DOCWELL_SIGNUP_ENABLED:-true} # Optional: creates the first account as superadmin while there are no accounts. DOCWELL_ADMIN_EMAIL: ${DOCWELL_ADMIN_EMAIL:-} @@ -24,6 +35,7 @@ services: DOCWELL_ADMIN_NAME: ${DOCWELL_ADMIN_NAME:-} DOCWELL_SIGNUP_DOMAINS: ${DOCWELL_SIGNUP_DOMAINS:-} DOCWELL_MAX_UPLOAD_MB: ${DOCWELL_MAX_UPLOAD_MB:-50} + DOCWELL_AUDIT_RETENTION_DAYS: ${DOCWELL_AUDIT_RETENTION_DAYS:-} DOCWELL_SMTP_HOST: ${DOCWELL_SMTP_HOST:-} DOCWELL_SMTP_PORT: ${DOCWELL_SMTP_PORT:-587} DOCWELL_SMTP_USERNAME: ${DOCWELL_SMTP_USERNAME:-} @@ -31,10 +43,10 @@ services: DOCWELL_SMTP_TLS: ${DOCWELL_SMTP_TLS:-false} DOCWELL_MAIL_FROM: ${DOCWELL_MAIL_FROM:-no-reply@docwell.localhost} volumes: - - pb_data:/pb_data - - server_data:/data + - ${PB_DATA:-pb_data}:/pb_data + - ${SERVER_DATA:-server_data}:/data ports: - - "3000:3000" + - "${WEB_BIND:-0.0.0.0}:${WEB_PORT:-3000}:3000" volumes: pb_data: diff --git a/Docker-AIO/start-seaweedfs-split.sh b/Docker-AIO/start-seaweedfs-split.sh new file mode 100644 index 0000000..460ce13 --- /dev/null +++ b/Docker-AIO/start-seaweedfs-split.sh @@ -0,0 +1,99 @@ +#!/bin/sh +# SPDX-License-Identifier: AGPL-3.0-or-later +# Entrypoint of Dockerfile.seaweedfs.split: starts SeaweedFS as separate +# processes (master, volume, filer, S3 gateway and the admin UI), seeds the +# bucket and PocketBase's identity, then hands over to start.sh, which runs +# PocketBase, docwell-server and docwell-web and watches every SeaweedFS +# process with them. +set -eu + +: "${DOCWELL_S3_ACCESS_KEY:?DOCWELL_S3_ACCESS_KEY is required}" +: "${DOCWELL_S3_SECRET:?DOCWELL_S3_SECRET is required}" +# weed turns the admin UI's login off when the password is empty, and a panel +# that can mint keys for the bucket is the bucket. +: "${WEED_ADMIN_PASSWORD:?WEED_ADMIN_PASSWORD is required; refusing to serve an unauthenticated SeaweedFS admin UI}" +BUCKET="${DOCWELL_S3_BUCKET:-docwell}" +PIDS="" + +# wait_for URL NAME PID: until URL answers; gives up when PID dies or after 60s. +wait_for() { + i=0 + until wget -qO- "$1" >/dev/null 2>&1; do + kill -0 "$3" 2>/dev/null || { echo "$2 exited during startup" >&2; exit 1; } + i=$((i + 1)) + [ "$i" -gt 120 ] && echo "$2 did not start" >&2 && exit 1 + sleep 0.5 + done +} + +# Stop what already runs if the seed or a later role fails, so the container +# exits as a whole and its restart policy starts it over. +# shellcheck disable=SC2086 # PIDS is a list +trap 'kill $PIDS 2>/dev/null || true' EXIT + +# Every role binds and advertises 127.0.0.1: they only talk to each other and +# to PocketBase, in this container, and the volume server serves file content +# by id with no authentication. Only the admin UI listens on all interfaces, +# so that it can be published. Master, volume and filer share /seaweed/data, +# the layout `weed server -dir` writes, so the volume moves between this image +# and Dockerfile.seaweedfs unchanged. + +# Master: volume topology and file ids. +weed master -ip=127.0.0.1 -ip.bind=127.0.0.1 -port=9333 -mdir=/seaweed/data \ + -volumeSizeLimitMB=1024 -metricsPort=9324 & +MASTER_PID=$! +PIDS="$PIDS $MASTER_PID" +wait_for http://127.0.0.1:9333/cluster/status "SeaweedFS master" "$MASTER_PID" + +# Volume server: where the bytes land. On 8081 because 8080 is docwell-server. +# -max=0 sizes it from free disk instead of the default cap of 8 volumes. +weed volume -master=127.0.0.1:9333 -ip=127.0.0.1 -ip.bind=127.0.0.1 -port=8081 \ + -dir=/seaweed/data -max=0 -metricsPort=9325 & +VOLUME_PID=$! +PIDS="$PIDS $VOLUME_PID" +wait_for http://127.0.0.1:8081/healthz "SeaweedFS volume server" "$VOLUME_PID" + +# Filer: the directory tree (buckets, object keys) and the IAM store the S3 +# identities live in. -defaultStoreDir keeps its leveldb on the data volume. +weed filer -master=127.0.0.1:9333 -ip=127.0.0.1 -ip.bind=127.0.0.1 -port=8888 \ + -defaultStoreDir=/seaweed/data -metricsPort=9326 & +FILER_PID=$! +PIDS="$PIDS $FILER_PID" +wait_for http://127.0.0.1:8888/healthz "SeaweedFS filer" "$FILER_PID" + +# Seed, before the gateway serves: create the bucket and write PocketBase's +# identity into the filer's IAM store, the store the admin UI edits. +# Env-var credentials would be silently displaced by the first user added in +# the panel, locking PocketBase out. Both commands update in place, so every +# boot re-applies the environment, which is also how a rotated +# DOCWELL_S3_SECRET arrives. weed shell reads them from stdin, so the secret +# stays off argv. +shell() { weed shell -master=127.0.0.1:9333 -filer=127.0.0.1:8888; } +printf '%s\n' \ + "s3.bucket.create -name $BUCKET" \ + "s3.configure -user docwell -access_key $DOCWELL_S3_ACCESS_KEY -secret_key $DOCWELL_S3_SECRET -actions Admin -apply" \ + | shell +# The gate: with an empty IAM store the gateway would allow anyone. +if ! echo "s3.configure" | shell | grep -qF "$DOCWELL_S3_ACCESS_KEY"; then + echo "PocketBase's identity is not in the SeaweedFS IAM store; refusing to start the gateway" >&2 + exit 1 +fi + +# S3 gateway: PocketBase's endpoint. No -config file: credentials come from the +# filer's IAM store, so the admin UI adds and revokes keys without a restart. +weed s3 -filer=127.0.0.1:8888 -ip.bind=127.0.0.1 -port=8333 -metricsPort=9327 & +S3_PID=$! +PIDS="$PIDS $S3_PID" +wait_for http://127.0.0.1:8333/healthz "SeaweedFS S3 gateway" "$S3_PID" + +# Admin UI: cluster view, buckets, maintenance, and Object Store -> Users. +# Reads WEED_ADMIN_USER / WEED_ADMIN_PASSWORD (and the optional READONLY pair) +# from the environment, which keeps them off the command line. +weed admin -port=23646 -master=127.0.0.1:9333 -dataDir=/seaweed/admin \ + -metricsPort=9328 & +ADMIN_PID=$! +PIDS="$PIDS $ADMIN_PID" + +trap - EXIT +# shellcheck disable=SC2086 +AIO_EXTRA_PIDS="$PIDS" exec /start.sh diff --git a/Docker-AIO/start-seaweedfs.sh b/Docker-AIO/start-seaweedfs.sh new file mode 100644 index 0000000..9f62556 --- /dev/null +++ b/Docker-AIO/start-seaweedfs.sh @@ -0,0 +1,49 @@ +#!/bin/sh +# SPDX-License-Identifier: AGPL-3.0-or-later +# Entrypoint of Dockerfile.seaweedfs: starts SeaweedFS as one `weed server -s3` +# process (master, volume, filer and S3 gateway), creates the bucket, then +# hands over to start.sh, which runs PocketBase, docwell-server and docwell-web +# and watches the weed process with them. +set -eu + +# The gateway's single identity, and the pair PocketBase signs in with. No +# safe defaults: without them the gateway would allow anyone. +: "${DOCWELL_S3_ACCESS_KEY:?DOCWELL_S3_ACCESS_KEY is required; refusing to start an unauthenticated gateway}" +: "${DOCWELL_S3_SECRET:?DOCWELL_S3_SECRET is required; refusing to start an unauthenticated gateway}" +BUCKET="${DOCWELL_S3_BUCKET:-docwell}" + +# wait_for URL NAME PID: until URL answers; gives up when PID dies or after 60s. +wait_for() { + i=0 + until wget -qO- "$1" >/dev/null 2>&1; do + kill -0 "$3" 2>/dev/null || { echo "$2 exited during startup" >&2; exit 1; } + i=$((i + 1)) + [ "$i" -gt 120 ] && echo "$2 did not start" >&2 && exit 1 + sleep 0.5 + done +} + +# SeaweedFS reads AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY when it starts +# without an -s3.config file, and one identity is what takes the gateway out of +# its allow-anyone default. Set for weed only, not for the processes after it. +# +# Every role binds and advertises 127.0.0.1: only PocketBase, in this +# container, talks to them, and the volume server serves file content by id +# with no authentication. The volume server is on 8081 because 8080 is +# docwell-server here. +AWS_ACCESS_KEY_ID="$DOCWELL_S3_ACCESS_KEY" \ +AWS_SECRET_ACCESS_KEY="$DOCWELL_S3_SECRET" \ + weed server -dir=/seaweed/data -ip=127.0.0.1 -ip.bind=127.0.0.1 \ + -volume.port=8081 -s3 -s3.port=8333 -master.volumeSizeLimitMB=1024 & +WEED_PID=$! + +wait_for http://127.0.0.1:9333/cluster/status "SeaweedFS master" "$WEED_PID" +wait_for http://127.0.0.1:8333/healthz "SeaweedFS S3 gateway" "$WEED_PID" + +# PocketBase never creates a bucket and SeaweedFS does not make one on first +# upload. Creating one that exists is a no-op; `|| true` keeps a hiccup here +# from blocking a restart (the admin panel's "Test the saved bucket" reports a +# missing bucket). +echo "s3.bucket.create -name $BUCKET" | weed shell -master=127.0.0.1:9333 || true + +AIO_EXTRA_PIDS="$WEED_PID" exec /start.sh diff --git a/Docker-AIO/start.sh b/Docker-AIO/start.sh index 0b7b80f..6d3e013 100644 --- a/Docker-AIO/start.sh +++ b/Docker-AIO/start.sh @@ -44,11 +44,25 @@ SERVER_PID=$! DOCWELL_WEB_ADDR=0.0.0.0:3000 DOCWELL_PROXY_TARGET=http://127.0.0.1:8080 docwell-web & WEB_PID=$! -trap 'kill $WEB_PID $SERVER_PID $PB_PID 2>/dev/null' INT TERM +# Processes a wrapper started before exec'ing this script (the SeaweedFS +# roles in Dockerfile.seaweedfs and Dockerfile.seaweedfs.split). exec keeps +# them children of this shell, so they are watched and stopped with the rest. +EXTRA_PIDS="${AIO_EXTRA_PIDS:-}" + +# shellcheck disable=SC2086 # the PID lists are meant to split +trap 'kill $WEB_PID $SERVER_PID $PB_PID $EXTRA_PIDS 2>/dev/null' INT TERM + +all_alive() { + for pid in "$@"; do + kill -0 "$pid" || return 1 + done +} # Exit as soon as any process dies so the container restarts as a whole. -while kill -0 $PB_PID && kill -0 $SERVER_PID && kill -0 $WEB_PID; do +# shellcheck disable=SC2086 +while all_alive $PB_PID $SERVER_PID $WEB_PID $EXTRA_PIDS; do sleep 2 done 2>/dev/null -kill $WEB_PID $SERVER_PID $PB_PID 2>/dev/null || true +# shellcheck disable=SC2086 +kill $WEB_PID $SERVER_PID $PB_PID $EXTRA_PIDS 2>/dev/null || true exit 1