From 7bf7255ceb6fe20c0204a033720a1536a3deaba6 Mon Sep 17 00:00:00 2001 From: gideok Kim Date: Tue, 15 Apr 2025 23:45:22 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20DevOps=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EB=B0=B0=ED=8F=AC=ED=95=A0=20=EC=88=98=20=EC=9E=88=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20workflow=20=EC=A0=84=EB=8B=AC=20=EB=A1=9C=EC=A7=81?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../workflows/upload_docker_image_to_acr.yml | 42 ++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/.github/workflows/upload_docker_image_to_acr.yml b/.github/workflows/upload_docker_image_to_acr.yml index 8bce0ff..7d10ac1 100644 --- a/.github/workflows/upload_docker_image_to_acr.yml +++ b/.github/workflows/upload_docker_image_to_acr.yml @@ -1,4 +1,4 @@ -name: Build and Push Backend Image to ACR +name: Build, Push Backend Image to ACR and Trigger Deployment # 워크플로우 트리거 설정 on: @@ -9,6 +9,8 @@ on: jobs: build-and-push: runs-on: ubuntu-latest # 실행 환경 지정 + outputs: + image_tag: ${{ steps.set_image_tag.outputs.image_tag }} steps: # 1. 소스 코드 체크아웃 - name: Checkout repository @@ -58,4 +60,40 @@ jobs: echo "${{ steps.meta.outputs.tags }}" echo "Checking image in ACR..." echo "Basic tag information:" - az acr repository show-tags --name ${{ secrets.ACR_LOGIN_SERVER }} --repository ${{ github.ref == 'refs/heads/dev' && secrets.ACR_REPOSITORY_NAME_TEST || secrets.ACR_REPOSITORY_NAME }} --output table \ No newline at end of file + az acr repository show-tags --name ${{ secrets.ACR_LOGIN_SERVER }} --repository ${{ github.ref == 'refs/heads/dev' && secrets.ACR_REPOSITORY_NAME_TEST || secrets.ACR_REPOSITORY_NAME }} --output table + + # 7. 다음 job에서 사용할 이미지 태그 설정 (SHA 태그 사용!) + - name: Set Image Tag Output (Using SHA) + id: set_image_tag # job outputs에서 참조하는 id와 일치해야 함 + run: | + # metadata-action 출력에서 SHA 태그 추출 + SHA_TAG=$(echo "${{ steps.meta.outputs.tags }}" | grep -oE '[a-f0-9]{7,40}' | head -n 1) + if [[ -z "$SHA_TAG" ]]; then + echo "Error: Could not extract SHA tag from metadata outputs." + exit 1 + fi + # 조건부 리포지토리 이름 다시 확인 + if [[ "${{ github.ref_name }}" == "main" ]]; then + ACR_REPO_NAME_FOR_OUTPUT="${{ secrets.ACR_REPOSITORY_NAME }}" + else # dev 또는 기타 + ACR_REPO_NAME_FOR_OUTPUT="${{ secrets.ACR_REPOSITORY_NAME_TEST }}" + fi + FULL_TAG="${{ secrets.ACR_LOGIN_SERVER }}/$ACR_REPO_NAME_FOR_OUTPUT:$SHA_TAG" + echo "Outputting image tag for deployment: $FULL_TAG" + echo "image_tag=$FULL_TAG" >> $GITHUB_OUTPUT + + call-deploy-workflow: + name: Trigger ACA Deployment + needs: build-and-push + runs-on: ubuntu-latest + # main 또는 dev 브랜치에 push될 때만 배포 실행 + if: github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'dev') + + steps: + - name: Call Reusable Deployment Workflow + uses: 9git9git/9git-devops/.github/workflows/deploy_to_aca.yml@main + with: + image_tag: ${{ needs.build-and-push.outputs.image_tag }} + target_environment: ${{ (github.ref_name == 'main' && 'production') || 'test' }} + app_type: 'backend' + secrets: inherit