feat: Tomcat 스레드 메트릭 노출 활성화 #23
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 | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - dev | |
| env: | |
| AWS_REGION: ap-northeast-2 | |
| ECR_REPOSITORY: ifu-server | |
| jobs: | |
| # =========================================== | |
| # Staging: EC2에서 직접 빌드 | |
| # =========================================== | |
| deploy-staging: | |
| if: github.ref == 'refs/heads/dev' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Setup SSH key | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "${{ secrets.EC2_SSH_KEY }}" > ~/.ssh/ifu-keypair.pem | |
| chmod 600 ~/.ssh/ifu-keypair.pem | |
| - name: Build and Deploy on EC2 | |
| run: | | |
| ssh -o StrictHostKeyChecking=no -i ~/.ssh/ifu-keypair.pem ec2-user@${{ secrets.STAGING_EC2_HOST }} << 'EOF' | |
| set -e | |
| cd /home/ec2-user | |
| # SSM Parameter Store에서 GitHub PAT 가져오기 | |
| GH_PAT=$(aws ssm get-parameter --name "/ifu/github-pat" --with-decryption --query "Parameter.Value" --output text) | |
| # Git clone 또는 pull | |
| if [ ! -d "If-U-SERVER" ]; then | |
| echo "Cloning repository..." | |
| git clone "https://${GH_PAT}@github.com/If-U-Lab/If-U-SERVER.git" | |
| cd If-U-SERVER | |
| # URL에서 PAT 제거 (보안) | |
| git remote set-url origin https://github.com/If-U-Lab/If-U-SERVER.git | |
| else | |
| cd If-U-SERVER | |
| # pull 시에만 임시로 PAT 사용 | |
| git remote set-url origin "https://${GH_PAT}@github.com/If-U-Lab/If-U-SERVER.git" | |
| fi | |
| git fetch origin | |
| git checkout dev | |
| git pull origin dev | |
| # PAT 제거 (보안) | |
| git remote set-url origin https://github.com/If-U-Lab/If-U-SERVER.git | |
| # 기존 컨테이너 강제 삭제 (stop + rm) | |
| echo "Removing existing container..." | |
| docker rm -f ifu-server 2>/dev/null || true | |
| # Docker 이미지 빌드 (ARM64 네이티브) | |
| echo "Building Docker image..." | |
| docker build -t ifu-server:staging . | |
| # 새 컨테이너 실행 (CloudWatch Logs 연동) | |
| echo "Starting new container..." | |
| docker run -d \ | |
| --name ifu-server \ | |
| --restart unless-stopped \ | |
| --log-driver=awslogs \ | |
| --log-opt awslogs-region=ap-northeast-2 \ | |
| --log-opt awslogs-group=/ifu/staging/application \ | |
| --log-opt awslogs-stream=ifu-server-staging-$(date +%Y%m%d-%H%M) \ | |
| -p 8080:8080 \ | |
| -e ENVIRONMENT=staging \ | |
| -e TZ=Asia/Seoul \ | |
| ifu-server:staging | |
| # 이전 이미지 정리 | |
| docker image prune -f | |
| echo "Deployment completed successfully!" | |
| EOF | |
| - name: Health check | |
| run: | | |
| echo "Waiting for application to start..." | |
| sleep 30 | |
| HEALTH_URL="https://staging-api.if-u.site/actuator/health" | |
| for i in {1..5}; do | |
| response=$(curl -s -o /dev/null -w "%{http_code}" $HEALTH_URL || echo "000") | |
| if [[ "$response" == "200" ]]; then | |
| echo "Health check passed!" | |
| exit 0 | |
| fi | |
| echo "Attempt $i: Health check returned $response, retrying in 10s..." | |
| sleep 10 | |
| done | |
| echo "Health check failed after 5 attempts" | |
| exit 1 | |
| # =========================================== | |
| # Production: QEMU 빌드 | |
| # =========================================== | |
| deploy-production: | |
| if: github.ref == 'refs/heads/main' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| aws-region: ${{ env.AWS_REGION }} | |
| - name: Login to Amazon ECR | |
| id: login-ecr | |
| uses: aws-actions/amazon-ecr-login@v2 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Set up QEMU (for ARM64 build) | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| platforms: linux/arm64 | |
| push: true | |
| tags: | | |
| ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:${{ github.sha }} | |
| ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:prod-latest | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Setup SSH key | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "${{ secrets.EC2_SSH_KEY }}" > ~/.ssh/ifu-keypair.pem | |
| chmod 600 ~/.ssh/ifu-keypair.pem | |
| - name: Deploy to EC2 | |
| run: | | |
| ssh -o StrictHostKeyChecking=no -i ~/.ssh/ifu-keypair.pem ec2-user@${{ secrets.PROD_EC2_HOST }} << 'EOF' | |
| set -e | |
| # ECR 로그인 | |
| aws ecr get-login-password --region ap-northeast-2 | \ | |
| docker login --username AWS --password-stdin 017777088622.dkr.ecr.ap-northeast-2.amazonaws.com | |
| # 새 이미지 pull | |
| docker pull 017777088622.dkr.ecr.ap-northeast-2.amazonaws.com/ifu-server:prod-latest | |
| # 기존 컨테이너 중지 및 삭제 | |
| docker stop ifu-server 2>/dev/null || true | |
| docker rm ifu-server 2>/dev/null || true | |
| # 새 컨테이너 실행 (CloudWatch Logs 연동) | |
| docker run -d \ | |
| --name ifu-server \ | |
| --restart unless-stopped \ | |
| --log-driver=awslogs \ | |
| --log-opt awslogs-region=ap-northeast-2 \ | |
| --log-opt awslogs-group=/ifu/prod/application \ | |
| --log-opt awslogs-stream=ifu-server-prod-$(date +%Y%m%d-%H%M) \ | |
| -p 8080:8080 \ | |
| -e ENVIRONMENT=prod \ | |
| -e TZ=Asia/Seoul \ | |
| 017777088622.dkr.ecr.ap-northeast-2.amazonaws.com/ifu-server:prod-latest | |
| # 이전 이미지 정리 | |
| docker image prune -f | |
| echo "Deployment completed successfully!" | |
| EOF | |
| - name: Health check | |
| run: | | |
| echo "Waiting for application to start..." | |
| sleep 30 | |
| HEALTH_URL="https://api.if-u.site/actuator/health" | |
| for i in {1..5}; do | |
| response=$(curl -s -o /dev/null -w "%{http_code}" $HEALTH_URL || echo "000") | |
| if [[ "$response" == "200" ]]; then | |
| echo "Health check passed!" | |
| exit 0 | |
| fi | |
| echo "Attempt $i: Health check returned $response, retrying in 10s..." | |
| sleep 10 | |
| done | |
| echo "Health check failed after 5 attempts" | |
| exit 1 |