chore: CD 완료/실패시 슬랙 알림 #5
Workflow file for this run
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: API CD | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: '롤백할 버전 (ex: v1.6.0)' | |
| required: true | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'push' | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Build and Push Docker Image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| push: true | |
| tags: | | |
| ${{ secrets.DOCKER_USERNAME }}/velog-dashboard-v2-api:latest | |
| ${{ secrets.DOCKER_USERNAME }}/velog-dashboard-v2-api:${{ github.ref_name }} | |
| platforms: linux/amd64 | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| deploy: | |
| runs-on: ubuntu-latest | |
| needs: [build-and-push] | |
| if: always() && (needs.build-and-push.result == 'success' || needs.build-and-push.result == 'skipped') | |
| steps: | |
| - name: Deploy to Server 1 | |
| uses: appleboy/ssh-action@v1 | |
| with: | |
| host: ${{ secrets.DEPLOY_HOST_1 }} | |
| username: ${{ secrets.DEPLOY_USER }} | |
| key: ${{ secrets.DEPLOY_SSH_KEY_1 }} | |
| command_timeout: 10m | |
| script: | | |
| export GIT_SSH_COMMAND='ssh -i ~/.ssh/velog-dashboard-v2-api' | |
| export API_VERSION=${{ github.event_name == 'workflow_dispatch' && github.event.inputs.version || github.ref_name }} | |
| cd ${{ secrets.DEPLOY_PATH }} | |
| git pull origin main | |
| sed '/docker compose logs -f/d' run.sh | bash | |
| - name: Deploy to Server 2 | |
| uses: appleboy/ssh-action@v1 | |
| with: | |
| host: ${{ secrets.DEPLOY_HOST_2 }} | |
| username: ${{ secrets.DEPLOY_USER }} | |
| key: ${{ secrets.DEPLOY_SSH_KEY_2 }} | |
| command_timeout: 10m | |
| script: | | |
| export GIT_SSH_COMMAND='ssh -i ~/.ssh/velog-dashboard-v2-api' | |
| export API_VERSION=${{ github.event_name == 'workflow_dispatch' && github.event.inputs.version || github.ref_name }} | |
| cd ${{ secrets.DEPLOY_PATH }} | |
| git pull origin main | |
| sed '/docker compose logs -f/d' run.sh | bash | |
| - name: Notify Slack on Success | |
| if: success() | |
| uses: slackapi/slack-github-action@v1.24.0 | |
| with: | |
| payload: | | |
| { | |
| "text": "✅ API 배포 성공\n• 버전: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.version || github.ref_name }}\n• 트리거: ${{ github.actor }}\n• <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|액션 로그>" | |
| } | |
| env: | |
| SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | |
| - name: Notify Slack on Failure | |
| if: failure() | |
| uses: slackapi/slack-github-action@v1.24.0 | |
| with: | |
| payload: | | |
| { | |
| "text": "❌ API 배포 실패\n• 버전: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.version || github.ref_name }}\n• 트리거: ${{ github.actor }}\n• <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|액션 로그>" | |
| } | |
| env: | |
| SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |