added garage config for state management

This commit is contained in:
2026-02-23 23:55:43 +01:00
parent b29c73c404
commit 11149f762d
3 changed files with 86 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
services:
garaged:
image: dxflrs/garage:v2.2.0
restart: always
ports:
- "3900:3900"
- "3901:3901"
- "3902:3902"
- "3903:3903"
volumes:
- ./garage.toml:/etc/garage.toml
- ./meta:/var/lib/garage/meta
- ./data:/var/lib/garage/data

16
state/garage/garage.toml Normal file
View File

@@ -0,0 +1,16 @@
replication_factor = 1
consistency_mode = "consistent"
metadata_dir = "/var/lib/garage/meta"
data_dir = "/var/lib/garage/data"
db_engine = "lmdb"
rpc_secret = "09c4a7f218ef7a734a77bb9b4a7165b24ebe9f59b4e7d18e72f1ace5b8f0c7f3"
rpc_bind_addr = "[::]:3901"
[s3_api]
api_bind_addr = "[::]:3900"
s3_region = "garage"
[admin]
api_bind_addr = "0.0.0.0:3903"

57
state/garage/init.sh Executable file
View File

@@ -0,0 +1,57 @@
#!/bin/bash
### AI generated ###
set -euo pipefail
COMPOSE="docker compose"
GARAGE="$COMPOSE exec garaged /garage"
echo "Starting Garage..."
$COMPOSE up -d
echo "Waiting for Garage to be ready..."
until $GARAGE status >/dev/null 2>&1; do
sleep 1
done
# Get node ID from status output
NODE_ID=$($GARAGE status 2>/dev/null | grep -oP '^[a-f0-9]+')
if [ -z "$NODE_ID" ]; then
echo "ERROR: Could not determine node ID"
exit 1
fi
echo "Node ID: $NODE_ID"
# Assign layout (skip if already assigned)
if $GARAGE status 2>/dev/null | grep -q "NO ROLE ASSIGNED"; then
echo "Assigning layout..."
$GARAGE layout assign -z dc1 -c 1G "$NODE_ID"
$GARAGE layout apply --version 1
else
echo "Layout already assigned, skipping."
fi
# Create bucket (skip if exists)
if ! $GARAGE bucket info tofu-state >/dev/null 2>&1; then
echo "Creating bucket 'tofu-state'..."
$GARAGE bucket create tofu-state
else
echo "Bucket 'tofu-state' already exists, skipping."
fi
# Create key (skip if exists)
if ! $GARAGE key info tofu-key >/dev/null 2>&1; then
echo "Creating key 'tofu-key'..."
$GARAGE key create tofu-key
$GARAGE bucket allow tofu-state --read --write --key tofu-key
else
echo "Key 'tofu-key' already exists, skipping."
fi
echo ""
echo "=== Garage is ready ==="
echo ""
$GARAGE key info tofu-key