Deploy Pull-it backend and worker to Yeon Pi #182
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 EC2 (Compose) | |
| on: | |
| workflow_run: | |
| workflows: ["Code check (linter, formatter)"] | |
| types: | |
| - completed | |
| branches: | |
| - develop | |
| jobs: | |
| deploy: | |
| if: github.event.workflow_run.conclusion == 'success' | |
| environment: qa | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| with: | |
| ref: ${{ github.event.workflow_run.head_sha }} | |
| - name: Login to Docker registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ secrets.DOCKER_REGISTRY_HOST }} | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| ecr: false | |
| - name: Setup SSH key | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo '${{ secrets.EC2_SSH_KEY }}' > ~/.ssh/ec2_key.pem | |
| chmod 600 ~/.ssh/ec2_key.pem | |
| ssh-keyscan -H ${{ secrets.EC2_HOST }} >> ~/.ssh/known_hosts 2>/dev/null || true | |
| - name: Create app directory on EC2 | |
| run: ssh -i ~/.ssh/ec2_key.pem -o StrictHostKeyChecking=no ubuntu@${{ secrets.EC2_HOST }} "mkdir -p /home/ubuntu/app/prometheus" | |
| - name: Upload configs and deployment script | |
| run: | | |
| scp -i ~/.ssh/ec2_key.pem -o StrictHostKeyChecking=no docker-compose.qa.yml ubuntu@${{ secrets.EC2_HOST }}:/home/ubuntu/app/docker-compose.qa.yml | |
| scp -i ~/.ssh/ec2_key.pem -o StrictHostKeyChecking=no prometheus/prometheus.qa.yml ubuntu@${{ secrets.EC2_HOST }}:/home/ubuntu/app/prometheus/prometheus.qa.yml | |
| scp -i ~/.ssh/ec2_key.pem -o StrictHostKeyChecking=no scripts/deploy-qa.sh ubuntu@${{ secrets.EC2_HOST }}:/home/ubuntu/app/deploy-qa.sh | |
| - name: Execute Blue-Green Deployment | |
| run: | | |
| ssh -i ~/.ssh/ec2_key.pem -o StrictHostKeyChecking=no ubuntu@${{ secrets.EC2_HOST }} " | |
| export DOCKER_IMAGE_NAME='${{ secrets.DOCKER_IMAGE_NAME }}' | |
| export IMAGE_TAG='${{ github.event.workflow_run.head_sha }}' | |
| export DB_USERNAME='${{ secrets.DB_USERNAME }}' | |
| export DB_PASSWORD='${{ secrets.DB_PASSWORD }}' | |
| export DB_ROOT_PASSWORD='${{ secrets.DB_ROOT_PASSWORD }}' | |
| export KAKAO_REST_API_KEY='${{ secrets.KAKAO_REST_API_KEY }}' | |
| export KAKAO_CLIENT_SECRET='${{ secrets.KAKAO_CLIENT_SECRET }}' | |
| export S3_ACCESS_KEY='${{ secrets.S3_ACCESS_KEY }}' | |
| export S3_SECRET_KEY='${{ secrets.S3_SECRET_KEY }}' | |
| export GEMINI_API_KEY='${{ secrets.GEMINI_API_KEY }}' | |
| export JWT_REDIRECT_URL='${{ secrets.JWT_REDIRECT_URL }}' | |
| export JWT_COOKIE_DOMAIN='${{ secrets.JWT_COOKIE_DOMAIN }}' | |
| export AWS_REGION='ap-northeast-2' | |
| export SENTRY_DSN='${{ secrets.SENTRY_DSN }}' | |
| export SENTRY_AUTH_TOKEN='${{ secrets.SENTRY_AUTH_TOKEN }}' | |
| export GRAFANA_ADMIN_PASSWORD='${{ secrets.GRAFANA_ADMIN_PASSWORD }}' | |
| export RABBITMQ_DEFAULT_USER='${{ secrets.RABBITMQ_DEFAULT_USER }}' | |
| export RABBITMQ_DEFAULT_PASS='${{ secrets.RABBITMQ_DEFAULT_PASS }}' | |
| # Make the script executable and run it | |
| chmod +x /home/ubuntu/app/deploy-qa.sh | |
| bash /home/ubuntu/app/deploy-qa.sh | |
| " | |
| - name: Cleanup | |
| if: always() | |
| run: rm -f ~/.ssh/ec2_key.pem |