Merge pull request #43 from pythonkr/feature/migrate-purchase-repo #23
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: Release-Server | |
| concurrency: | |
| group: ${{ github.workflow }} | |
| cancel-in-progress: false | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| WORKFLOW_PHASE: | |
| description: "배포할 대상 환경을 선택하세요." | |
| required: true | |
| default: dev | |
| type: choice | |
| options: | |
| - dev | |
| - prd | |
| push: | |
| branches: | |
| - "main" | |
| jobs: | |
| BuildAndDeploy: | |
| runs-on: ubuntu-latest | |
| env: | |
| API_STAGE: ${{ github.event_name == 'workflow_dispatch' && inputs.WORKFLOW_PHASE || 'dev' }} | |
| BUMP_RULE: ${{ (github.event_name == 'workflow_dispatch' && inputs.WORKFLOW_PHASE || 'dev') == 'dev' && '--stage' || '' }} | |
| steps: | |
| - name: Checkout source codes | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v5 | |
| with: | |
| enable-cache: true | |
| ignore-nothing-to-cache: true | |
| - name: Install dependencies | |
| run: uv sync --only-group=deployment | |
| - 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: Get current date, repo name and release tag version | |
| id: info | |
| run: | | |
| echo "TAG=$(uv run python ./.github/scripts/get_new_version.py --cleanup-invalid ${{ env.BUMP_RULE }})" >> "$GITHUB_OUTPUT" | |
| echo "date=$(date +'%Y-%m-%d_%H:%M:%S')" >> "$GITHUB_OUTPUT" | |
| echo "repository_name=$(echo ${{ github.repository }} | sed -e 's/${{ github.repository_owner }}\///')" >> "$GITHUB_OUTPUT" | |
| - name: Build and Push Docker image to Docker Hub | |
| uses: docker/build-push-action@v5 | |
| with: | |
| push: true | |
| tags: | | |
| ${{ secrets.DOCKERHUB_IMAGE }}:${{ steps.info.outputs.TAG }} | |
| ${{ secrets.DOCKERHUB_IMAGE }}:latest | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| context: . | |
| file: ./infra/server.Dockerfile | |
| platforms: linux/amd64 | |
| provenance: false | |
| build-args: | | |
| RELEASE_VERSION=${{ steps.info.outputs.TAG }} | |
| GIT_HASH=${{ github.sha }} | |
| IMAGE_BUILD_DATETIME=${{ steps.info.outputs.date }} | |
| - name: Create and push git tag | |
| run: | | |
| git tag ${{ steps.info.outputs.TAG }} | |
| git push origin ${{ steps.info.outputs.TAG }} | |
| # Trigger infrastructure repo to bump tag and run ansible deploy. | |
| - name: Generate infrastructure deploy token | |
| id: deploy-token | |
| uses: actions/create-github-app-token@v3 | |
| with: | |
| client-id: ${{ vars.DEPLOY_APP_CLIENT_ID }} | |
| private-key: ${{ secrets.DEPLOY_APP_PRIVATE_KEY }} | |
| owner: ${{ github.repository_owner }} | |
| repositories: ${{ secrets.INFRA_REPO_NAME }} | |
| - name: Trigger infrastructure deploy | |
| env: | |
| GH_TOKEN: ${{ steps.deploy-token.outputs.token }} | |
| INFRA_REPO: ${{ github.repository_owner }}/${{ secrets.INFRA_REPO_NAME }} | |
| SERVICE: backend-${{ env.API_STAGE }} | |
| IMAGE_TAG: ${{ steps.info.outputs.TAG }} | |
| run: | | |
| gh api "repos/$INFRA_REPO/dispatches" \ | |
| --method POST \ | |
| -f event_type=bump-image \ | |
| -f "client_payload[service]=$SERVICE" \ | |
| -f "client_payload[image_tag]=$IMAGE_TAG" | |
| - uses: ./.github/actions/notify-slack-deploy | |
| if: always() | |
| with: | |
| slack-token: ${{ secrets.SLACK_BOT_TOKEN }} | |
| slack-channel: ${{ vars.SLACK_DEPLOYMENT_ALERT_CHANNEL }} | |
| header-prefix: "${{ steps.info.outputs.repository_name }} ${{ steps.info.outputs.TAG }} 버전 Build & Push" |