-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·94 lines (79 loc) · 2.84 KB
/
bootstrap.sh
File metadata and controls
executable file
·94 lines (79 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/sh
# Bootstrap script for PROPS
# Starts Garage, waits for initialization, and populates .env with S3 credentials
set -e
ENV_FILE=".env"
COMPOSE_CMD="docker compose"
echo "=== PROPS Bootstrap ==="
# Check for .env file
if [ ! -f "$ENV_FILE" ]; then
echo "No .env file found. Creating from .env.example..."
cp .env.example "$ENV_FILE"
echo "Created $ENV_FILE - you may want to edit it after bootstrap completes."
fi
# Start garage and wait for init to complete
echo ""
echo "Starting Garage S3 storage and running initialization..."
$COMPOSE_CMD up -d garage-init
echo ""
echo "Waiting for garage-init to complete..."
if ! $COMPOSE_CMD wait garage-init; then
echo "ERROR: garage-init failed"
echo "Check logs with: $COMPOSE_CMD logs garage-init"
exit 1
fi
echo "Garage initialization complete!"
# Get credentials from garage
echo ""
echo "Fetching S3 credentials from Garage..."
KEY_INFO=$($COMPOSE_CMD exec garage /garage -c /etc/garage.toml key info assets-key --show-secret 2>/dev/null)
KEY_ID=$(echo "$KEY_INFO" | grep "Key ID:" | awk '{print $3}' | tr -d '\r')
SECRET_KEY=$(echo "$KEY_INFO" | grep "Secret key:" | awk '{print $3}' | tr -d '\r')
BUCKET_NAME="${S3_BUCKET_NAME:-assets}"
if [ -z "$KEY_ID" ] || [ -z "$SECRET_KEY" ]; then
echo "ERROR: Could not extract credentials from Garage"
echo "Key info output:"
echo "$KEY_INFO"
exit 1
fi
echo "Key ID: $KEY_ID"
echo "Secret Key: $(echo "$SECRET_KEY" | cut -c1-8)..."
echo "Bucket: $BUCKET_NAME"
# Update .env file with credentials
echo ""
echo "Updating $ENV_FILE with S3 credentials..."
update_env_var() {
VAR_NAME="$1"
VAR_VALUE="$2"
if grep -q "^${VAR_NAME}=" "$ENV_FILE" 2>/dev/null; then
# Replace existing value (works on both macOS and Linux)
if [ "$(uname)" = "Darwin" ]; then
sed -i '' "s|^${VAR_NAME}=.*|${VAR_NAME}=${VAR_VALUE}|" "$ENV_FILE"
else
sed -i "s|^${VAR_NAME}=.*|${VAR_NAME}=${VAR_VALUE}|" "$ENV_FILE"
fi
echo " Updated $VAR_NAME"
elif grep -q "^# *${VAR_NAME}=" "$ENV_FILE" 2>/dev/null; then
# Uncomment and set value
if [ "$(uname)" = "Darwin" ]; then
sed -i '' "s|^# *${VAR_NAME}=.*|${VAR_NAME}=${VAR_VALUE}|" "$ENV_FILE"
else
sed -i "s|^# *${VAR_NAME}=.*|${VAR_NAME}=${VAR_VALUE}|" "$ENV_FILE"
fi
echo " Uncommented and set $VAR_NAME"
else
# Append to file
echo "${VAR_NAME}=${VAR_VALUE}" >> "$ENV_FILE"
echo " Added $VAR_NAME"
fi
}
update_env_var "S3_ACCESS_KEY_ID" "$KEY_ID"
update_env_var "S3_SECRET_ACCESS_KEY" "$SECRET_KEY"
update_env_var "S3_BUCKET_NAME" "$BUCKET_NAME"
echo ""
echo "=== Bootstrap Complete ==="
echo ""
echo "Your .env file has been updated with S3 credentials."
echo "Start the full stack with:"
echo " docker compose --profile dev up -d"
echo ""