feat: ChatRoomContorller 구현 #70
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: Deploy to GCP Compute Engine | |
| on: | |
| push: | |
| branches: [ develop ] | |
| paths-ignore: | |
| - 'api/src/docs/asciidoc/**' | |
| - '.github/workflows/docs.yml' | |
| workflow_dispatch: | |
| concurrency: | |
| group: build-and-deploy | |
| cancel-in-progress: true | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Create application.yml in api module | |
| run: | | |
| mkdir -p api/src/main/resources | |
| echo "${{ secrets.APPLICATION_DEV }}" > api/src/main/resources/application.yml | |
| echo "✅ application.yml created successfully" | |
| ls -la api/src/main/resources/ | |
| - name: Create .env | |
| run: | | |
| echo "${{ secrets.ENV_FILE }}" > .env | |
| echo "✅ .env file created successfully" | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: true | |
| tags: | | |
| ${{ secrets.DOCKERHUB_USERNAME }}/sent-app:${{ github.run_number }} | |
| ${{ secrets.DOCKERHUB_USERNAME }}/sent-app:latest | |
| - name: Verify Docker image push | |
| run: | | |
| echo "✅ Docker image pushed successfully" | |
| echo "🐳 Image tag: ${{ secrets.DOCKERHUB_USERNAME }}/sent-app:latest" | |
| - name: Prepare server directory | |
| uses: appleboy/ssh-action@v0.1.7 | |
| with: | |
| host: ${{ secrets.SERVER_IP }} | |
| username: ${{ secrets.SERVER_USER }} | |
| key: ${{ secrets.SERVER_SSH_KEY }} | |
| script: | | |
| mkdir -p /home/sentthoughts/Sent-Server | |
| echo "📁 Server directory prepared" | |
| - name: Copy all files to server | |
| uses: appleboy/scp-action@v0.1.7 | |
| with: | |
| host: ${{ secrets.SERVER_IP }} | |
| username: ${{ secrets.SERVER_USER }} | |
| key: ${{ secrets.SERVER_SSH_KEY }} | |
| source: . | |
| target: /home/sentthoughts/Sent-Server/ | |
| - name: Setup SSL certificates | |
| uses: appleboy/ssh-action@v0.1.7 | |
| with: | |
| host: ${{ secrets.SERVER_IP }} | |
| username: ${{ secrets.SERVER_USER }} | |
| key: ${{ secrets.SERVER_SSH_KEY }} | |
| script: | | |
| cd /home/sentthoughts/Sent-Server | |
| if [ ! -d "certs" ]; then | |
| ln -s /home/ubuntu/certs/devcerts ./certs | |
| fi | |
| if [ ! -f "certs/fullchain.pem" ] || [ ! -f "certs/privkey.pem" ]; then | |
| echo "❌ SSL certificates not found!" | |
| exit 1 | |
| fi | |
| - name: Check Docker status before deployment | |
| uses: appleboy/ssh-action@v0.1.7 | |
| with: | |
| host: ${{ secrets.SERVER_IP }} | |
| username: ${{ secrets.SERVER_USER }} | |
| key: ${{ secrets.SERVER_SSH_KEY }} | |
| script: | | |
| echo "🐳 Current Docker containers:" | |
| docker ps -a | |
| echo "" | |
| echo "🌐 Current Docker networks:" | |
| docker network ls | |
| echo "" | |
| echo "💾 Docker system info:" | |
| docker system df | |
| - name: Deploy with Docker Compose | |
| uses: appleboy/ssh-action@v0.1.7 | |
| with: | |
| host: ${{ secrets.SERVER_IP }} | |
| username: ${{ secrets.SERVER_USER }} | |
| key: ${{ secrets.SERVER_SSH_KEY }} | |
| script: | | |
| cd /home/sentthoughts/Sent-Server | |
| echo "📍 Current directory: $(pwd)" | |
| echo "📥 Pulling latest Docker images..." | |
| docker-compose pull | |
| echo "✅ Docker images pulled successfully" | |
| echo "🛑 Stopping existing services..." | |
| docker-compose down | |
| echo "✅ Services stopped" | |
| echo "🚀 Starting services with docker-compose..." | |
| docker-compose up -d | |
| echo "✅ Services started successfully" | |
| echo "📋 Container status:" | |
| docker-compose ps | |
| echo "📝 Service logs (last 20 lines):" | |
| docker-compose logs --tail 20 | |
| - name: Health check | |
| uses: appleboy/ssh-action@v0.1.7 | |
| with: | |
| host: ${{ secrets.SERVER_IP }} | |
| username: ${{ secrets.SERVER_USER }} | |
| key: ${{ secrets.SERVER_SSH_KEY }} | |
| script: | | |
| cd /home/sentthoughts/Sent-Server | |
| echo "🏥 Starting health check..." | |
| # Wait for services to start | |
| echo "⏰ Waiting for backend (sent-server) to initialize..." | |
| MAX_ATTEMPTS=15 | |
| SLEEP_SEC=8 | |
| for i in $(seq 1 $MAX_ATTEMPTS) | |
| do | |
| BACKEND_STATUS=$(curl -A "health-probe" -s -o /dev/null -w "%{http_code}" -k https://localhost/health || echo "000") | |
| echo "⏳ Health check attempt $i/$MAX_ATTEMPTS: backend $BACKEND_STATUS" | |
| if [ "$BACKEND_STATUS" = "200" ]; then | |
| echo "✅ Backend health check passed on attempt $i!" | |
| echo "📋 Final service status:" | |
| docker-compose ps | |
| echo "📝 Backend health response:" | |
| curl -s -k https://localhost/health || echo "No response" | |
| # nginx 상태/로그는 백엔드가 정상일 때만 한 번 확인 | |
| echo "📝 Nginx logs (last 10 lines):" | |
| docker-compose logs --tail 10 nginx-proxy 2>/dev/null || echo "⚠️ Unable to get nginx logs" | |
| echo "📝 Nginx status:" | |
| docker-compose ps nginx-proxy 2>/dev/null || echo "⚠️ Unable to get nginx status" | |
| exit 0 | |
| fi | |
| # 3회마다 최근 로그 출력 | |
| if (( $i % 3 == 0 )); then | |
| echo "📝 [Attempt $i] Recent backend logs:" | |
| docker-compose logs --tail 10 sent-server 2>/dev/null || echo "⚠️ Unable to get backend logs" | |
| fi | |
| sleep $SLEEP_SEC | |
| done | |
| echo "❌ Health check failed after $MAX_ATTEMPTS attempts!" | |
| echo "🔍 Final backend logs:" | |
| docker-compose logs --tail 30 sent-server 2>/dev/null || echo "⚠️ Unable to get backend logs" | |
| echo "🔍 Nginx logs:" | |
| docker-compose logs --tail 30 nginx-proxy 2>/dev/null || echo "⚠️ Unable to get nginx logs" | |
| echo "🔍 Service status:" | |
| docker-compose ps 2>/dev/null || echo "⚠️ Unable to get docker-compose status" | |
| exit 1 |