1- name : Lighthouse Service CI/CD
1+ name : Lighthouse Services CI/CD
22
33on :
44 push :
55 branches : [master]
66 paths :
77 - " lighthouse-service/**"
8+ - " lighthouse-worker/**"
89 - " .github/workflows/lighthouse-service-ci-cd.yml"
910 workflow_dispatch :
1011 inputs :
1819 - debug
1920
2021jobs :
21- build-and-deploy :
22+ build-and-test-service :
23+ name : Build and Test Lighthouse Service
2224 runs-on : self-hosted
2325 steps :
2426 - uses : actions/checkout@v3
5052 cd lighthouse-service
5153 ./mvnw clean package -DskipTests
5254
55+ build-and-test-worker :
56+ name : Build and Test Lighthouse Worker
57+ runs-on : self-hosted
58+ steps :
59+ - uses : actions/checkout@v3
60+
61+ - name : Set up Node.js
62+ uses : actions/setup-node@v3
63+ with :
64+ node-version : " 18"
65+ cache : " npm"
66+ cache-dependency-path : " lighthouse-worker/package-lock.json"
67+
68+ - name : Install dependencies
69+ run : |
70+ cd lighthouse-worker
71+ npm ci
72+
73+ - name : Run Tests
74+ run : |
75+ cd lighthouse-worker
76+ npm test || echo "No tests found, continuing build process"
77+
78+ build-docker-images :
79+ name : Build Docker Images
80+ needs : [build-and-test-service, build-and-test-worker]
81+ runs-on : self-hosted
82+ steps :
83+ - uses : actions/checkout@v3
84+
5385 - name : Set up QEMU
5486 uses : docker/setup-qemu-action@v2
5587 with :
6496 username : ${{ secrets.DOCKERHUB_USERNAME }}
6597 password : ${{ secrets.DOCKERHUB_TOKEN }}
6698
67- - name : Build and Push Docker image
99+ - name : Build and Push Lighthouse Service
68100 uses : docker/build-push-action@v4
69101 with :
70102 context : ./lighthouse-service
@@ -73,6 +105,20 @@ jobs:
73105 provenance : false
74106 tags : ${{ secrets.DOCKERHUB_USERNAME }}/lighthouse-service:latest-arm64
75107
108+ - name : Build and Push Lighthouse Worker
109+ uses : docker/build-push-action@v4
110+ with :
111+ context : ./lighthouse-worker
112+ platforms : linux/arm64
113+ push : true
114+ provenance : false
115+ tags : ${{ secrets.DOCKERHUB_USERNAME }}/lighthouse-worker:latest-arm64
116+
117+ deploy-services :
118+ name : Deploy Services to VPS
119+ needs : [build-docker-images]
120+ runs-on : self-hosted
121+ steps :
76122 - name : Deploy to VPS
77123 uses : appleboy/ssh-action@master
78124 with :
@@ -83,16 +129,19 @@ jobs:
83129 mkdir -p /opt/craftpilot/tmp/netty
84130 mkdir -p /opt/craftpilot/tmp/lighthouse
85131
132+ # Lighthouse Service deployment
133+ echo "=== Deploying Lighthouse Service ==="
134+
86135 # Stop and remove previous container
87- echo "Stopping and removing previous container if it exists"
136+ echo "Stopping and removing previous lighthouse-service container if it exists"
88137 docker stop lighthouse-service || true
89138 docker rm lighthouse-service || true
90139
91140 # Pull the latest image with explicit platform for ARM64
92- echo "Pulling latest ARM64 image"
141+ echo "Pulling latest ARM64 lighthouse-service image"
93142 docker pull --platform linux/arm64 ${{ secrets.DOCKERHUB_USERNAME }}/lighthouse-service:latest-arm64
94143
95- echo "Starting container with proper environment variables"
144+ echo "Starting lighthouse-service container with proper environment variables"
96145 docker run -d \
97146 --platform linux/arm64 \
98147 --name lighthouse-service \
@@ -104,9 +153,6 @@ jobs:
104153 -e SPRING_PROFILES_ACTIVE=prod \
105154 -e SPRING_DATA_REDIS_HOST=redis \
106155 -e SPRING_DATA_REDIS_PASSWORD=13579ada \
107- -e LIGHTHOUSE_CLI_PATH=/usr/local/bin/lighthouse \
108- -e CHROME_PATH=/usr/bin/google-chrome \
109- -e LIGHTHOUSE_CHROMIUM_PATH=/usr/bin/google-chrome \
110156 --ulimit nofile=65536:65536 \
111157 --security-opt no-new-privileges \
112158 --health-cmd="curl -f http://localhost:8085/health || exit 1" \
@@ -115,76 +161,130 @@ jobs:
115161 --health-retries=5 \
116162 --health-start-period=60s \
117163 ${{ secrets.DOCKERHUB_USERNAME }}/lighthouse-service:latest-arm64
164+
165+ # Lighthouse Worker deployment
166+ echo "=== Deploying Lighthouse Worker ==="
118167
119- # Verify available tools in the container
120- echo "Waiting for container to start (10 seconds)..."
121- sleep 10
168+ # Stop and remove previous worker containers
169+ echo "Stopping and removing previous lighthouse-worker containers if they exist"
170+ docker ps -q --filter "name=lighthouse-worker" | xargs -r docker stop
171+ docker ps -aq --filter "name=lighthouse-worker" | xargs -r docker rm
172+
173+ # Pull the latest worker image with explicit platform for ARM64
174+ echo "Pulling latest ARM64 lighthouse-worker image"
175+ docker pull --platform linux/arm64 ${{ secrets.DOCKERHUB_USERNAME }}/lighthouse-worker:latest-arm64
122176
123- echo "Verifying critical tools in container..."
124- docker exec lighthouse-service java -version || echo "Java check failed"
125- docker exec lighthouse-service node --version || echo "Node.js check failed"
126- docker exec lighthouse-service npm --version || echo "NPM check failed"
127- docker exec lighthouse-service which lighthouse || echo "Lighthouse CLI check failed"
128- docker exec lighthouse-service lighthouse --version || echo "Lighthouse version check failed"
177+ # Start two worker instances
178+ echo "Starting lighthouse-worker containers with proper environment variables"
179+ for i in 1 2; do
180+ docker run -d \
181+ --platform linux/arm64 \
182+ --name lighthouse-worker-$i \
183+ --network craftpilot-network \
184+ --restart unless-stopped \
185+ -e REDIS_HOST=redis \
186+ -e REDIS_PORT=6379 \
187+ -e REDIS_PASSWORD=13579ada \
188+ -e POLL_INTERVAL=5000 \
189+ -e MAX_RETRIES=3 \
190+ -e LIGHTHOUSE_QUEUE_NAME=lighthouse-jobs \
191+ -e LIGHTHOUSE_RESULTS_PREFIX=lighthouse-results: \
192+ --health-cmd="curl -f http://localhost:8086/health || exit 1" \
193+ --health-interval=30s \
194+ --health-timeout=10s \
195+ --health-retries=5 \
196+ --health-start-period=30s \
197+ ${{ secrets.DOCKERHUB_USERNAME }}/lighthouse-worker:latest-arm64
198+ done
129199
130- echo "Validating container environment variables ..."
131- docker exec lighthouse-service printenv | grep -E "PATH|NODE_PATH|JAVA_HOME|CHROME"
200+ echo "Waiting for containers to start (10 seconds) ..."
201+ sleep 10
132202
133- echo "=== Waiting for service startup ==="
203+ # Check service health
204+ echo "=== Checking Lighthouse Service Health ==="
134205 max_attempts=30
135206 counter=0
136- success =0
207+ service_success =0
137208
138209 while [ $counter -lt $max_attempts ]; do
139- echo "Health check attempt $((counter + 1))/$max_attempts"
210+ echo "Service health check attempt $((counter + 1))/$max_attempts"
140211
141212 # Container durumu kontrolü
142213 if ! docker ps --filter "name=lighthouse-service" --format '{{.Status}}' | grep -q "Up"; then
143- echo "Container is not running anymore . Checking logs..."
214+ echo "Service container is not running. Checking logs..."
144215 docker logs lighthouse-service | tail -n 100
145- exit 1
216+ break
146217 fi
147218
148219 # Application log kontrolü
149220 if docker logs lighthouse-service 2>&1 | grep -q "Started LighthouseServiceApplication"; then
150- echo "Application startup completed"
221+ echo "Service application startup completed"
151222
152223 # Health check kontrolü
153224 HEALTH_CHECK=$(curl -s http://localhost:8085/health)
154225 if echo "$HEALTH_CHECK" | grep -q '"status":"UP"'; then
155- echo "✓ Health check passed: $HEALTH_CHECK "
156- success =1
226+ echo "✓ Service health check passed"
227+ service_success =1
157228 break
158229 elif echo "$HEALTH_CHECK" | grep -q '"redis":"DOWN"'; then
159230 echo "× Redis connection issue detected in health check"
160- echo "Health response: $HEALTH_CHECK"
161- # Redis sağlık bilgilerini göster
162- echo "Redis connection details from logs:"
163231 docker logs lighthouse-service 2>&1 | grep -i "redis\|lettuce" | tail -20
164232 else
165233 echo "× Health check failed with response: $HEALTH_CHECK"
166234 fi
167235 else
168- echo "Waiting for application startup..."
236+ echo "Waiting for service application startup..."
169237 fi
170238
171- echo "Waiting for service to start... ($((counter + 1))/$max_attempts)"
172239 sleep 10
173240 counter=$((counter + 1))
174241 done
175242
176- if [ $success -eq 1 ]; then
243+ # Check worker health
244+ echo "=== Checking Lighthouse Worker Health ==="
245+ worker_success=0
246+
247+ for i in 1 2; do
248+ if docker ps --filter "name=lighthouse-worker-$i" --format '{{.Status}}' | grep -q "Up"; then
249+ WORKER_HEALTH=$(docker exec lighthouse-worker-$i curl -s http://localhost:8086/health || echo '{"status":"DOWN"}')
250+ if echo "$WORKER_HEALTH" | grep -q '"status":"UP"'; then
251+ echo "✓ Worker $i health check passed"
252+ worker_success=1
253+ else
254+ echo "× Worker $i health check failed"
255+ docker logs lighthouse-worker-$i | tail -n 50
256+ fi
257+ else
258+ echo "Worker $i is not running"
259+ docker logs lighthouse-worker-$i | tail -n 50
260+ fi
261+ done
262+
263+ # Validate overall deployment status
264+ if [ $service_success -eq 1 ] && [ $worker_success -eq 1 ]; then
177265 echo "=== Deployment completed successfully ==="
178266 exit 0
179267 else
180- echo "=== Health check failed - Debug Information ==="
181- echo "Docker Status:"
182- docker ps -a | grep lighthouse-service
183- echo "Container Logs:"
184- docker logs lighthouse-service --tail 100
185- echo "Health Check Response:"
186- curl -v http://localhost:8085/health || true
187- echo "Redis Check:"
268+ echo "=== Deployment health check failed ==="
269+
270+ if [ $service_success -ne 1 ]; then
271+ echo "Service health check failed - Debug Information:"
272+ docker ps -a | grep lighthouse-service
273+ docker logs lighthouse-service --tail 100
274+ curl -v http://localhost:8085/health || true
275+ fi
276+
277+ if [ $worker_success -ne 1 ]; then
278+ echo "Worker health check failed - Debug Information:"
279+ docker ps -a | grep lighthouse-worker
280+ for i in 1 2; do
281+ echo "Worker $i logs:"
282+ docker logs lighthouse-worker-$i --tail 50
283+ done
284+ fi
285+
286+ echo "Redis Connectivity Check:"
188287 docker exec lighthouse-service sh -c 'nc -zv $SPRING_DATA_REDIS_HOST $SPRING_DATA_REDIS_PORT' || echo "Redis connection failed"
288+
189289 exit 1
190290 fi
0 commit comments