-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-docker.sh
More file actions
executable file
·237 lines (207 loc) · 7.39 KB
/
setup-docker.sh
File metadata and controls
executable file
·237 lines (207 loc) · 7.39 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
#!/bin/bash
# =============================================================================
# Design System Builder - Docker Setup Script (Development)
# =============================================================================
# This script performs a complete setup of the Design System Builder
# development environment including:
# - Building and starting all services (postgres-registry, db-service, admin, client, generator, docs-generator)
# - Running database migrations
# - Seeding initial data (seed-dev.ts)
# - Comprehensive health checks for all services
#
# Usage: ./setup-docker.sh
# =============================================================================
# Colors for better output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Helper functions
echo_success() {
echo -e "${GREEN}✅ $1${NC}"
}
echo_error() {
echo -e "${RED}❌ $1${NC}"
}
echo_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
echo_info() {
echo -e "${BLUE}ℹ️ $1${NC}"
}
echo_step() {
echo -e "${PURPLE}🔧 $1${NC}"
}
echo_header() {
echo -e "${CYAN}$1${NC}"
}
# Progress indicator
show_progress() {
local current=$1
local total=$2
local step=$3
local percent=$((current * 100 / total))
printf "\r${BLUE}Progress: [%3d%%] %s${NC}" $percent "$step"
}
COMPOSE_FILE="docker-compose.dev.yml"
echo_header "🐳 Design System Builder - Docker Setup (Development)"
echo "======================================================"
# Check if Docker is running
if ! docker info > /dev/null 2>&1; then
echo_error "Docker is not running. Please start Docker first."
exit 1
fi
echo_success "Docker is running"
# Check if docker-compose is available
if ! command -v docker-compose &> /dev/null; then
echo_error "docker-compose not found. Please install docker-compose."
exit 1
fi
echo_success "docker-compose is available"
echo ""
echo_header "🚀 Setting up development environment..."
echo " 📦 Services: postgres-registry, db-service, admin, client, generator, publisher, docs-generator"
echo " 🗄️ Database: migrations + seeding (dev seeds)"
echo " 🔍 Health checks: all services"
# Stop any existing containers
echo_step "Stopping existing containers..."
docker-compose -f $COMPOSE_FILE down -v
# Build and start services
echo_step "Building and starting services..."
if docker-compose -f $COMPOSE_FILE build; then
echo_success "Build successful"
else
echo_error "Build failed. Troubleshooting suggestions:"
echo " 1. Check internet connection: ping google.com"
echo " 2. Try disabling Docker proxy in Docker Desktop settings:"
echo " - Open Docker Desktop"
echo " - Go to Settings → Resources → Proxies"
echo " - Uncheck 'Manual proxy configuration'"
echo " - Apply & Restart Docker"
echo " 3. Restart Docker Desktop"
echo " 4. Check firewall settings"
echo " 5. Try using mobile hotspot temporarily"
echo ""
echo_info "Current Docker proxy settings:"
docker info | grep -E "(HTTP Proxy|HTTPS Proxy)" || echo " No proxy configured"
exit 1
fi
# Start only postgres + db-service first (migrate before other services connect)
echo_info "Starting postgres and db-service..."
docker-compose -f $COMPOSE_FILE up -d postgres-registry db-service
# Wait for PostgreSQL (db-service) to be ready
echo ""
echo_step "Waiting for PostgreSQL (db-service) to be ready..."
timeout=60
while ! docker-compose -f $COMPOSE_FILE exec -T postgres-registry pg_isready -U postgres -d ds_registry > /dev/null 2>&1; do
sleep 2
timeout=$((timeout - 2))
if [ $timeout -le 0 ]; then
echo_error "PostgreSQL (db-service) did not start in time"
exit 1
fi
done
echo_success "PostgreSQL (db-service) is ready"
# Database setup — run BEFORE other services start
echo ""
echo_header "🗄️ Setting up databases..."
# --- db-service migrations ---
echo_step "Running db-service migrations..."
if docker-compose -f $COMPOSE_FILE exec -T db-service npx drizzle-kit migrate; then
echo_success "db-service migrations completed"
else
echo_error "db-service migrations failed"
exit 1
fi
# --- Seeding ---
echo_step "Seeding db-service database (dev)..."
if docker-compose -f $COMPOSE_FILE exec -T db-service npx tsx src/db/seed-dev.ts; then
echo_success "db-service database seeding (dev) completed"
else
echo_error "db-service database seeding (dev) failed"
exit 1
fi
# Now start the remaining services (client, admin, generator, etc.)
echo_info "Starting remaining services..."
docker-compose -f $COMPOSE_FILE up -d
# Wait for frontend services to be ready
echo_step "Waiting for services to start..."
timeout=30
while ! curl -sf http://localhost:3002 > /dev/null 2>&1 || ! curl -sf http://localhost:3004 > /dev/null 2>&1; do
sleep 2
timeout=$((timeout - 2))
if [ $timeout -le 0 ]; then
break
fi
done
# Check final health
echo ""
echo_header "🔍 Final health check..."
services_healthy=true
total_services=4
current_service=0
# Check PostgreSQL (db-service)
current_service=$((current_service + 1))
show_progress $current_service $total_services "Checking PostgreSQL (db-service)..."
if docker-compose -f $COMPOSE_FILE exec -T postgres-registry pg_isready -U postgres -d ds_registry > /dev/null 2>&1; then
echo_success "PostgreSQL (db-service) is healthy"
else
echo_error "PostgreSQL (db-service) is not healthy"
services_healthy=false
fi
# Check DB Service
current_service=$((current_service + 1))
show_progress $current_service $total_services "Checking DB Service..."
if curl -sf http://localhost:3008/api/tables > /dev/null 2>&1; then
echo_success "DB Service is healthy"
else
echo_error "DB Service is not healthy"
services_healthy=false
fi
# Check Admin
current_service=$((current_service + 1))
show_progress $current_service $total_services "Checking Admin..."
if curl -f http://localhost:3004 > /dev/null 2>&1; then
echo_success "Admin is healthy"
else
echo_error "Admin is not healthy"
services_healthy=false
fi
# Check Client
current_service=$((current_service + 1))
show_progress $current_service $total_services "Checking Client..."
if curl -f http://localhost:3002 > /dev/null 2>&1; then
echo_success "Client is healthy"
else
echo_error "Client is not healthy"
services_healthy=false
fi
echo ""
if [ "$services_healthy" = true ]; then
echo_header "🎉 Setup completed successfully!"
echo ""
echo_header "📋 Service Information:"
echo " 🛠️ Admin: http://localhost:3004"
echo " 🎨 Client: http://localhost:3002"
echo " 📋 DB Service: http://localhost:3008"
echo " 🏗️ Generator: http://localhost:3005"
echo " 📄 Docs Generator: http://localhost:3006"
echo " 🗄️ DB (db-service): localhost:5433"
echo ""
echo_header "📦 View running services:"
docker-compose -f $COMPOSE_FILE ps
echo ""
echo_header "📝 Useful commands:"
echo " View logs: docker-compose -f $COMPOSE_FILE logs -f"
echo " Stop services: docker-compose -f $COMPOSE_FILE down"
echo " Restart: docker-compose -f $COMPOSE_FILE restart"
echo ""
echo_header "🎯 Test the CLI tool:"
echo " cd generate-ds && npm run dev 1 --dry-run"
else
echo_error "Setup completed with errors. Please check the service logs:"
echo " docker-compose -f $COMPOSE_FILE logs"
fi