ANALYTICS-SERVICE #32
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: Eureka Server CI/CD | |
| on: | |
| push: | |
| branches: [master] | |
| paths: | |
| - "eureka-server/**" | |
| - ".github/workflows/eureka-server-ci-cd.yml" | |
| workflow_dispatch: | |
| jobs: | |
| build-and-push: | |
| runs-on: self-hosted | |
| defaults: | |
| run: | |
| working-directory: ./eureka-server | |
| 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: Grant execute permission for mvnw | |
| run: chmod +x mvnw | |
| - name: Build | |
| run: ./mvnw clean package -DskipTests | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v2 | |
| with: | |
| platforms: arm64 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| with: | |
| platforms: linux/arm64 | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and Push Docker image | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: ./eureka-server | |
| platforms: linux/arm64 | |
| push: true | |
| tags: | | |
| ${{ secrets.DOCKERHUB_USERNAME }}/eureka-server:latest-arm64 | |
| ${{ secrets.DOCKERHUB_USERNAME }}/eureka-server:${{ github.sha }}-arm64 | |
| cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/eureka-server:buildcache-arm64 | |
| cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/eureka-server:buildcache-arm64,mode=max | |
| deploy: | |
| 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: | | |
| # Eureka Server'ı başlat | |
| echo "Starting Eureka Server..." | |
| docker pull ${{ secrets.DOCKERHUB_USERNAME }}/eureka-server:latest-arm64 | |
| docker stop eureka-server || true | |
| docker rm eureka-server || true | |
| docker run -d \ | |
| --name eureka-server \ | |
| --network craftpilot-network \ | |
| --restart unless-stopped \ | |
| -p 8761:8761 \ | |
| --memory 600m \ | |
| --memory-swap 1g \ | |
| --cpu-shares 512 \ | |
| -e SPRING_PROFILES_ACTIVE=prod \ | |
| -e SERVER_PORT=8761 \ | |
| -e EUREKA_CLIENT_REGISTER_WITH_EUREKA=false \ | |
| -e EUREKA_CLIENT_FETCH_REGISTRY=false \ | |
| -e SPRING_SECURITY_USER_NAME=craftpilot \ | |
| -e SPRING_SECURITY_USER_PASSWORD=13579ada \ | |
| -e EUREKA_SERVER_ENABLE_SELF_PRESERVATION=false \ | |
| -e EUREKA_SERVER_EVICTION_INTERVAL_TIMER_IN_MS=3000 \ | |
| -e MANAGEMENT_ENDPOINTS_WEB_EXPOSURE_INCLUDE=health,info,metrics,prometheus \ | |
| -e MANAGEMENT_ENDPOINT_HEALTH_SHOW_DETAILS=always \ | |
| -e JAVA_OPTS="-XX:+UseContainerSupport -XX:MaxRAMPercentage=75.0 -XX:+UseG1GC -Xms256m -Xmx512m" \ | |
| ${{ secrets.DOCKERHUB_USERNAME }}/eureka-server:latest-arm64 | |
| # Health check - port 8761'i kontrol et | |
| echo "Checking Eureka Server health..." | |
| for i in {1..30}; do | |
| HEALTH_STATUS=$(curl -s -u craftpilot:13579ada http://localhost:8761/actuator/health || echo "Failed to connect") | |
| if echo "$HEALTH_STATUS" | grep -q "UP"; then | |
| echo "Eureka Server is healthy" | |
| exit 0 | |
| fi | |
| if [ $i -eq 15]; then | |
| echo "Mid-point container logs:" | |
| docker logs eureka-server | |
| fi | |
| echo "Waiting for Eureka Server to be healthy... (attempt $i/30)" | |
| sleep 10 | |
| done | |
| echo "Eureka Server failed to become healthy" | |
| docker logs eureka-server | |
| exit 1 |