Files
Docwell/Docker-AIO/start-seaweedfs-split.sh
T
tajniak81andClaude Opus 5.5 f7a2ded680
CI / go (Media) (push) Successful in 13m22s
CI / go (Server) (push) Failing after 24m20s
CI / go (Web-App) (push) Successful in 14m3s
CI / frontend (push) Failing after 9m19s
CI / mobile (push) Failing after 6m19s
CI / docker (push) Successful in 20m37s
CI / desktop (ubuntu-latest) (push) Successful in 1h9m43s
CI / desktop (macos-latest) (push) Canceled after 0s
CI / desktop (windows-latest) (push) Canceled after 0s
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 <noreply@anthropic.com>
2026-11-18 19:29:46 +01:00

100 lines
4.5 KiB
Bash

#!/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