Dev - CD (Deploy) #118
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: Dev - CD (Deploy) | |
| on: | |
| workflow_run: | |
| workflows: [ "Dev - CI (Build & Push)" ] | |
| types: [ completed ] | |
| permissions: | |
| packages: read | |
| jobs: | |
| deploy: | |
| # CI가 성공했을 때만 실행 | |
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| runs-on: [self-hosted] | |
| # [설정] GitHub Environment의 'development' 변수들(32124 포트 등)을 사용 | |
| environment: | |
| name: development | |
| steps: | |
| # CI에서 넘겨준 이미지 태그 파일 다운로드 | |
| - name: Download Image Tag Artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: image-tag | |
| github-token: ${{ secrets.ACTION_TOKEN }} | |
| run-id: ${{ github.event.workflow_run.id }} | |
| - name: Read Image Tag | |
| id: get-tag | |
| run: echo "IMAGE_TAG=$(head -n 1 image_tag.txt)" >> $GITHUB_OUTPUT | |
| - name: Login to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.ACTION_TOKEN }} | |
| - name: Pull latest image | |
| run: docker pull ${{ steps.get-tag.outputs.IMAGE_TAG }} | |
| - name: Clean up old container | |
| run: | | |
| docker rm -f ${{ secrets.CONTAINER_NAME }} || true | |
| docker image prune -f | |
| - name: Run New Container (Dev) | |
| run: | | |
| docker run -d \ | |
| --name ${{ secrets.CONTAINER_NAME }} \ | |
| --network ${{ secrets.NETWORK_NAME }} \ | |
| -p ${{ secrets.WEB_PORT }}:8080 \ | |
| -e SPRING_PROFILES_ACTIVE=dev \ | |
| -e TZ=Asia/Seoul \ | |
| ${{ steps.get-tag.outputs.IMAGE_TAG }} |