lighthouse-service mimarısı yenilendi. #60
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Lighthouse Services CI/CD | |
| on: | |
| push: | |
| branches: [master] | |
| paths: | |
| - "lighthouse-service/**" | |
| - "lighthouse-worker/**" | |
| - ".github/workflows/lighthouse-service-ci-cd.yml" | |
| workflow_dispatch: | |
| inputs: | |
| environment: | |
| description: "Environment to deploy to" | |
| required: true | |
| default: "prod" | |
| type: choice | |
| options: | |
| - prod | |
| - debug | |
| jobs: | |
| build-and-test-service: | |
| name: Build and Test Lighthouse Service | |
| runs-on: self-hosted | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up JDK | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: "21" | |
| distribution: "temurin" | |
| - name: Cache Maven packages | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.m2 | |
| key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} | |
| restore-keys: ${{ runner.os }}-m2 | |
| - name: Generate Maven Wrapper if not exists | |
| run: | | |
| cd lighthouse-service | |
| if [ ! -f "mvnw" ]; then | |
| echo "Maven Wrapper not found, generating it..." | |
| mvn -N wrapper:wrapper -Dmaven=3.9.5 | |
| fi | |
| chmod +x mvnw | |
| - name: Build and Test | |
| run: | | |
| cd lighthouse-service | |
| ./mvnw clean compile | |
| if [ $? -eq 0 ]; then | |
| echo "Compilation successful! Running tests..." | |
| ./mvnw test -Dtest=!IntegrationTest* || echo "Tests may have failures but continuing" | |
| ./mvnw package -DskipTests | |
| else | |
| echo "Compilation failed!" | |
| exit 1 | |
| fi | |
| build-and-test-worker: | |
| name: Build and Test Lighthouse Worker | |
| runs-on: self-hosted | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: "18" | |
| cache: "npm" | |
| cache-dependency-path: "lighthouse-worker/package.json" | |
| - name: Install dependencies | |
| run: | | |
| cd lighthouse-worker | |
| echo "Installing npm dependencies..." | |
| [ ! -f "package-lock.json" ] && npm install --package-lock-only | |
| npm ci | |
| update-dockerfile: | |
| name: Update Dockerfile for ARM64 Support | |
| runs-on: self-hosted | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Update Lighthouse Service Dockerfile for ARM64 | |
| run: | | |
| echo 'FROM eclipse-temurin:17-jdk-alpine as builder | |
| WORKDIR /app | |
| COPY mvnw . | |
| COPY .mvn .mvn | |
| COPY pom.xml . | |
| COPY src src | |
| RUN chmod +x ./mvnw && ./mvnw package -DskipTests | |
| FROM adoptopenjdk/openjdk17:alpine-jre | |
| WORKDIR /app | |
| COPY --from=builder /app/target/*.jar /app/app.jar | |
| HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 CMD wget -q -O /dev/null http://localhost:8085/health || exit 1 | |
| ENV SPRING_PROFILES_ACTIVE=prod | |
| EXPOSE 8085 | |
| ENTRYPOINT ["java", "-jar", "/app/app.jar"]' > lighthouse-service/Dockerfile | |
| build-docker-images: | |
| name: Build Docker Images | |
| needs: [build-and-test-service, build-and-test-worker, update-dockerfile] | |
| runs-on: self-hosted | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v2 | |
| with: | |
| platforms: arm64 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and Push Lighthouse Service | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: ./lighthouse-service | |
| platforms: linux/arm64 | |
| push: true | |
| provenance: false | |
| tags: ${{ secrets.DOCKERHUB_USERNAME }}/lighthouse-service:latest-arm64 | |
| - name: Build and Push Lighthouse Worker | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: ./lighthouse-worker | |
| platforms: linux/arm64 | |
| push: true | |
| provenance: false | |
| tags: ${{ secrets.DOCKERHUB_USERNAME }}/lighthouse-worker:latest-arm64 | |
| deploy-services: | |
| name: Deploy Services to VPS | |
| needs: [build-docker-images] | |
| runs-on: self-hosted | |
| steps: | |
| - name: Deploy to VPS | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.VPS_HOST }} | |
| username: ${{ secrets.SSH_USERNAME }} | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| script: | | |
| mkdir -p /opt/craftpilot/tmp/netty | |
| mkdir -p /opt/craftpilot/tmp/lighthouse | |
| # Lighthouse Service deployment | |
| echo "=== Deploying Lighthouse Service ===" | |
| # Stop and remove previous container | |
| echo "Stopping and removing previous lighthouse-service container if it exists" | |
| docker stop lighthouse-service || true | |
| docker rm lighthouse-service || true | |
| # Pull the latest image with explicit platform for ARM64 | |
| echo "Pulling latest ARM64 lighthouse-service image" | |
| docker pull --platform linux/arm64 ${{ secrets.DOCKERHUB_USERNAME }}/lighthouse-service:latest-arm64 | |
| echo "Starting lighthouse-service container with proper environment variables" | |
| docker run -d \ | |
| --platform linux/arm64 \ | |
| --name lighthouse-service \ | |
| --network craftpilot-network \ | |
| --restart unless-stopped \ | |
| -p 8085:8085 \ | |
| -v /opt/craftpilot/tmp/lighthouse:/tmp/lighthouse \ | |
| -v /opt/craftpilot/tmp/netty:/tmp/netty \ | |
| -e SPRING_PROFILES_ACTIVE=prod \ | |
| -e SPRING_DATA_REDIS_HOST=redis \ | |
| -e SPRING_DATA_REDIS_PASSWORD=13579ada \ | |
| --ulimit nofile=65536:65536 \ | |
| --security-opt no-new-privileges \ | |
| --health-cmd="curl -f http://localhost:8085/health || exit 1" \ | |
| --health-interval=30s \ | |
| --health-timeout=10s \ | |
| --health-retries=5 \ | |
| --health-start-period=60s \ | |
| ${{ secrets.DOCKERHUB_USERNAME }}/lighthouse-service:latest-arm64 | |
| # Lighthouse Worker deployment | |
| echo "=== Deploying Lighthouse Worker ===" | |
| # Stop and remove previous worker containers | |
| echo "Stopping and removing previous lighthouse-worker containers if they exist" | |
| docker ps -q --filter "name=lighthouse-worker" | xargs -r docker stop | |
| docker ps -aq --filter "name=lighthouse-worker" | xargs -r docker rm | |
| # Pull the latest worker image with explicit platform for ARM64 | |
| echo "Pulling latest ARM64 lighthouse-worker image" | |
| docker pull --platform linux/arm64 ${{ secrets.DOCKERHUB_USERNAME }}/lighthouse-worker:latest-arm64 | |
| # Start two worker instances | |
| echo "Starting lighthouse-worker containers with proper environment variables" | |
| for i in 1 2; do | |
| docker run -d \ | |
| --platform linux/arm64 \ | |
| --name lighthouse-worker-$i \ | |
| --network craftpilot-network \ | |
| --restart unless-stopped \ | |
| -e REDIS_HOST=redis \ | |
| -e REDIS_PORT=6379 \ | |
| -e REDIS_PASSWORD=13579ada \ | |
| -e POLL_INTERVAL=5000 \ | |
| -e MAX_RETRIES=3 \ | |
| -e LIGHTHOUSE_QUEUE_NAME=lighthouse-jobs \ | |
| -e LIGHTHOUSE_RESULTS_PREFIX=lighthouse-results: \ | |
| --health-cmd="curl -f http://localhost:8086/health || exit 1" \ | |
| --health-interval=30s \ | |
| --health-timeout=10s \ | |
| --health-retries=5 \ | |
| --health-start-period=30s \ | |
| ${{ secrets.DOCKERHUB_USERNAME }}/lighthouse-worker:latest-arm64 | |
| done | |
| echo "Waiting for containers to start (10 seconds)..." | |
| sleep 10 | |
| # Check service health | |
| echo "=== Checking Lighthouse Service Health ===" | |
| max_attempts=30 | |
| counter=0 | |
| service_success=0 | |
| while [ $counter -lt $max_attempts ]; do | |
| echo "Service health check attempt $((counter + 1))/$max_attempts" | |
| # Container durumu kontrolü | |
| if ! docker ps --filter "name=lighthouse-service" --format '{{.Status}}' | grep -q "Up"; then | |
| echo "Service container is not running. Checking logs..." | |
| docker logs lighthouse-service | tail -n 100 | |
| break | |
| fi | |
| # Application log kontrolü | |
| if docker logs lighthouse-service 2>&1 | grep -q "Started LighthouseServiceApplication"; then | |
| echo "Service application startup completed" | |
| # Health check kontrolü | |
| HEALTH_CHECK=$(curl -s http://localhost:8085/health) | |
| if echo "$HEALTH_CHECK" | grep -q '"status":"UP"'; then | |
| echo "✓ Service health check passed" | |
| service_success=1 | |
| break | |
| elif echo "$HEALTH_CHECK" | grep -q '"redis":"DOWN"'; then | |
| echo "× Redis connection issue detected in health check" | |
| docker logs lighthouse-service 2>&1 | grep -i "redis\|lettuce" | tail -20 | |
| else | |
| echo "× Health check failed with response: $HEALTH_CHECK" | |
| fi | |
| else | |
| echo "Waiting for service application startup..." | |
| fi | |
| sleep 10 | |
| counter=$((counter + 1)) | |
| done | |
| # Check worker health | |
| echo "=== Checking Lighthouse Worker Health ===" | |
| worker_success=0 | |
| for i in 1 2; do | |
| if docker ps --filter "name=lighthouse-worker-$i" --format '{{.Status}}' | grep -q "Up"; then | |
| WORKER_HEALTH=$(docker exec lighthouse-worker-$i curl -s http://localhost:8086/health || echo '{"status":"DOWN"}') | |
| if echo "$WORKER_HEALTH" | grep -q '"status":"UP"'; then | |
| echo "✓ Worker $i health check passed" | |
| worker_success=1 | |
| else | |
| echo "× Worker $i health check failed" | |
| docker logs lighthouse-worker-$i | tail -n 50 | |
| fi | |
| else | |
| echo "Worker $i is not running" | |
| docker logs lighthouse-worker-$i | tail -n 50 | |
| fi | |
| done | |
| # Validate overall deployment status | |
| if [ $service_success -eq 1 ] && [ $worker_success -eq 1 ]; then | |
| echo "=== Deployment completed successfully ===" | |
| exit 0 | |
| else | |
| echo "=== Deployment health check failed ===" | |
| if [ $service_success -ne 1 ]; then | |
| echo "Service health check failed - Debug Information:" | |
| docker ps -a | grep lighthouse-service | |
| docker logs lighthouse-service --tail 100 | |
| curl -v http://localhost:8085/health || true | |
| fi | |
| if [ $worker_success -ne 1 ]; then | |
| echo "Worker health check failed - Debug Information:" | |
| docker ps -a | grep lighthouse-worker | |
| for i in 1 2; do | |
| echo "Worker $i logs:" | |
| docker logs lighthouse-worker-$i --tail 50 | |
| done | |
| fi | |
| echo "Redis Connectivity Check:" | |
| docker exec lighthouse-service sh -c 'nc -zv $SPRING_DATA_REDIS_HOST $SPRING_DATA_REDIS_PORT' || echo "Redis connection failed" | |
| exit 1 | |
| fi |