feat: Dockerfile yapılandırması güncellendi; craft-pilot-commons kont… #52
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: Activity Log Service CI/CD | |
| on: | |
| push: | |
| branches: [master] | |
| paths: | |
| - "activity-log-service/**" | |
| - "craft-pilot-commons/**" | |
| - ".github/workflows/activity-log-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-deploy: | |
| runs-on: self-hosted | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up JDK | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: "17" | |
| 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: Build commons library (if needed) | |
| run: | | |
| if [ -d "craft-pilot-commons" ]; then | |
| cd craft-pilot-commons | |
| mvn clean install -DskipTests | |
| fi | |
| - name: Build with Maven | |
| run: | | |
| cd activity-log-service | |
| mvn 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 | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Prepare build context | |
| run: | | |
| # Create a temporary directory for build context | |
| mkdir -p /tmp/docker-build-context | |
| # Check source directories and files | |
| echo "Current directory: $(pwd)" | |
| echo "Checking activity-log-service directory:" | |
| ls -la activity-log-service/ | |
| # Ensure activity-log-service directory exists | |
| if [ ! -d "activity-log-service" ]; then | |
| echo "ERROR: activity-log-service directory not found" | |
| exit 1 | |
| fi | |
| # Copy directories to build context | |
| cp -r activity-log-service /tmp/docker-build-context/ | |
| # Copy craft-pilot-commons if it exists | |
| if [ -d "craft-pilot-commons" ]; then | |
| cp -r craft-pilot-commons /tmp/docker-build-context/ | |
| fi | |
| # Verify build context contents | |
| echo "Checking build context:" | |
| ls -la /tmp/docker-build-context/ | |
| echo "Checking activity-log-service directory in build context:" | |
| ls -la /tmp/docker-build-context/activity-log-service/ | |
| - name: Build and Push Docker image | |
| id: docker_build | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: /tmp/docker-build-context | |
| file: /tmp/docker-build-context/activity-log-service/Dockerfile | |
| platforms: linux/arm64 | |
| push: true | |
| tags: ${{ secrets.DOCKERHUB_USERNAME }}/activity-log-service:latest-arm64 | |
| cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/activity-log-service:buildcache | |
| cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/activity-log-service:buildcache,mode=max | |
| - 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 | |
| command_timeout: "10m" | |
| script: | | |
| echo "Starting deployment of Activity Log Service..." | |
| docker pull ${{ secrets.DOCKERHUB_USERNAME }}/activity-log-service:latest-arm64 | |
| docker stop activity-log-service || true | |
| docker rm activity-log-service || true | |
| # Debug ve prod modları için farklı container yapılandırması | |
| if [[ "${{ github.event.inputs.environment }}" == "debug" ]]; then | |
| # Debug modu container yapılandırması | |
| docker run -d \ | |
| --name activity-log-service \ | |
| --network craftpilot-network \ | |
| --restart unless-stopped \ | |
| -p 8095:8095 \ | |
| -p 5010:5010 \ | |
| -e SPRING_PROFILES_ACTIVE=prod \ | |
| -e KAFKA_BOOTSTRAP_SERVERS=kafka:9092 \ | |
| -e EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://craftpilot:13579ada@eureka-server:8761/eureka/ \ | |
| -e HOSTNAME=activity-log-service \ | |
| -e SPRING_SECURITY_USER_NAME=craftpilot \ | |
| -e SPRING_SECURITY_USER_PASSWORD=13579ada \ | |
| -e REDIS_HOST=redis \ | |
| -e REDIS_PORT=6379 \ | |
| -e REDIS_PASSWORD=13579ada \ | |
| -e MONGODB_URI=${{ secrets.MONGODB_URI }} \ | |
| -e MONGO_INITDB_DATABASE=${{ secrets.MONGO_INITDB_DATABASE || 'craftpilot' }} \ | |
| -e MANAGEMENT_ENDPOINTS_WEB_BASE_PATH=/actuator \ | |
| -e "MANAGEMENT_ENDPOINTS_WEB_EXPOSURE_INCLUDE=*" \ | |
| -e MANAGEMENT_ENDPOINT_HEALTH_SHOW_DETAILS=always \ | |
| -e "JAVA_OPTS=-XX:+UseContainerSupport -XX:MaxRAMPercentage=70.0 -XX:+UseG1GC -Djava.security.egd=file:/dev/./urandom -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5010" \ | |
| --health-cmd="curl -f http://localhost:8095/actuator/health || exit 1" \ | |
| --health-interval=30s \ | |
| --health-timeout=10s \ | |
| --health-retries=3 \ | |
| --health-start-period=60s \ | |
| ${{ secrets.DOCKERHUB_USERNAME }}/activity-log-service:latest-arm64 | |
| else | |
| # Prod modu container yapılandırması | |
| docker run -d \ | |
| --name activity-log-service \ | |
| --network craftpilot-network \ | |
| --restart unless-stopped \ | |
| -p 8095:8095 \ | |
| -e SPRING_PROFILES_ACTIVE=prod \ | |
| -e KAFKA_BOOTSTRAP_SERVERS=kafka:9092 \ | |
| -e EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://craftpilot:13579ada@eureka-server:8761/eureka/ \ | |
| -e HOSTNAME=activity-log-service \ | |
| -e SPRING_SECURITY_USER_NAME=craftpilot \ | |
| -e SPRING_SECURITY_USER_PASSWORD=13579ada \ | |
| -e REDIS_HOST=redis \ | |
| -e REDIS_PORT=6379 \ | |
| -e REDIS_PASSWORD=13579ada \ | |
| -e MONGODB_URI=${{ secrets.MONGODB_URI }} \ | |
| -e MONGO_INITDB_DATABASE=${{ secrets.MONGO_INITDB_DATABASE || 'craftpilot' }} \ | |
| -e MANAGEMENT_ENDPOINTS_WEB_BASE_PATH=/actuator \ | |
| -e "MANAGEMENT_ENDPOINTS_WEB_EXPOSURE_INCLUDE=health,info,metrics" \ | |
| -e MANAGEMENT_ENDPOINT_HEALTH_SHOW_DETAILS=always \ | |
| -e MANAGEMENT_HEALTH_VALIDATE_GROUP_MEMBERSHIP=false \ | |
| -e "JAVA_OPTS=-XX:+UseContainerSupport -XX:MaxRAMPercentage=70.0 -XX:+UseG1GC -Djava.security.egd=file:/dev/./urandom" \ | |
| --health-cmd="curl -f http://localhost:8095/actuator/health || exit 1" \ | |
| --health-interval=30s \ | |
| --health-timeout=10s \ | |
| --health-retries=3 \ | |
| --health-start-period=60s \ | |
| ${{ secrets.DOCKERHUB_USERNAME }}/activity-log-service:latest-arm64 | |
| fi | |
| echo "=== Waiting for service startup ===" | |
| max_attempts=15 | |
| counter=0 | |
| while [ $counter -lt $max_attempts ]; do | |
| echo "Health check attempt $((counter + 1))/$max_attempts" | |
| # Container durumu kontrolü | |
| if ! docker ps --filter "name=activity-log-service" --format '{{.Status}}' | grep -q "Up"; then | |
| echo "Container is not running. Checking logs..." | |
| docker logs activity-log-service | |
| exit 1 | |
| fi | |
| # Health check kontrolü (basitleştirilmiş) | |
| HEALTH_CHECK=$(curl -s http://localhost:8095/actuator/health || echo "FAILED") | |
| if echo "$HEALTH_CHECK" | grep -q '"status":"UP"'; then | |
| echo "✓ Service is healthy" | |
| echo "=== Deployment completed successfully ===" | |
| exit 0 | |
| fi | |
| echo "Waiting for service to start... ($((counter + 1))/$max_attempts)" | |
| sleep 10 | |
| counter=$((counter + 1)) | |
| done | |
| echo "=== Service failed to start - Debug Information ===" | |
| echo "Docker Status:" | |
| docker ps -a | grep activity-log-service | |
| echo "Container Logs (last 100 lines):" | |
| docker logs activity-log-service --tail 100 | |
| exit 1 |