Deploy #34
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: | |
| - fix/** | |
| workflow_run: | |
| workflows: ["CI (Java)", "CI (Python/FastAPI)"] | |
| types: [completed] | |
| jobs: | |
| deploy: | |
| name: Deploy to AWS EC2 | |
| runs-on: ubuntu-latest | |
| if: | | |
| github.event.workflow_run.conclusion == 'success' && | |
| (startsWith(github.event.workflow_run.head_branch, 'user-service-v') || | |
| startsWith(github.event.workflow_run.head_branch, 'pre-processing-v')) | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Create env file | |
| run: | | |
| echo "DB_HOST=${{ secrets.DB_HOST }}" > .env.prod | |
| echo "DB_PORT=${{ secrets.DB_PORT }}" >> .env.prod | |
| echo "DB_USER=${{ secrets.DB_USER }}" >> .env.prod | |
| echo "DB_PASS=${{ secrets.DB_PASS }}" >> .env.prod | |
| echo "DB_NAME=${{ secrets.DB_NAME }}" >> .env.prod | |
| echo "ENV_NAME=${{ secrets.ENV_NAME }}" >> .env.prod | |
| - name: Set repo lowercase | |
| run: echo "REPO_LC=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV | |
| - name: Copy docker compose files to EC2 | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.SERVER_HOST }} | |
| username: ubuntu | |
| key: ${{ secrets.SERVER_SSH_KEY }} | |
| source: "docker/production/docker-compose.yml" | |
| target: "~/app" | |
| - name: Copy .env.prod file to EC2 | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.SERVER_HOST }} | |
| username: ubuntu | |
| key: ${{ secrets.SERVER_SSH_KEY }} | |
| source: ".env.prod" | |
| target: "~/app/docker/production/" | |
| overwrite: true | |
| - name: Deploy on EC2 | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.SERVER_HOST }} | |
| username: ubuntu | |
| key: ${{ secrets.SERVER_SSH_KEY }} | |
| script: | | |
| cd ~/app/docker/production | |
| echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
| echo ls | |
| docker-compose down | |
| docker-compose up -d | |
| sleep 10 | |
| docker-compose ps | |
| docker image prune -f | |
| - name: Send Discord notification - Success | |
| if: success() | |
| uses: Ilshidur/action-discord@master | |
| env: | |
| DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL }} | |
| with: | |
| args: | | |
| **배포 성공** | |
| **Repository:** ${{ env.REPO_LC }} | |
| **Tag:** ${{ github.ref_name }} | |
| **Server:** ${{ secrets.SERVER_HOST }} | |
| **Status:** Success! | |
| - name: Send Discord notification - Failure | |
| if: failure() | |
| uses: Ilshidur/action-discord@master | |
| env: | |
| DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL }} | |
| with: | |
| args: | | |
| **배포 실패** | |
| **Repository:** ${{ env.REPO_LC }} | |
| **Tag:** ${{ github.ref_name }} | |
| **Error:** 배포 중 오류가 발생했습니다. | |
| **Check:** ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |