-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-init.sh
More file actions
executable file
·149 lines (128 loc) · 5.64 KB
/
docker-init.sh
File metadata and controls
executable file
·149 lines (128 loc) · 5.64 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
#!/bin/bash
# JudgeFinder Docker Quick Start Script
# This script initializes the local Docker development environment
set -e
# Colors
BLUE='\033[0;34m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
echo -e "${BLUE}╔════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ JudgeFinder Docker Quick Start ║${NC}"
echo -e "${BLUE}╔════════════════════════════════════════╗${NC}"
echo ""
# Check if Docker is running
if ! docker info > /dev/null 2>&1; then
echo -e "${RED}Error: Docker is not running.${NC}"
echo "Please start Docker Desktop and try again."
exit 1
fi
echo -e "${GREEN}✓ Docker is running${NC}"
# Check if .env.docker.local exists
if [ ! -f .env.docker.local ]; then
echo -e "${YELLOW}Creating .env.docker.local from template...${NC}"
cp .env.docker .env.docker.local
# Generate secure passwords
POSTGRES_PASS=$(openssl rand -base64 24)
JWT_SECRET=$(openssl rand -base64 32)
DASHBOARD_PASS=$(openssl rand -base64 16)
# Update the env file with generated secrets (macOS/Linux compatible)
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
sed -i '' "s/POSTGRES_PASSWORD=.*/POSTGRES_PASSWORD=${POSTGRES_PASS}/" .env.docker.local
sed -i '' "s/JWT_SECRET=.*/JWT_SECRET=${JWT_SECRET}/" .env.docker.local
sed -i '' "s/DASHBOARD_PASSWORD=.*/DASHBOARD_PASSWORD=${DASHBOARD_PASS}/" .env.docker.local
else
# Linux
sed -i "s/POSTGRES_PASSWORD=.*/POSTGRES_PASSWORD=${POSTGRES_PASS}/" .env.docker.local
sed -i "s/JWT_SECRET=.*/JWT_SECRET=${JWT_SECRET}/" .env.docker.local
sed -i "s/DASHBOARD_PASSWORD=.*/DASHBOARD_PASSWORD=${DASHBOARD_PASS}/" .env.docker.local
fi
echo -e "${GREEN}✓ Generated secure passwords in .env.docker.local${NC}"
echo -e "${YELLOW} Dashboard password: ${DASHBOARD_PASS}${NC}"
else
echo -e "${YELLOW}! .env.docker.local already exists${NC}"
fi
# Check if kong.yml exists
if [ ! -f supabase/config/kong.yml ]; then
echo -e "${RED}Error: supabase/config/kong.yml not found${NC}"
echo "Please ensure all config files are present."
exit 1
fi
echo -e "${GREEN}✓ Configuration files present${NC}"
# Start Docker services
echo ""
echo -e "${BLUE}Starting Docker services...${NC}"
docker-compose --env-file .env.docker.local up -d
# Wait for services to be healthy
echo -e "${BLUE}Waiting for services to be healthy...${NC}"
sleep 10
# Check if database is ready
MAX_RETRIES=30
RETRY_COUNT=0
while ! docker exec supabase-db pg_isready -U postgres > /dev/null 2>&1; do
RETRY_COUNT=$((RETRY_COUNT + 1))
if [ $RETRY_COUNT -gt $MAX_RETRIES ]; then
echo -e "${RED}Error: Database failed to start${NC}"
echo "Run: docker-compose logs db"
exit 1
fi
echo -e "${YELLOW}Waiting for database... ($RETRY_COUNT/$MAX_RETRIES)${NC}"
sleep 2
done
echo -e "${GREEN}✓ Database is ready${NC}"
# Apply migrations if they exist
if [ -d supabase/migrations ] && [ "$(ls -A supabase/migrations)" ]; then
echo -e "${BLUE}Applying database migrations...${NC}"
# Count SQL migration files
MIGRATION_COUNT=$(find supabase/migrations -name "*.sql" -type f | wc -l)
if [ "$MIGRATION_COUNT" -gt 0 ]; then
echo -e "${YELLOW}Found $MIGRATION_COUNT migration files${NC}"
# Check if Supabase CLI is available
if command -v supabase &> /dev/null; then
echo -e "${BLUE}Using Supabase CLI to apply migrations...${NC}"
npx supabase db push 2>&1 || echo -e "${YELLOW}Note: Some migrations may have already been applied${NC}"
else
echo -e "${YELLOW}Supabase CLI not found. Migrations will be auto-applied on first connection.${NC}"
fi
else
echo -e "${YELLOW}No migration files found${NC}"
fi
else
echo -e "${YELLOW}No migrations directory found${NC}"
fi
echo ""
echo -e "${GREEN}╔════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ Setup Complete! ║${NC}"
echo -e "${GREEN}╚════════════════════════════════════════╝${NC}"
echo ""
echo -e "${BLUE}Services are now running:${NC}"
echo -e " ${GREEN}Supabase Studio:${NC} http://localhost:54323"
echo -e " ${GREEN}API Gateway:${NC} http://localhost:54321"
echo -e " ${GREEN}PostgreSQL:${NC} localhost:54322"
echo -e " ${GREEN}Analytics:${NC} http://localhost:54324"
echo ""
echo -e "${BLUE}Dashboard Credentials:${NC}"
echo -e " ${GREEN}Username:${NC} supabase"
echo -e " ${GREEN}Password:${NC} (see .env.docker.local)"
echo ""
echo -e "${BLUE}Next Steps:${NC}"
echo -e " 1. Update your ${GREEN}.env.local${NC} to point to local Supabase:"
echo -e " ${YELLOW}NEXT_PUBLIC_SUPABASE_URL=http://localhost:54321${NC}"
echo ""
echo -e " 2. Start your Next.js app:"
echo -e " ${YELLOW}npm run dev${NC}"
echo ""
echo -e " 3. View logs:"
echo -e " ${YELLOW}docker-compose logs -f${NC}"
echo ""
echo -e "${BLUE}Useful Commands:${NC}"
echo -e " ${GREEN}make help${NC} - Show all available commands"
echo -e " ${GREEN}make docker-logs${NC} - View all service logs"
echo -e " ${GREEN}make db-connect${NC} - Connect to PostgreSQL"
echo -e " ${GREEN}make playwright-test${NC} - Run E2E tests"
echo -e " ${GREEN}make docker-down${NC} - Stop all services"
echo ""
echo -e "For more information, see ${GREEN}DOCKER_SETUP.md${NC}"
echo ""