added garage config for state management
This commit is contained in:
57
state/garage/init.sh
Executable file
57
state/garage/init.sh
Executable 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
|
||||
Reference in New Issue
Block a user