DocHub/storage/init-garage.sh
Tianyang 0f0b7e9d32 feat: add Garage as self-hosted S3-compatible storage, replacing MinIO
MinIO's community edition has been trimming features and its licensing
direction has grown less predictable. Garage (AGPL, purpose-built for
self-hosting) is a drop-in S3-compatible replacement — no changes needed
to backend/app/minio_client.py, which talks to the S3 API generically.

Deployed independently from the app stack (storage/docker-compose.yml),
same separation MinIO had. Single-node config (replication_factor = 1)
matching this project's learning/small-team scope. init-garage.sh handles
the one-time layout assignment + bucket creation Garage requires that
MinIO didn't (MinIO auto-creates buckets via API; Garage needs an
explicit `garage bucket create` step).
2026-08-01 09:43:08 +08:00

36 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# One-time Garage initialization: assigns this single node to the cluster
# layout, then creates the DocHub bucket and an access key for the backend.
#
# Run this once after `docker compose up -d` in this directory.
set -euo pipefail
GARAGE="docker compose exec garage /garage"
echo "Waiting for garage to be ready..."
until $GARAGE status >/dev/null 2>&1; do
sleep 1
done
NODE_ID=$($GARAGE status | awk '/NODE ID/{found=1; next} found && NF {print $1; exit}')
if [ -z "$NODE_ID" ]; then
echo "Could not determine node ID from 'garage status' output." >&2
exit 1
fi
echo "Assigning layout to node $NODE_ID (single node, capacity 10G)..."
$GARAGE layout assign -z dochub -c 10G "$NODE_ID"
$GARAGE layout apply --version 1
echo "Creating bucket 'dochub'..."
$GARAGE bucket create dochub
echo "Creating access key 'dochub-backend'..."
$GARAGE key create dochub-backend
$GARAGE bucket allow --read --write --owner dochub --key dochub-backend
echo
echo "Done. Run 'docker compose exec garage /garage key info dochub-backend'"
echo "to retrieve the access key ID and secret key, then set them as"
echo "MINIO_ACCESS_KEY / MINIO_SECRET_KEY for the DocHub backend."