Refactor code structure for improved readability and maintainability #57
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: Analytics Service CI/CD | |
| on: | |
| push: | |
| branches: [master] | |
| paths: | |
| - "analytics-service/**" | |
| - ".github/workflows/analytics-service-ci-cd.yml" | |
| workflow_dispatch: | |
| jobs: | |
| build-and-deploy: | |
| runs-on: self-hosted | |
| defaults: | |
| run: | |
| working-directory: ./analytics-service | |
| steps: | |
| - uses: actions/checkout@v3 | |
| # QEMU kurulumu | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v2 | |
| with: | |
| platforms: arm64 | |
| # Docker Buildx kurulumu | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| with: | |
| platforms: linux/arm64 | |
| # Docker Hub'a giriş yap | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| logout: true | |
| # Sadece ARM64 için build ve push | |
| - name: Build and Push Docker image | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: ./analytics-service | |
| platforms: linux/arm64 | |
| push: true | |
| tags: | | |
| ${{ secrets.DOCKERHUB_USERNAME }}/analytics-service:latest-arm64 | |
| ${{ secrets.DOCKERHUB_USERNAME }}/analytics-service:${{ github.sha }}-arm64 | |
| cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/analytics-service:buildcache-arm64 | |
| cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/analytics-service:buildcache-arm64,mode=max | |
| # Google Cloud kimlik doğrulaması | |
| - id: "auth" | |
| name: "Authenticate to Google Cloud" | |
| uses: "google-github-actions/auth@v1" | |
| with: | |
| credentials_json: "${{ secrets.GCP_SA_KEY }}" | |
| # Google Cloud CLI kurulumu | |
| - name: "Set up Cloud SDK" | |
| uses: "google-github-actions/setup-gcloud@v1" | |
| - name: Deploy to VPS | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.VPS_HOST }} | |
| username: ${{ secrets.SSH_USERNAME }} | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| script_stop: true | |
| debug: true | |
| command_timeout: "20m" | |
| script: | | |
| echo "=== Testing Docker ===" | |
| docker version | |
| docker info | |
| docker ps | |
| echo "=== Pulling ARM64 Image ===" | |
| docker pull ${{ secrets.DOCKERHUB_USERNAME }}/analytics-service:latest-arm64 | |
| echo "=== Stopping Old Container ===" | |
| docker stop analytics-service || true | |
| docker rm analytics-service || true | |
| echo "=== Starting New Container ===" | |
| docker run -d \ | |
| --name analytics-service \ | |
| --network craftpilot-network \ | |
| --restart unless-stopped \ | |
| -p 8064:8064 \ | |
| -v /opt/craftpilot/gcp-credentials.json:/app/gcp-credentials.json:ro \ | |
| -e SPRING_PROFILES_ACTIVE=prod \ | |
| -e EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://craftpilot:13579ada@eureka-server:8761/eureka/ \ | |
| -e REDIS_HOST=redis \ | |
| -e REDIS_PORT=6379 \ | |
| -e REDIS_PASSWORD=13579ada \ | |
| -e SPRING_CLOUD_GCP_PROJECT_ID=${{ secrets.GCP_PROJECT_ID }} \ | |
| -e GOOGLE_APPLICATION_CREDENTIALS=/app/gcp-credentials.json \ | |
| -e SPRING_CLOUD_GCP_CREDENTIALS_LOCATION=file:/app/gcp-credentials.json \ | |
| -e MANAGEMENT_ENDPOINT_HEALTH_SHOW_DETAILS=always \ | |
| -e MANAGEMENT_ENDPOINT_HEALTH_PROBES_ENABLED=true \ | |
| -e MANAGEMENT_HEALTH_VALIDATE_GROUP_MEMBERSHIP=false \ | |
| -e LOGGING_LEVEL_COM_CRAFTPILOT=DEBUG \ | |
| -e LOGGING_LEVEL_COM_GOOGLE_CLOUD=DEBUG \ | |
| ${{ secrets.DOCKERHUB_USERNAME }}/analytics-service:latest-arm64 | |
| echo "=== Waiting for Container to Start ===" | |
| sleep 60 | |
| echo "=== Container Logs ===" | |
| docker logs analytics-service | |
| echo "=== Health Check ===" | |
| for i in {1..5}; do | |
| if curl -f http://localhost:8064/actuator/health; then | |
| echo "Service is healthy" | |
| exit 0 | |
| fi | |
| echo "Waiting for service to start... Attempt $i" | |
| sleep 10 | |
| done | |
| echo "Service failed health check" | |
| docker logs analytics-service | |
| exit 1 |