fix cors ayarları #345
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: API Gateway CI/CD | |
on: | |
push: | |
branches: [master] | |
paths: | |
- "api-gateway/**" | |
- ".github/workflows/api-gateway-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: "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: | | |
cd api-gateway | |
chmod +x mvnw | |
- name: Build | |
run: | | |
cd api-gateway | |
./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 | |
- 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: ./api-gateway | |
platforms: linux/arm64 | |
push: true | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/api-gateway:latest-arm64 | |
- name: Deploy to VPS | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.VPS_HOST }} | |
username: ${{ secrets.SSH_USERNAME }} | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
script: | | |
set -e # Exit on any error | |
echo "=== Setting up directories ===" | |
sudo mkdir -p /opt/craftpilot/config | |
sudo chown -R $USER:$USER /opt/craftpilot | |
echo "=== Setting up GCP credentials ===" | |
echo '${{ secrets.GCP_SA_KEY }}' > /opt/craftpilot/config/firebase-credentials.json | |
chmod 600 /opt/craftpilot/config/firebase-credentials.json | |
echo "=== Deploying API Gateway ===" | |
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/api-gateway:latest-arm64 | |
docker stop api-gateway || true | |
docker rm api-gateway || true | |
if [[ "${{ github.event.inputs.environment }}" == "debug" ]]; then | |
docker run -d \ | |
--name api-gateway \ | |
--hostname api-gateway \ | |
--network craftpilot-network \ | |
--restart unless-stopped \ | |
-p 8080:8080 \ | |
-p 5006:5006 \ | |
-v /opt/craftpilot/config/firebase-credentials.json:/app/config/firebase-credentials.json:ro \ | |
-e SPRING_PROFILES_ACTIVE=prod \ | |
-e SERVER_PORT=8080 \ | |
-e SPRING_FIREBASE_CREDENTIALS_PATH=/app/config/firebase-credentials.json \ | |
-e EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://craftpilot:13579ada@eureka-server:8761/eureka/ \ | |
-e EUREKA_INSTANCE_HOSTNAME=api-gateway \ | |
-e EUREKA_INSTANCE_PREFER_IP_ADDRESS=false \ | |
-e REDIS_HOST=redis \ | |
-e REDIS_PORT=6379 \ | |
-e REDIS_PASSWORD=13579ada \ | |
-e MANAGEMENT_ENDPOINTS_WEB_EXPOSURE_INCLUDE=health,info,metrics,prometheus \ | |
-e MANAGEMENT_ENDPOINT_HEALTH_SHOW_DETAILS=always \ | |
-e SPRING_APPLICATION_NAME=api-gateway \ | |
-e GOOGLE_APPLICATION_CREDENTIALS=/app/config/firebase-credentials.json \ | |
-e "JAVA_TOOL_OPTIONS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5006" \ | |
${{ secrets.DOCKERHUB_USERNAME }}/api-gateway:latest-arm64 | |
else | |
docker run -d \ | |
--name api-gateway \ | |
--hostname api-gateway \ | |
--network craftpilot-network \ | |
--restart unless-stopped \ | |
-p 8080:8080 \ | |
-v /opt/craftpilot/config/firebase-credentials.json:/app/config/firebase-credentials.json:ro \ | |
-e SPRING_PROFILES_ACTIVE=prod \ | |
-e SERVER_PORT=8080 \ | |
-e SPRING_FIREBASE_CREDENTIALS_PATH=/app/config/firebase-credentials.json \ | |
-e EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://craftpilot:13579ada@eureka-server:8761/eureka/ \ | |
-e EUREKA_INSTANCE_HOSTNAME=api-gateway \ | |
-e EUREKA_INSTANCE_PREFER_IP_ADDRESS=false \ | |
-e REDIS_HOST=redis \ | |
-e REDIS_PORT=6379 \ | |
-e REDIS_PASSWORD=13579ada \ | |
-e MANAGEMENT_ENDPOINTS_WEB_EXPOSURE_INCLUDE=health,info,metrics,prometheus \ | |
-e MANAGEMENT_ENDPOINT_HEALTH_SHOW_DETAILS=always \ | |
-e SPRING_APPLICATION_NAME=api-gateway \ | |
-e GOOGLE_APPLICATION_CREDENTIALS=/app/config/firebase-credentials.json \ | |
${{ secrets.DOCKERHUB_USERNAME }}/api-gateway:latest-arm64 | |
fi | |
echo "=== Waiting for Service Startup ===" | |
max_attempts=20 | |
counter=0 | |
while [ $counter -lt $max_attempts ]; do | |
echo "Health check attempt $((counter + 1))/$max_attempts" | |
if docker ps --filter "name=api-gateway" --format '{{.Status}}' | grep -q "Up"; then | |
if curl -sf http://localhost:8080/actuator/health > /dev/null; then | |
echo "✓ API Gateway is healthy" | |
echo "=== Deployment completed successfully ===" | |
exit 0 | |
fi | |
fi | |
echo "Waiting for service to be healthy..." | |
sleep 10 | |
counter=$((counter + 1)) | |
done | |
echo "=== Health Check Failed - Debug Information ===" | |
echo "Docker Status:" | |
docker ps -a | grep api-gateway | |
echo "Container Logs:" | |
docker logs api-gateway --tail 200 | |
echo "Network Information:" | |
docker network inspect craftpilot-network | |
exit 1 |