fix:오류 수정 (#261) #7
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 | |
| env: | |
| IMAGE_NAME: tt_backend | |
| on: | |
| push: | |
| paths: | |
| - ".github/workflows/**" | |
| - "src/**" | |
| - "build.gradle.kts" | |
| - "Dockerfile" | |
| branches: | |
| - develop | |
| # 권한 최소화/명시화 | |
| permissions: | |
| contents: write | |
| packages: write | |
| jobs: | |
| makeTagAndRelease: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| tag_name: ${{ steps.create_tag.outputs.new_tag }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Create Tag | |
| id: create_tag | |
| uses: mathieudutour/github-tag-action@v6.2 | |
| with: | |
| github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | |
| - name: Create Release | |
| id: create_release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | |
| with: | |
| tag_name: ${{ steps.create_tag.outputs.new_tag }} | |
| release_name: Release ${{ steps.create_tag.outputs.new_tag }} | |
| body: ${{ steps.create_tag.outputs.changelog }} | |
| draft: false | |
| prerelease: false | |
| buildImageAndPush: | |
| name: 도커 이미지 빌드와 푸시 | |
| needs: makeTagAndRelease | |
| runs-on: ubuntu-latest | |
| outputs: | |
| owner_lc: ${{ steps.export_owner.outputs.owner_lc }} | |
| image_name: ${{ steps.export_image.outputs.image_name }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Docker Buildx 설치 | |
| uses: docker/setup-buildx-action@v2 | |
| - name: 레지스트리 로그인 | |
| uses: docker/login-action@v2 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | |
| - name: set lower case owner name | |
| id: export_owner | |
| run: | | |
| # OWNER_LC="${GITHUB_REPOSITORY_OWNER,,}" | |
| OWNER_LC="chehyeon-kim23" # 본인 아이디를 소문자로 직접 입력 | |
| echo "owner_lc=$OWNER_LC" >> $GITHUB_OUTPUT | |
| - name: export image name | |
| id: export_image | |
| run: echo "image_name=tt_backend" >> $GITHUB_OUTPUT | |
| - name: 빌드 앤 푸시 | |
| uses: docker/build-push-action@v3 | |
| with: | |
| context: . | |
| push: true | |
| build-args: | | |
| DOPPLER_TOKEN=${{ secrets.DOPPLER_TOKEN }} | |
| cache-from: type=registry,ref=ghcr.io/${{ steps.export_owner.outputs.owner_lc }}/${{ steps.export_image.outputs.image_name }}:cache | |
| cache-to: type=registry,ref=ghcr.io/${{ steps.export_owner.outputs.owner_lc }}/${{ steps.export_image.outputs.image_name }}:cache,mode=max | |
| tags: | | |
| ghcr.io/${{ steps.export_owner.outputs.owner_lc }}/${{ steps.export_image.outputs.image_name }}:${{ needs.makeTagAndRelease.outputs.tag_name }}, | |
| ghcr.io/${{ steps.export_owner.outputs.owner_lc }}/${{ steps.export_image.outputs.image_name }}:latest | |
| deploy: | |
| runs-on: ubuntu-latest | |
| needs: [ buildImageAndPush ] | |
| steps: | |
| - uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-region: ${{ secrets.AWS_REGION }} | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| - name: 인스턴스 ID 가져오기 | |
| id: get_instance_id | |
| run: | | |
| INSTANCE_ID=$(aws ec2 describe-instances --filters "Name=tag:Name,Values=waitfair-ec2-1" "Name=instance-state-name,Values=running" --query "Reservations[].Instances[].InstanceId" --output text) | |
| echo "INSTANCE_ID=$INSTANCE_ID" >> $GITHUB_ENV | |
| - name: AWS SSM Send-Command | |
| uses: peterkimzz/aws-ssm-send-command@master | |
| id: ssm | |
| with: | |
| aws-region: ${{ secrets.AWS_REGION }} | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| instance-ids: ${{ env.INSTANCE_ID }} | |
| comment: Deploy Spring Boot with Prod Profile | |
| command: | | |
| # 1. 찾은 경로로 이동 | |
| cd /dockerProjects/tt-src/WEB7_9_B2ST_BE/docker/ | |
| # 2. GHCR 로그인 (이미지 pull 권한 확인) | |
| echo "${{ secrets.PERSONAL_ACCESS_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
| # 3. 최신 이미지 가져오기 | |
| docker compose pull | |
| # 4. 컨테이너 재시작 (변경사항 반영) | |
| docker compose up -d | |
| # 5. 미사용 이미지 정리 | |
| docker image prune -f |