Saving changes. No real progress yet
soaricarus_api CI / Test Suite (pull_request) Successful in 3m36s
soaricarus_api CI / Check (pull_request) Successful in 4m3s
soaricarus_api CI / Rustfmt (pull_request) Successful in 5m49s
soaricarus_api CI / Clippy (pull_request) Successful in 2m24s
soaricarus_api CI / build (pull_request) Successful in 4m32s
soaricarus_api CI / Test Suite (pull_request) Successful in 3m36s
soaricarus_api CI / Check (pull_request) Successful in 4m3s
soaricarus_api CI / Rustfmt (pull_request) Successful in 5m49s
soaricarus_api CI / Clippy (pull_request) Successful in 2m24s
soaricarus_api CI / build (pull_request) Successful in 4m32s
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
# FROM dxflrs/garage:v2.3.0
|
||||
# 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
|
||||
|
||||
# Install necessary tools (curl, busybox for sh, etc.)
|
||||
# The Garage image is based on Alpine, so we use apk
|
||||
RUN apk add --no-cache curl busybox
|
||||
|
||||
# Copy the garage binary from the official image
|
||||
COPY --from=garage-base /garage /usr/local/bin/garage
|
||||
|
||||
# Copy the init script
|
||||
COPY init-garage.sh /init-garage.sh
|
||||
RUN chmod +x /init-garage.sh
|
||||
|
||||
# Use the init script as the entrypoint
|
||||
# It will run setup, then exec garage
|
||||
ENTRYPOINT ["/init-garage.sh"]
|
||||
@@ -0,0 +1,109 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
BUCKET_NAME="${BUCKET_NAME:-soaricarus-storage}"
|
||||
CREDENTIALS_FILE="/shared/garage-credentials.env"
|
||||
SETUP_DONE="/shared/setup.done"
|
||||
|
||||
# Function to write credentials to shared volume
|
||||
write_credentials() {
|
||||
local access_key="$1"
|
||||
local secret_key="$2"
|
||||
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
|
||||
touch "$SETUP_DONE"
|
||||
echo "✅ Credentials saved to $CREDENTIALS_FILE"
|
||||
}
|
||||
|
||||
# Check if setup already done
|
||||
if [ -f "$SETUP_DONE" ]; then
|
||||
echo "ℹ️ Setup already completed. Starting Garage..."
|
||||
# Source credentials if needed for the main Garage process
|
||||
# shellcheck source=/dev/null
|
||||
[ -f "$CREDENTIALS_FILE" ] && . "$CREDENTIALS_FILE"
|
||||
exec /usr/local/bin/garage "$@"
|
||||
fi
|
||||
|
||||
echo "🔧 Running initial setup..."
|
||||
|
||||
# Start Garage in background for setup
|
||||
echo "⏳ Starting Garage in background..."
|
||||
/usr/local/bin/garage "$@" &
|
||||
GARAGE_PID=$!
|
||||
|
||||
# Wait for Garage API to be ready
|
||||
echo "⏳ Waiting for Garage API..."
|
||||
# until curl -s -f "http://localhost:3900/v0/status" > /dev/null 2>&1; do
|
||||
# echo " Not ready yet, sleeping 2s..."
|
||||
# sleep 2
|
||||
#done
|
||||
echo "✅ Garage API is responding!"
|
||||
|
||||
# Apply layout if not already applied
|
||||
if ! /usr/local/bin/garage layout show 2>/dev/null | grep -q "Current cluster layout"; then
|
||||
echo "📦 Applying cluster layout..."
|
||||
NODE_ID=$(/usr/local/bin/garage node id | head -n1)
|
||||
/usr/local/bin/garage layout assign --version 1 "$NODE_ID"
|
||||
/usr/local/bin/garage layout apply --version 1
|
||||
echo " ✅ Layout applied"
|
||||
sleep 3
|
||||
else
|
||||
echo "ℹ️ Layout already applied"
|
||||
fi
|
||||
|
||||
echo "Laid out"
|
||||
|
||||
# Create bucket if it doesn't exist
|
||||
if ! /usr/local/bin/garage bucket info "$BUCKET_NAME" 2>/dev/null; then
|
||||
echo "📦 Creating bucket: $BUCKET_NAME"
|
||||
/usr/local/bin/garage bucket create "$BUCKET_NAME"
|
||||
else
|
||||
echo "ℹ️ Bucket $BUCKET_NAME already exists"
|
||||
fi
|
||||
|
||||
# Create or import key
|
||||
# We'll use the credentials from .env if provided, otherwise generate new ones
|
||||
if [ -n "$AWS_ACCESS_KEY_ID" ] && [ -n "$AWS_SECRET_ACCESS_KEY" ]; then
|
||||
echo "🔑 Using pre-defined AWS credentials from .env"
|
||||
if ! /usr/local/bin/garage key info "$AWS_ACCESS_KEY_ID" 2>/dev/null; then
|
||||
# Key doesn't exist, import it
|
||||
/usr/local/bin/garage key import "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY" "app-key"
|
||||
echo " ✅ Key imported: $AWS_ACCESS_KEY_ID"
|
||||
else
|
||||
echo " ℹ️ Key already exists: $AWS_ACCESS_KEY_ID"
|
||||
fi
|
||||
ACCESS_KEY="$AWS_ACCESS_KEY_ID"
|
||||
SECRET_KEY="$AWS_SECRET_ACCESS_KEY"
|
||||
else
|
||||
echo "🔑 Generating new key..."
|
||||
KEY_OUTPUT=$(/usr/local/bin/garage key create --name "app-key")
|
||||
echo "$KEY_OUTPUT"
|
||||
ACCESS_KEY=$(echo "$KEY_OUTPUT" | grep 'Key ID:' | awk '{print $3}')
|
||||
SECRET_KEY=$(echo "$KEY_OUTPUT" | grep 'Secret key:' | awk '{print $3}')
|
||||
echo " ✅ Key generated: $ACCESS_KEY"
|
||||
fi
|
||||
|
||||
# Grant permissions
|
||||
/usr/local/bin/garage bucket allow --read --write --owner "$BUCKET_NAME" --key "$ACCESS_KEY"
|
||||
echo " ✅ Permissions granted"
|
||||
|
||||
# Write credentials to shared volume
|
||||
write_credentials "$ACCESS_KEY" "$SECRET_KEY"
|
||||
|
||||
echo "🎉 Setup complete!"
|
||||
echo " Bucket: $BUCKET_NAME"
|
||||
echo " Access Key: $ACCESS_KEY"
|
||||
|
||||
# Stop the background Garage process
|
||||
echo "⏹️ Stopping background Garage process..."
|
||||
kill "$GARAGE_PID"
|
||||
wait "$GARAGE_PID" 2>/dev/null || true
|
||||
|
||||
echo "🚀 Starting Garage in foreground..."
|
||||
exec /usr/local/bin/garage "$@"
|
||||
|
||||
Executable
+36
@@ -0,0 +1,36 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
BUCKET_NAME="${BUCKET_NAME:-soaricarus-storage}"
|
||||
CREDENTIALS_FILE="/shared/garage-credentials.env"
|
||||
SETUP_DONE="/shared/setup.done"
|
||||
|
||||
echo "🔧 Running initial setup..."
|
||||
|
||||
# Start Garage in background for setup
|
||||
echo "⏳ Starting Garage in background..."
|
||||
/usr/local/bin/garage "$@" &
|
||||
GARAGE_PID=$!
|
||||
|
||||
# Wait for Garage API to be ready
|
||||
echo "⏳ Waiting for Garage API..."
|
||||
# until curl -s -f "http://localhost:3900/v0/status" > /dev/null 2>&1; do
|
||||
# echo " Not ready yet, sleeping 2s..."
|
||||
# sleep 2
|
||||
#done
|
||||
echo "✅ Garage API is responding!"
|
||||
|
||||
# Apply layout if not already applied
|
||||
#if ! /usr/local/bin/garage layout show 2>/dev/null | grep -q "Current cluster layout"; then
|
||||
# echo "📦 Applying cluster layout..."
|
||||
# NODE_ID=$(/usr/local/bin/garage node id | head -n1)
|
||||
# echo $NODE_ID
|
||||
# /usr/local/bin/garage layout assign --version 1 "$NODE_ID"
|
||||
# /usr/local/bin/garage layout apply --version 1
|
||||
# echo " ✅ Layout applied"
|
||||
# sleep 3
|
||||
#else
|
||||
# echo "ℹ️ Layout already applied"
|
||||
# fi
|
||||
|
||||
echo "Laid out"
|
||||
Reference in New Issue
Block a user