@@ -7,24 +7,43 @@ services:
77 - postEnvironmentStart
88 commands :
99 start : |
10- # Force cleanup of any existing PostgreSQL containers
10+ cd /workspaces/gitpodflix-demo/database/main
11+
12+ # Clean up any existing containers that might conflict
1113 echo "Cleaning up any existing PostgreSQL containers..."
12- docker rm -f postgres 2>/dev/null || true
13- sleep 2 # Give Docker time to clean up
14-
15- echo "Starting PostgreSQL with Docker..."
16- docker run --rm \
17- --name postgres \
18- -e POSTGRES_USER=gitpod \
19- -e POSTGRES_PASSWORD=gitpod \
20- -e POSTGRES_DB=gitpodflix \
21- -p 5432:5432 \
22- -v postgres_data:/var/lib/postgresql/data \
23- -v /workspaces/gitpodflix-demo/database/main/migrations:/docker-entrypoint-initdb.d \
24- postgres:15
14+ docker stop main-postgres-1 2>/dev/null || true
15+ docker rm main-postgres-1 2>/dev/null || true
16+ docker stop postgres 2>/dev/null || true
17+ docker rm postgres 2>/dev/null || true
18+
19+ # Kill any process using port 5432
20+ if lsof -Pi :5432 -sTCP:LISTEN -t >/dev/null 2>&1; then
21+ echo "Killing process on port 5432..."
22+ kill -9 $(lsof -ti:5432) 2>/dev/null || true
23+ sleep 3
24+ fi
25+
26+ echo "Starting PostgreSQL with docker-compose..."
27+ docker-compose up -d
28+
29+ # Wait for container to be healthy
30+ echo "Waiting for PostgreSQL to be healthy..."
31+ for i in {1..30}; do
32+ if docker-compose ps | grep -q "healthy"; then
33+ echo "PostgreSQL container is healthy"
34+ break
35+ fi
36+ if [ $i -eq 30 ]; then
37+ echo "Timeout waiting for PostgreSQL to be healthy"
38+ docker-compose logs
39+ exit 1
40+ fi
41+ echo "Waiting... attempt $i/30"
42+ sleep 2
43+ done
2544
2645 ready : |
27- if docker exec postgres pg_isready -U gitpod; then
46+ if PGPASSWORD=gitpod psql -h localhost -U gitpod -d gitpodflix -c "SELECT 1" >/dev/null 2>&1 ; then
2847 echo "PostgreSQL is ready and accepting connections"
2948 exit 0
3049 else
@@ -33,10 +52,9 @@ services:
3352 fi
3453
3554 stop : |
36- echo "Stopping PostgreSQL container..."
37- docker stop postgres || true
38- echo "Removing PostgreSQL container..."
39- docker rm -f postgres || true
55+ cd /workspaces/gitpodflix-demo/database/main
56+ echo "Stopping PostgreSQL with docker-compose..."
57+ docker-compose down
4058
4159 catalog :
4260 name : " Catalog Service"
@@ -48,26 +66,47 @@ services:
4866 start : |
4967 cd /workspaces/gitpodflix-demo/backend/catalog
5068
69+ # Kill any existing process on port 3001
70+ if lsof -Pi :3001 -sTCP:LISTEN -t >/dev/null 2>&1; then
71+ echo "Killing existing process on port 3001..."
72+ kill -9 $(lsof -ti:3001) 2>/dev/null || true
73+ sleep 2
74+ fi
75+
76+ # Create .env file if it doesn't exist
77+ if [ ! -f .env ]; then
78+ echo "Creating .env file..."
79+ cat > .env << EOF
80+ DB_HOST=localhost
81+ DB_USER=gitpod
82+ DB_PASSWORD=gitpod
83+ DB_NAME=gitpodflix
84+ DB_PORT=5432
85+ PORT=3001
86+ EOF
87+ fi
88+
5189 # Ensure dependencies are installed
52- echo "Ensuring dependencies are installed ..."
90+ echo "Installing dependencies..."
5391 npm install
5492
55- # Wait for ts-node to be available
56- echo "Waiting for ts-node to be available ..."
57- for i in {1..30 }; do
58- if [ -f "node_modules/.bin/ts-node" ] ; then
59- echo "✓ ts-node is available "
93+ # Wait for PostgreSQL to be ready before starting
94+ echo "Waiting for PostgreSQL to be ready ..."
95+ for i in {1..60 }; do
96+ if PGPASSWORD=gitpod psql -h localhost -U gitpod -d gitpodflix -c "SELECT 1" >/dev/null 2>&1 ; then
97+ echo "✓ PostgreSQL is ready "
6098 break
6199 fi
62- if [ $i -eq 30 ]; then
63- echo "✗ Timeout waiting for ts-node "
100+ if [ $i -eq 60 ]; then
101+ echo "✗ Timeout waiting for PostgreSQL "
64102 exit 1
65103 fi
66- echo "Waiting for ts-node ... attempt $i/30 "
67- sleep 1
104+ echo "Waiting for PostgreSQL ... attempt $i/60 "
105+ sleep 2
68106 done
69107
70- PORT=3001 npm run dev
108+ echo "Starting catalog service..."
109+ npm run dev
71110 ready : |
72111 if curl -s http://localhost:3001/health > /dev/null; then
73112 echo "Catalog service is ready"
@@ -77,6 +116,9 @@ services:
77116 exit 1
78117 fi
79118 stop : |
119+ if lsof -Pi :3001 -sTCP:LISTEN -t >/dev/null 2>&1; then
120+ kill -9 $(lsof -ti:3001) 2>/dev/null || true
121+ fi
80122 pkill -f "node.*catalog" || true
81123
82124 gitpod-flix :
@@ -89,22 +131,34 @@ services:
89131 start : |
90132 cd /workspaces/gitpodflix-demo/frontend
91133
92- # Wait for vite to be available
93- echo "Waiting for vite to be available..."
94- for i in {1..30}; do
95- if command -v vite >/dev/null 2>&1 || [ -f "node_modules/.bin/vite" ]; then
96- echo "✓ vite is available"
134+ # Kill any existing process on port 3000
135+ if lsof -Pi :3000 -sTCP:LISTEN -t >/dev/null 2>&1; then
136+ echo "Killing existing process on port 3000..."
137+ kill -9 $(lsof -ti:3000) 2>/dev/null || true
138+ sleep 2
139+ fi
140+
141+ # Install dependencies
142+ echo "Installing frontend dependencies..."
143+ npm install
144+
145+ # Wait for backend to be ready before starting frontend
146+ echo "Waiting for backend API to be ready..."
147+ for i in {1..60}; do
148+ if curl -s http://localhost:3001/health >/dev/null 2>&1; then
149+ echo "✓ Backend API is ready"
97150 break
98151 fi
99- if [ $i -eq 30 ]; then
100- echo "✗ Timeout waiting for vite "
152+ if [ $i -eq 60 ]; then
153+ echo "✗ Timeout waiting for backend API "
101154 exit 1
102155 fi
103- echo "Waiting for vite ... attempt $i/30 "
156+ echo "Waiting for backend ... attempt $i/60 "
104157 sleep 2
105158 done
106159
107- PORT=3000 npm run dev
160+ echo "Starting frontend service..."
161+ npm run dev
108162 ready : |
109163 if curl -s http://localhost:3000 > /dev/null; then
110164 echo "Gitpod Flix is ready"
@@ -114,7 +168,11 @@ services:
114168 exit 1
115169 fi
116170 stop : |
171+ if lsof -Pi :3000 -sTCP:LISTEN -t >/dev/null 2>&1; then
172+ kill -9 $(lsof -ti:3000) 2>/dev/null || true
173+ fi
117174 pkill -f "node.*frontend" || true
175+ pkill -f "vite" || true
118176
119177tasks :
120178 seedDatabase :
0 commit comments