From 8fae71b08665b5084f9b5ada4fb0219dc56d182a Mon Sep 17 00:00:00 2001 From: phoenix Date: Thu, 23 Jul 2026 16:05:21 -0400 Subject: [PATCH] Getting somewhere. Object Storage is initialized but not initializing hangs --- Dockerfile | 4 ++ docker-compose.yaml | 22 +++++++++++ scripts/init-garage.sh | 85 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100755 scripts/init-garage.sh diff --git a/Dockerfile b/Dockerfile index 11cfe6b..0c2ac50 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,6 +30,10 @@ RUN --mount=type=ssh mkdir src && \ COPY src ./src COPY .env ./.env COPY migrations ./migrations +COPY scripts/init-garage.sh /scripts/init-garage.sh + +# Make it executable +RUN chmod +x /scripts/init-garage.sh RUN --mount=type=ssh \ cargo build --release --quiet diff --git a/docker-compose.yaml b/docker-compose.yaml index 951ef58..10eaefb 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -80,6 +80,28 @@ services: networks: - soaricarus-network + # --- Storage Initialization --- + maze-init: + # image: dxflrs/garage:v2.3.0 + image: alpine:latest + container_name: maze-init + depends_on: + maze: + condition: service_started + volumes: + - ./scripts:/scripts:ro + - object_data:/var/lib/garage + environment: + - AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} + - AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} + - GARAGE_RPC_SECRET=${GARAGE_RPC_SECRET} + env_file: + - .env + # entrypoint: ["/bin/bash"] + command: ["sh", "/scripts/init-garage.sh"] + restart: "no" # Run once and exit + networks: + - soaricarus-network # PostgreSQL Database Service main_db: diff --git a/scripts/init-garage.sh b/scripts/init-garage.sh new file mode 100755 index 0000000..87e399f --- /dev/null +++ b/scripts/init-garage.sh @@ -0,0 +1,85 @@ +#!/bin/bash +set -e + +# Use the credentials from your .env +BUCKET_NAME="soaricarus-storage" + +echo "âŗ Waiting for Garage to be ready..." +until curl -s -f "http://localhost:3901/v0/status" > /dev/null 2>&1; do + echo " Garage not ready yet, retrying in 2s..." + sleep 2 +done +echo "✅ Garage API is responding!" + +# Wait a bit more for Garage to fully initialize +sleep 5 + +# Check if layout is already applied +if garage layout show 2>/dev/null | grep -q "Current cluster layout"; then + echo "â„šī¸ Layout already applied, checking bucket..." +else + echo "đŸ“Ļ Applying cluster layout..." + + # Get node ID - this might need multiple attempts + MAX_RETRIES=10 + RETRY_COUNT=0 + while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do + NODE_ID=$(garage node id 2>/dev/null | head -n1) + if [ -n "$NODE_ID" ]; then + break + fi + RETRY_COUNT=$((RETRY_COUNT + 1)) + echo " Waiting for node ID (attempt $RETRY_COUNT/$MAX_RETRIES)..." + sleep 2 + done + + if [ -z "$NODE_ID" ]; then + echo "❌ Failed to get node ID after $MAX_RETRIES attempts" + exit 1 + fi + + echo " Node ID: $NODE_ID" + garage layout assign --version 1 "$NODE_ID" + garage layout apply --version 1 + echo " ✅ Layout applied" + + # Wait for layout to stabilize + sleep 3 +fi + +# Check if bucket already exists +if garage bucket info "${BUCKET_NAME}" 2>/dev/null; then + echo "â„šī¸ Bucket '${BUCKET_NAME}' already exists. Skipping setup." + exit 0 +fi + +echo "đŸ“Ļ Creating bucket and configuring permissions..." + +# 1. Create the bucket +garage bucket create "${BUCKET_NAME}" +echo " ✅ Bucket created: ${BUCKET_NAME}" + +# 2. Check if key exists +if garage key info "${AWS_ACCESS_KEY_ID}" 2>/dev/null; then + echo " â„šī¸ Key already exists: ${AWS_ACCESS_KEY_ID}" +else + garage key create \ + --name "app-key" \ + "${AWS_ACCESS_KEY_ID}" \ + "${AWS_SECRET_ACCESS_KEY}" + echo " ✅ Key created: ${AWS_ACCESS_KEY_ID}" +fi + +# 3. Grant full permissions +garage bucket allow \ + --read \ + --write \ + --owner \ + "${BUCKET_NAME}" \ + --key "${AWS_ACCESS_KEY_ID}" +echo " ✅ Permissions granted" + +echo "🎉 Setup complete!" +echo " Bucket: ${BUCKET_NAME}" +echo " Access Key: ${AWS_ACCESS_KEY_ID}" +echo " Endpoint: http://maze:3900"