fix: 소셜 도메인 조정 #2
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: CD PROD | |
| on: | |
| push: | |
| branches: | |
| - prod | |
| workflow_dispatch: | |
| jobs: | |
| deploy-prod: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Extract Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: dykkim/muneo | |
| tags: | | |
| type=raw,value=prod-latest | |
| type=sha,format=short,prefix=prod- | |
| - name: Build and push image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Copy prod deploy files to EC2 | |
| uses: appleboy/scp-action@v0.1.7 | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USERNAME }} | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| port: ${{ secrets.EC2_PORT }} | |
| source: "docker-compose.prod.yml,nginx/conf.d/prod.conf" | |
| target: ${{ secrets.EC2_DEPLOY_PATH_PROD }} | |
| strip_components: 0 | |
| overwrite: true | |
| - name: Deploy prod stack on EC2 | |
| uses: appleboy/ssh-action@v1.0.3 | |
| env: | |
| DEPLOY_PATH: ${{ secrets.EC2_DEPLOY_PATH }} | |
| DEPLOY_PATH_PROD: ${{ secrets.EC2_DEPLOY_PATH_PROD }} | |
| DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | |
| DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} | |
| DOCKERHUB_IMAGE: dykkim/muneo | |
| PROD_APP_ENV: ${{ secrets.PROD_APP_ENV }} | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USERNAME }} | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| port: ${{ secrets.EC2_PORT }} | |
| envs: DEPLOY_PATH,DEPLOY_PATH_PROD,DOCKERHUB_USERNAME,DOCKERHUB_TOKEN,DOCKERHUB_IMAGE,PROD_APP_ENV | |
| script_stop: true | |
| script: | | |
| set -e | |
| sudo systemctl enable --now docker || true | |
| mkdir -p "${DEPLOY_PATH_PROD}" | |
| cd "${DEPLOY_PATH_PROD}" | |
| mkdir -p nginx/conf.d | |
| printf "%s" "${PROD_APP_ENV}" > .env | |
| { | |
| echo "" | |
| echo "DOCKERHUB_IMAGE=${DOCKERHUB_IMAGE}" | |
| echo "IMAGE_TAG=prod-latest" | |
| } >> .env | |
| echo "${DOCKERHUB_TOKEN}" | docker login -u "${DOCKERHUB_USERNAME}" --password-stdin | |
| docker compose -f docker-compose.prod.yml pull app-prod redis-prod | |
| docker compose -f docker-compose.prod.yml up -d --remove-orphans app-prod redis-prod | |
| # Keep one shared nginx stack (dev path), and update only its prod server block. | |
| mkdir -p "${DEPLOY_PATH}/nginx/conf.d" | |
| cp -f "${DEPLOY_PATH_PROD}/nginx/conf.d/prod.conf" "${DEPLOY_PATH}/nginx/conf.d/prod.conf" | |
| cd "${DEPLOY_PATH}" | |
| # Wait until shared nginx is actually running before exec commands. | |
| for i in {1..30}; do | |
| if docker compose ps --status running nginx | grep -q "nginx"; then | |
| break | |
| fi | |
| sleep 2 | |
| done | |
| docker compose exec -T nginx nginx -t | |
| docker compose exec -T nginx nginx -s reload | |
| docker compose exec -T nginx sh -c "grep -n 'api-prod.muneo.ai.kr\\|risk-detector\\|proxy_read_timeout\\|proxy_request_buffering' /etc/nginx/conf.d/prod.conf || true" | |
| docker image prune -f |