From 11149f762dd6be75050f9a7dcb82086b3cfe04e3 Mon Sep 17 00:00:00 2001 From: Linus Waldowsky Date: Mon, 23 Feb 2026 23:55:43 +0100 Subject: [PATCH] added garage config for state management --- state/garage/docker-compose.yml | 13 ++++++++ state/garage/garage.toml | 16 +++++++++ state/garage/init.sh | 57 +++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 state/garage/docker-compose.yml create mode 100644 state/garage/garage.toml create mode 100755 state/garage/init.sh diff --git a/state/garage/docker-compose.yml b/state/garage/docker-compose.yml new file mode 100644 index 0000000..6d76a59 --- /dev/null +++ b/state/garage/docker-compose.yml @@ -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 diff --git a/state/garage/garage.toml b/state/garage/garage.toml new file mode 100644 index 0000000..d51880a --- /dev/null +++ b/state/garage/garage.toml @@ -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" diff --git a/state/garage/init.sh b/state/garage/init.sh new file mode 100755 index 0000000..0758198 --- /dev/null +++ b/state/garage/init.sh @@ -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