Trying
soaricarus_api CI / Rustfmt (pull_request) Successful in 2m21s
soaricarus_api CI / Test Suite (pull_request) Successful in 3m55s
soaricarus_api CI / Check (pull_request) Successful in 4m15s
soaricarus_api CI / Clippy (pull_request) Successful in 4m22s
soaricarus_api CI / build (pull_request) Successful in 3m48s
soaricarus_api CI / Rustfmt (pull_request) Successful in 2m21s
soaricarus_api CI / Test Suite (pull_request) Successful in 3m55s
soaricarus_api CI / Check (pull_request) Successful in 4m15s
soaricarus_api CI / Clippy (pull_request) Successful in 4m22s
soaricarus_api CI / build (pull_request) Successful in 3m48s
This commit is contained in:
+7
-5
@@ -60,7 +60,9 @@ services:
|
|||||||
- soaricarus-network
|
- soaricarus-network
|
||||||
# --- storage service ---
|
# --- storage service ---
|
||||||
maze:
|
maze:
|
||||||
image: dxflrs/garage:v2.3.0
|
build:
|
||||||
|
context: ./garage
|
||||||
|
dockerfile: Dockerfile
|
||||||
container_name: maze
|
container_name: maze
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
@@ -81,13 +83,13 @@ services:
|
|||||||
- AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
|
- AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
|
||||||
- GARAGE_RPC_SECRET=${GARAGE_RPC_SECRET}
|
- GARAGE_RPC_SECRET=${GARAGE_RPC_SECRET}
|
||||||
- BUCKET_NAME=${S3_BUCKET_NAME}
|
- BUCKET_NAME=${S3_BUCKET_NAME}
|
||||||
entrypoint: ["/entrypoint.sh"]
|
# entrypoint: ["/entrypoint.sh"]
|
||||||
command: []
|
# command: []
|
||||||
healthcheck:
|
healthcheck:
|
||||||
# test: ["CMD-SHELL", "curl -f http://localhost:3901/v0/status || exit 1"]
|
test: ["CMD-SHELL", "curl -f http://localhost:3901/v0/status || exit 1"]
|
||||||
# test: ["CMD-SHELL", "echo 'What is to be done?'"]
|
# test: ["CMD-SHELL", "echo 'What is to be done?'"]
|
||||||
# test: ["CMD-SHELL", "nc -z localhost 3900 || exit 1"]
|
# test: ["CMD-SHELL", "nc -z localhost 3900 || exit 1"]
|
||||||
test: ["CMD-SHELL", "/garage status | grep -q 'Health: ok' || exit 1"]
|
# test: ["CMD-SHELL", "/garage status | grep -q 'Health: ok' || exit 1"]
|
||||||
interval: 10s
|
interval: 10s
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 5
|
retries: 5
|
||||||
|
|||||||
+13
-16
@@ -1,21 +1,18 @@
|
|||||||
# FROM dxflrs/garage:v2.3.0
|
# Use a base image with a shell (Alpine)
|
||||||
# Stage 1: Extract the garage binary from the official image
|
|
||||||
FROM dxflrs/garage:v2.3.0 as garage-base
|
|
||||||
|
|
||||||
# Stage 2: Create a new image with a shell
|
|
||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
|
|
||||||
# Install necessary tools (curl, busybox for sh, etc.)
|
# Install necessary tools
|
||||||
# The Garage image is based on Alpine, so we use apk
|
RUN apk add --no-cache curl
|
||||||
RUN apk add --no-cache curl busybox
|
|
||||||
|
|
||||||
# Copy the garage binary from the official image
|
# Copy the Garage binary from the official image
|
||||||
COPY --from=garage-base /garage /usr/local/bin/garage
|
COPY --from=dxflrs/garage:v2.3.0 /garage /usr/local/bin/garage
|
||||||
|
|
||||||
# Copy the init script
|
# Copy the entrypoint script
|
||||||
COPY init-garage.sh /init-garage.sh
|
COPY entrypoint.sh /entrypoint.sh
|
||||||
RUN chmod +x /init-garage.sh
|
RUN chmod +x /entrypoint.sh
|
||||||
|
|
||||||
# Use the init script as the entrypoint
|
# Set the entrypoint
|
||||||
# It will run setup, then exec garage
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
ENTRYPOINT ["/init-garage.sh"]
|
|
||||||
|
# Pass through any arguments to Garage
|
||||||
|
CMD []
|
||||||
|
|||||||
+79
-102
@@ -1,126 +1,103 @@
|
|||||||
#!/garage
|
#!/bin/sh
|
||||||
# This script runs as a garage command
|
set -e
|
||||||
# It will check if setup is needed and run initialization
|
|
||||||
|
|
||||||
# Check if we should run setup (first run)
|
|
||||||
SETUP_MARKER="/var/lib/garage/.setup_done"
|
|
||||||
BUCKET_NAME="${BUCKET_NAME:-soaricarus-storage}"
|
BUCKET_NAME="${BUCKET_NAME:-soaricarus-storage}"
|
||||||
CREDENTIALS_FILE="/shared/garage-credentials.env"
|
CREDENTIALS_FILE="/shared/garage-credentials.env"
|
||||||
|
SETUP_DONE="/shared/setup.done"
|
||||||
|
GARAGE_BIN="/usr/local/bin/garage"
|
||||||
|
|
||||||
# Function to check if Garage API is ready
|
# Function to write credentials
|
||||||
is_garage_ready() {
|
write_credentials() {
|
||||||
# Try to get status, if it works, Garage is ready
|
local access_key="$1"
|
||||||
/garage status 2>/dev/null | grep -q "Health: ok"
|
local secret_key="$2"
|
||||||
return $?
|
mkdir -p "$(dirname "$CREDENTIALS_FILE")"
|
||||||
|
cat > "$CREDENTIALS_FILE" << EOF
|
||||||
|
GARAGE_ACCESS_KEY_ID=$access_key
|
||||||
|
GARAGE_SECRET_ACCESS_KEY=$secret_key
|
||||||
|
GARAGE_BUCKET_NAME=$BUCKET_NAME
|
||||||
|
GARAGE_ENDPOINT=http://localhost:3900
|
||||||
|
EOF
|
||||||
|
touch "$SETUP_DONE"
|
||||||
|
echo "✅ Credentials saved to $CREDENTIALS_FILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to wait for Garage to be ready
|
# Check if setup already completed
|
||||||
wait_for_garage() {
|
if [ -f "$SETUP_DONE" ]; then
|
||||||
echo "⏳ Waiting for Garage to be ready..."
|
echo "ℹ️ Setup already completed. Starting Garage..."
|
||||||
local max_attempts=30
|
exec $GARAGE_BIN "$@"
|
||||||
local attempt=0
|
fi
|
||||||
while [ $attempt -lt $max_attempts ]; do
|
|
||||||
if is_garage_ready; then
|
echo "🔧 First-time setup - initializing Garage..."
|
||||||
echo "✅ Garage is ready!"
|
|
||||||
return 0
|
# Start Garage in background for setup (just the binary, no daemon subcommand)
|
||||||
fi
|
echo "⏳ Starting Garage in background..."
|
||||||
attempt=$((attempt + 1))
|
$GARAGE_BIN "$@" &
|
||||||
echo " Waiting... (attempt $attempt/$max_attempts)"
|
GARAGE_PID=$!
|
||||||
|
|
||||||
|
# Wait for Garage to be ready
|
||||||
|
echo "⏳ Waiting for Garage API..."
|
||||||
|
until curl -s -f "http://localhost:3901/v0/status" > /dev/null 2>&1; do
|
||||||
|
echo " Not ready yet, sleeping 2s..."
|
||||||
sleep 2
|
sleep 2
|
||||||
done
|
done
|
||||||
echo "❌ Garage failed to become ready"
|
echo "✅ Garage API is responding!"
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Function to run setup
|
# Apply cluster layout
|
||||||
run_setup() {
|
if ! $GARAGE_BIN layout show 2>/dev/null | grep -q "Current cluster layout"; then
|
||||||
echo "🔧 Running initial setup..."
|
echo "📦 Applying cluster layout..."
|
||||||
|
NODE_ID=$($GARAGE_BIN node id | head -n1)
|
||||||
# Get node ID
|
$GARAGE_BIN layout assign --version 1 "$NODE_ID"
|
||||||
NODE_ID=$(/garage node id | head -n1)
|
$GARAGE_BIN layout apply --version 1
|
||||||
echo " Node ID: $NODE_ID"
|
|
||||||
|
|
||||||
# Apply layout
|
|
||||||
/garage layout assign --version 1 "$NODE_ID"
|
|
||||||
/garage layout apply --version 1
|
|
||||||
echo " ✅ Layout applied"
|
echo " ✅ Layout applied"
|
||||||
sleep 3
|
sleep 2
|
||||||
|
else
|
||||||
|
echo "ℹ️ Layout already applied"
|
||||||
|
fi
|
||||||
|
|
||||||
# Create bucket
|
# Create bucket
|
||||||
if ! /garage bucket info "$BUCKET_NAME" 2>/dev/null; then
|
if ! $GARAGE_BIN bucket info "$BUCKET_NAME" 2>/dev/null; then
|
||||||
/garage bucket create "$BUCKET_NAME"
|
echo "📦 Creating bucket: $BUCKET_NAME"
|
||||||
echo " ✅ Bucket created: $BUCKET_NAME"
|
$GARAGE_BIN bucket create "$BUCKET_NAME"
|
||||||
else
|
else
|
||||||
echo " ℹ️ Bucket already exists"
|
echo "ℹ️ Bucket $BUCKET_NAME already exists"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Handle key
|
# Handle key
|
||||||
if [ -n "$AWS_ACCESS_KEY_ID" ] && [ -n "$AWS_SECRET_ACCESS_KEY" ]; then
|
if [ -n "$AWS_ACCESS_KEY_ID" ] && [ -n "$AWS_SECRET_ACCESS_KEY" ]; then
|
||||||
# Import existing key
|
echo "🔑 Using pre-defined credentials from .env"
|
||||||
if ! /garage key info "$AWS_ACCESS_KEY_ID" 2>/dev/null; then
|
if ! $GARAGE_BIN key info "$AWS_ACCESS_KEY_ID" 2>/dev/null; then
|
||||||
/garage key import "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY" "app-key"
|
$GARAGE_BIN key import "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY" "app-key"
|
||||||
echo " ✅ Key imported: $AWS_ACCESS_KEY_ID"
|
echo " ✅ Key imported: $AWS_ACCESS_KEY_ID"
|
||||||
else
|
else
|
||||||
echo " ℹ️ Key already exists: $AWS_ACCESS_KEY_ID"
|
echo " ℹ️ Key already exists: $AWS_ACCESS_KEY_ID"
|
||||||
fi
|
fi
|
||||||
ACCESS_KEY="$AWS_ACCESS_KEY_ID"
|
ACCESS_KEY="$AWS_ACCESS_KEY_ID"
|
||||||
SECRET_KEY="$AWS_SECRET_ACCESS_KEY"
|
SECRET_KEY="$AWS_SECRET_ACCESS_KEY"
|
||||||
else
|
else
|
||||||
# Generate new key
|
echo "🔑 Generating new key..."
|
||||||
KEY_OUTPUT=$(/garage key create --name "app-key")
|
KEY_OUTPUT=$($GARAGE_BIN key create --name "app-key")
|
||||||
echo "$KEY_OUTPUT"
|
echo "$KEY_OUTPUT"
|
||||||
ACCESS_KEY=$(echo "$KEY_OUTPUT" | grep 'Key ID:' | awk '{print $3}')
|
ACCESS_KEY=$(echo "$KEY_OUTPUT" | grep 'Key ID:' | awk '{print $3}')
|
||||||
SECRET_KEY=$(echo "$KEY_OUTPUT" | grep 'Secret key:' | awk '{print $3}')
|
SECRET_KEY=$(echo "$KEY_OUTPUT" | grep 'Secret key:' | awk '{print $3}')
|
||||||
echo " ✅ Key generated: $ACCESS_KEY"
|
echo " ✅ Key generated: $ACCESS_KEY"
|
||||||
fi
|
|
||||||
|
|
||||||
# Grant permissions
|
|
||||||
/garage bucket allow --read --write --owner "$BUCKET_NAME" --key "$ACCESS_KEY"
|
|
||||||
echo " ✅ Permissions granted"
|
|
||||||
|
|
||||||
# Write credentials to shared volume
|
|
||||||
mkdir -p "$(dirname "$CREDENTIALS_FILE")"
|
|
||||||
cat > "$CREDENTIALS_FILE" << EOF
|
|
||||||
GARAGE_ACCESS_KEY_ID=$ACCESS_KEY
|
|
||||||
GARAGE_SECRET_ACCESS_KEY=$SECRET_KEY
|
|
||||||
GARAGE_BUCKET_NAME=$BUCKET_NAME
|
|
||||||
GARAGE_ENDPOINT=http://maze:3900
|
|
||||||
EOF
|
|
||||||
echo " ✅ Credentials saved to $CREDENTIALS_FILE"
|
|
||||||
|
|
||||||
# Mark setup as done
|
|
||||||
touch "$SETUP_MARKER"
|
|
||||||
echo "🎉 Setup complete!"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Main execution
|
|
||||||
|
|
||||||
# Check if we need to run setup
|
|
||||||
if [ ! -f "$SETUP_MARKER" ]; then
|
|
||||||
echo "📦 First run detected. Starting Garage for setup..."
|
|
||||||
|
|
||||||
# Start Garage in background
|
|
||||||
/garage "$@" &
|
|
||||||
GARAGE_PID=$!
|
|
||||||
|
|
||||||
# Wait for it to be ready
|
|
||||||
if wait_for_garage; then
|
|
||||||
# Run the setup
|
|
||||||
run_setup
|
|
||||||
else
|
|
||||||
echo "❌ Setup failed - Garage didn't become ready"
|
|
||||||
kill "$GARAGE_PID" 2>/dev/null
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Kill the background Garage
|
|
||||||
echo "⏹️ Stopping background Garage..."
|
|
||||||
kill "$GARAGE_PID"
|
|
||||||
wait "$GARAGE_PID" 2>/dev/null || true
|
|
||||||
echo "🔄 Restarting Garage in foreground..."
|
|
||||||
else
|
|
||||||
echo "ℹ️ Setup already completed. Starting Garage..."
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Grant permissions
|
||||||
|
$GARAGE_BIN bucket allow --read --write --owner "$BUCKET_NAME" --key "$ACCESS_KEY"
|
||||||
|
echo " ✅ Permissions granted"
|
||||||
|
|
||||||
|
# Save credentials
|
||||||
|
write_credentials "$ACCESS_KEY" "$SECRET_KEY"
|
||||||
|
|
||||||
|
echo "🎉 Setup complete!"
|
||||||
|
echo " Bucket: $BUCKET_NAME"
|
||||||
|
echo " Access Key: $ACCESS_KEY"
|
||||||
|
|
||||||
|
# Stop background Garage
|
||||||
|
echo "⏹️ Stopping background Garage..."
|
||||||
|
kill "$GARAGE_PID"
|
||||||
|
wait "$GARAGE_PID" 2>/dev/null || true
|
||||||
|
|
||||||
# Start Garage in foreground
|
# Start Garage in foreground
|
||||||
exec /garage "$@"
|
echo "🚀 Starting Garage in foreground..."
|
||||||
|
exec $GARAGE_BIN "$@"
|
||||||
|
|||||||
Reference in New Issue
Block a user