-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·299 lines (263 loc) · 9.16 KB
/
Copy pathbootstrap.sh
File metadata and controls
executable file
·299 lines (263 loc) · 9.16 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#!/bin/bash
# RaidHub Services Bootstrap Script
# This script sets up the development environment and installs dependencies
# It is as idempotent as possible, so it can be run multiple times without issues
set -e
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " 🚀 RaidHub Services Bootstrap"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
# Function to detect OS
detect_os() {
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "macos"
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
echo "linux"
else
echo "unknown"
fi
}
# Function to install Go
install_go() {
local os=$(detect_os)
echo "📦 Installing Go..."
if [[ "$os" == "macos" ]]; then
if command -v brew &> /dev/null; then
brew install go
else
echo "❌ Homebrew not found. Please install Go manually from https://golang.org/dl/"
exit 1
fi
elif [[ "$os" == "linux" ]]; then
# Try package manager first
if command -v apt-get &> /dev/null; then
sudo apt-get update && sudo apt-get install -y golang-go
elif command -v yum &> /dev/null; then
sudo yum install -y golang
elif command -v dnf &> /dev/null; then
sudo dnf install -y golang
else
echo "❌ Package manager not found. Please install Go manually from https://golang.org/dl/"
exit 1
fi
else
echo "❌ Unsupported OS. Please install Go manually from https://golang.org/dl/"
exit 1
fi
echo "✅ Go installed"
}
# Function to install Docker
install_docker() {
local os=$(detect_os)
echo "📦 Installing Docker..."
if [[ "$os" == "macos" ]]; then
if command -v brew &> /dev/null; then
brew install --cask docker
echo "⚠️ Please start Docker Desktop manually after installation"
else
echo "❌ Homebrew not found. Please install Docker Desktop manually from https://www.docker.com/products/docker-desktop/"
exit 1
fi
elif [[ "$os" == "linux" ]]; then
# Install Docker using official script
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker $USER
rm get-docker.sh
echo "⚠️ Please log out and back in for Docker group changes to take effect"
else
echo "❌ Unsupported OS. Please install Docker manually from https://www.docker.com/products/docker-desktop/"
exit 1
fi
echo "✅ Docker installed"
}
# Function to install Tilt
install_tilt() {
echo "📦 Installing Tilt..."
curl -fsSL https://raw.githubusercontent.com/tilt-dev/tilt/master/scripts/install.sh | bash
echo "✅ Tilt installed"
}
# Setup .env file using make env
echo "📋 Setting up .env file..."
make env
echo ""
echo "📋 Checking dependencies..."
echo ""
# Check and install Go
if ! command -v go &> /dev/null; then
echo "❌ Go not found"
install_go
else
echo "✅ Go is installed"
fi
# Check and install Docker
if ! command -v docker &> /dev/null; then
echo "❌ Docker not found"
install_docker
else
echo "✅ Docker is installed"
fi
# Check if Docker is running
if ! docker info > /dev/null 2>&1; then
echo "❌ Docker is not running"
echo " On macOS: Start Docker Desktop"
echo " On Linux: sudo systemctl start docker"
exit 1
else
echo "✅ Docker is running"
fi
# Function to detect docker-compose command (standalone or plugin)
detect_docker_compose() {
if command -v docker-compose &> /dev/null; then
echo "docker-compose"
elif docker compose version > /dev/null 2>&1; then
echo "docker compose"
else
echo ""
fi
}
# Check for docker-compose (standalone or plugin)
DOCKER_COMPOSE_CMD=$(detect_docker_compose)
if [ -z "$DOCKER_COMPOSE_CMD" ]; then
echo "❌ docker-compose not found"
echo " Docker Compose V2 (plugin) is recommended: https://docs.docker.com/compose/install/"
echo " Or install standalone: https://docs.docker.com/compose/install/standalone/"
exit 1
else
echo "✅ docker-compose is available ($DOCKER_COMPOSE_CMD)"
fi
# Check and install Tilt
if ! command -v tilt &> /dev/null; then
echo "❌ Tilt not found"
install_tilt
else
echo "✅ Tilt is installed"
fi
# Create necessary directories
echo ""
echo "📁 Creating necessary directories..."
mkdir -p volumes logs bin
echo "✅ Directories created"
echo ""
# Configuration files are now static - no generation needed
echo "✅ Using static configuration files"
echo ""
# Stop any running services
echo "🛑 Stopping any running services..."
$DOCKER_COMPOSE_CMD down
echo "✅ Services stopped"
echo ""
# Start infrastructure services (postgres, clickhouse, rabbitmq, prometheus, loki, promtail, grafana)
# Exclude app services (atlas, hermes, zeus)
echo "🐳 Starting containerized infrastructure services..."
$DOCKER_COMPOSE_CMD --env-file ./.env up -d --force-recreate postgres rabbitmq clickhouse prometheus loki promtail grafana cron
echo "✅ Infrastructure services started"
echo ""
# Build app services (but don't start them)
echo "🔨 Building app services (atlas, hermes, zeus)..."
$DOCKER_COMPOSE_CMD --env-file ./.env build atlas hermes zeus
echo "✅ App services built (not started)"
echo "ℹ️ Apps (atlas, hermes, zeus) can be started with 'make dev' or manually."
echo ""
# Wait for databases to be ready
echo "⏳ Waiting for databases to be ready..."
max_attempts=30
attempt=0
# Wait for PostgreSQL
while [ $attempt -lt $max_attempts ]; do
if $DOCKER_COMPOSE_CMD --env-file ./.env exec -T postgres pg_isready -U dev > /dev/null 2>&1; then
echo "✅ PostgreSQL is ready"
break
fi
attempt=$((attempt + 1))
echo " Waiting for PostgreSQL... ($attempt/$max_attempts)"
sleep 2
done
echo ""
if [ $attempt -eq $max_attempts ]; then
echo "❌ PostgreSQL failed to start within $max_attempts attempts"
exit 1
fi
# Wait for ClickHouse
attempt=0
while [ $attempt -lt $max_attempts ]; do
# Check if container is running and ClickHouse is responding
if $DOCKER_COMPOSE_CMD --env-file ./.env ps clickhouse | grep -q "Up" && \
$DOCKER_COMPOSE_CMD --env-file ./.env exec -T clickhouse clickhouse-client --query "SELECT 1" > /dev/null 2>&1; then
echo "✅ ClickHouse is ready"
break
fi
attempt=$((attempt + 1))
echo " Waiting for ClickHouse... ($attempt/$max_attempts)"
sleep 2
done
echo ""
if [ $attempt -eq $max_attempts ]; then
echo "❌ ClickHouse failed to start within $max_attempts attempts"
exit 1
fi
# Run database migrations
echo ""
echo "🗄️ Running database migrations..."
if make migrate 2>&1; then
echo "✅ Migrations completed"
else
exit_code=$?
echo "❌ Migrations failed with exit code $exit_code"
fi
# Run database seeding
echo ""
echo "🌱 Seeding database..."
if make seed 2>&1; then
echo "✅ Seeding completed"
else
exit_code=$?
echo "⚠️ Seeding failed with exit code $exit_code (non-critical)"
fi
# Start zeus (needed for manifest downloader)
echo ""
echo "⚡ Starting Zeus API proxy (required for manifest downloader)..."
$DOCKER_COMPOSE_CMD --env-file ./.env up -d zeus
echo "✅ Zeus started"
echo ""
# Run manifest downloader to populate definitions
echo "🔮 Running manifest downloader to populate weapon and feat definitions..."
if go run ./tools/manifest-downloader -f; then
echo "✅ Manifest downloader completed"
else
exit_code=$?
echo "⚠️ Manifest downloader failed with exit code $exit_code (non-critical)"
fi
# Final summary
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🎉 Bootstrap complete!"
echo ""
echo "📚 How to run everything:"
echo ""
echo "🚀 Development (Recommended):"
echo " ▶️ Start all services: make dev (Tilt UI at http://localhost:10350)"
echo " This starts infrastructure + apps with hot reload"
echo " 🛑 Stop all services: make down"
echo ""
echo "🐳 Manual Docker Compose:"
echo " ▶️ Start crawler: make atlas-dev"
echo " ▶️ Start queue workers: make hermes-dev"
echo " ▶️ Start API-proxy: make zeus-dev"
echo " ▶️ Start cron UI: make cron-dev"
echo " ▶️ Start infrastructure: make infra"
echo " ▶️ Start everything: make up"
echo " 🛑 Stop everything: make down"
echo "🗄️ Database:"
echo " 🔄 Run migrations: make migrate"
echo " 🌱 Seed database: make seed"
echo ""
echo "🛠️ Investigation:"
echo " 📊 View logs: docker compose logs -f <service>"
echo " 📋 List services: docker compose ps"
echo " 🧹 Clean everything: make clean (removes volumes and data)"
echo ""
echo "⚠️ IMPORTANT: Set your BUNGIE_API_KEY in .env"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""