[Feat] 회원 탈퇴 기능 구현 (#132) #27
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: CI/CD Pipeline | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - develop | |
| pull_request: | |
| branches: | |
| - main | |
| env: | |
| AWS_REGION: ap-northeast-2 | |
| JAVA_VERSION: 21 | |
| jobs: | |
| test: | |
| name: Run Tests | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Make gradlew executable | |
| run: chmod +x ./gradlew | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '21' | |
| distribution: 'temurin' | |
| - name: Setup Gradle | |
| uses: gradle/gradle-build-action@v2 | |
| - name: Build application | |
| run: ./gradlew build -x test --no-daemon | |
| - name: Upload test results | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: test-results | |
| path: build/test-results/ | |
| if-no-files-found: ignore | |
| build: | |
| name: Build and Push Image | |
| runs-on: ubuntu-latest | |
| needs: test | |
| if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' | |
| outputs: | |
| image: ${{ steps.image.outputs.image }} | |
| tag: ${{ steps.image.outputs.tag }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set environment | |
| id: env | |
| run: | | |
| if [[ $GITHUB_REF == 'refs/heads/main' ]]; then | |
| echo "environment=prod" >> $GITHUB_OUTPUT | |
| else | |
| echo "environment=dev" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v2 | |
| 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@v1 | |
| - name: Build, tag, and push image to Amazon ECR | |
| id: image | |
| env: | |
| ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
| ENVIRONMENT: ${{ steps.env.outputs.environment }} | |
| PG_TOSS_CLIENT_KEY: ${{ secrets.PG_TOSS_CLIENT_KEY }} | |
| PG_TOSS_SECRET_KEY: ${{ secrets.PG_TOSS_SECRET_KEY }} | |
| run: | | |
| IMAGE_TAG=$GITHUB_SHA | |
| IMAGE_URI=$ECR_REGISTRY/team12-ecr-1:$IMAGE_TAG | |
| docker build --no-cache \ | |
| --build-arg PG_TOSS_SECRET_KEY=${{ env.PG_TOSS_SECRET_KEY }} \ | |
| --build-arg PG_TOSS_CLIENT_KEY=${{ env.PG_TOSS_CLIENT_KEY }} \ | |
| -t $IMAGE_URI . | |
| docker push $IMAGE_URI | |
| echo "image=$IMAGE_URI" >> $GITHUB_OUTPUT | |
| echo "tag=$IMAGE_TAG" >> $GITHUB_OUTPUT | |
| # Also tag as latest | |
| docker tag $IMAGE_URI $ECR_REGISTRY/team12-ecr-1:latest | |
| docker push $ECR_REGISTRY/team12-ecr-1:latest | |
| deploy-dev: | |
| name: Deploy to Development | |
| runs-on: ubuntu-latest | |
| needs: build | |
| if: github.ref == 'refs/heads/develop' | |
| environment: development | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v2 | |
| 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: Setup SSH key | |
| run: | | |
| echo "${{ secrets.EC2_SSH_KEY }}" > /tmp/ssh_key | |
| chmod 600 /tmp/ssh_key | |
| - name: Deploy Application | |
| run: | | |
| echo "Deploying new Docker image to EC2..." | |
| # EC2에 SSH로 접속하여 Docker 이미지 업데이트 | |
| ssh -i /tmp/ssh_key -o StrictHostKeyChecking=no [email protected] << 'EOF' | |
| cd /app | |
| # ECR 로그인 | |
| aws ecr get-login-password --region ap-northeast-2 | \ | |
| docker login --username AWS --password-stdin 174170816230.dkr.ecr.ap-northeast-2.amazonaws.com | |
| # 기존 컨테이너 완전히 제거 | |
| sudo /usr/local/bin/docker-compose down | |
| # 로컬 이미지 캐시 삭제 (latest 태그만) | |
| docker rmi 174170816230.dkr.ecr.ap-northeast-2.amazonaws.com/team12-ecr-1:latest || true | |
| # 최신 이미지 pull 및 재시작 | |
| sudo /usr/local/bin/docker-compose pull app | |
| sudo /usr/local/bin/docker-compose up -d --force-recreate | |
| # 새 이미지 digest 확인 | |
| docker images --digests | grep team12-ecr-1 | |
| echo "Deployment completed" | |
| EOF | |
| # - name: Health Check | |
| # run: | | |
| # echo "Running health check on https://api.bid-market.shop" | |
| # sleep 30 | |
| # | |
| # for i in {1..20}; do | |
| # if curl -f https://api.bid-market.shop/actuator/health; then | |
| # echo "Health check passed!" | |
| # exit 0 | |
| # fi | |
| # echo "Waiting for application... ($i/20)" | |
| # sleep 10 | |
| # done | |
| # echo "Health check failed!" | |
| # exit 1 | |
| deploy-prod: | |
| name: Deploy to Production | |
| runs-on: ubuntu-latest | |
| needs: build | |
| if: github.ref == 'refs/heads/main' | |
| environment: production | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v2 | |
| 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: Setup Terraform | |
| uses: hashicorp/setup-terraform@v2 | |
| with: | |
| terraform_version: 1.5.0 | |
| - name: Terraform Init | |
| run: | | |
| cd terraform/environments/prod | |
| terraform init | |
| - name: Terraform Apply | |
| run: | | |
| cd terraform/environments/prod | |
| terraform apply -auto-approve | |
| - name: Deploy Application | |
| run: | | |
| # Trigger instance refresh to deploy new version (Production) | |
| aws autoscaling start-instance-refresh \ | |
| --auto-scaling-group-name team12-asg-1 \ | |
| --preferences '{"MinHealthyPercentage": 90, "InstanceWarmup": 300}' | |
| echo "Production deployment initiated for team12-asg-1" | |
| echo "Instance refresh started. Waiting 8 minutes for deployment..." | |
| sleep 480 | |
| - name: Health Check | |
| run: | | |
| echo "Running health check on https://api.bid-market.shop" | |
| for i in {1..30}; do | |
| if curl -f https://api.bid-market.shop/actuator/health; then | |
| echo "Production deployment successful!" | |
| exit 0 | |
| fi | |
| echo "Waiting for application... ($i/30)" | |
| sleep 10 | |
| done | |
| echo "Health check failed!" | |
| exit 1 |