1- name : Build and Push Backend Image to ACR
1+ name : Build, Push Backend Image to ACR and Trigger Deployment
22
33# ์ํฌํ๋ก์ฐ ํธ๋ฆฌ๊ฑฐ ์ค์
44on :
99jobs :
1010 build-and-push :
1111 runs-on : ubuntu-latest # ์คํ ํ๊ฒฝ ์ง์
12+ outputs :
13+ image_tag : ${{ steps.set_image_tag.outputs.image_tag }}
1214 steps :
1315 # 1. ์์ค ์ฝ๋ ์ฒดํฌ์์
1416 - name : Checkout repository
5860 echo "${{ steps.meta.outputs.tags }}"
5961 echo "Checking image in ACR..."
6062 echo "Basic tag information:"
61- 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
63+ 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
64+
65+ # 7. ๋ค์ job์์ ์ฌ์ฉํ ์ด๋ฏธ์ง ํ๊ทธ ์ค์ (SHA ํ๊ทธ ์ฌ์ฉ!)
66+ - name : Set Image Tag Output (Using SHA)
67+ id : set_image_tag # job outputs์์ ์ฐธ์กฐํ๋ id์ ์ผ์นํด์ผ ํจ
68+ run : |
69+ # metadata-action ์ถ๋ ฅ์์ SHA ํ๊ทธ ์ถ์ถ
70+ SHA_TAG=$(echo "${{ steps.meta.outputs.tags }}" | grep -oE '[a-f0-9]{7,40}' | head -n 1)
71+ if [[ -z "$SHA_TAG" ]]; then
72+ echo "Error: Could not extract SHA tag from metadata outputs."
73+ exit 1
74+ fi
75+ # ์กฐ๊ฑด๋ถ ๋ฆฌํฌ์งํ ๋ฆฌ ์ด๋ฆ ๋ค์ ํ์ธ
76+ if [[ "${{ github.ref_name }}" == "main" ]]; then
77+ ACR_REPO_NAME_FOR_OUTPUT="${{ secrets.ACR_REPOSITORY_NAME }}"
78+ else # dev ๋๋ ๊ธฐํ
79+ ACR_REPO_NAME_FOR_OUTPUT="${{ secrets.ACR_REPOSITORY_NAME_TEST }}"
80+ fi
81+ FULL_TAG="${{ secrets.ACR_LOGIN_SERVER }}/$ACR_REPO_NAME_FOR_OUTPUT:$SHA_TAG"
82+ echo "Outputting image tag for deployment: $FULL_TAG"
83+ echo "image_tag=$FULL_TAG" >> $GITHUB_OUTPUT
84+
85+ call-deploy-workflow :
86+ name : Trigger ACA Deployment
87+ needs : build-and-push
88+ runs-on : ubuntu-latest
89+ # main ๋๋ dev ๋ธ๋์น์ push๋ ๋๋ง ๋ฐฐํฌ ์คํ
90+ if : github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'dev')
91+
92+ steps :
93+ - name : Call Reusable Deployment Workflow
94+ uses : 9git9git/9git-devops/.github/workflows/deploy_to_aca.yml@main
95+ with :
96+ image_tag : ${{ needs.build-and-push.outputs.image_tag }}
97+ target_environment : ${{ (github.ref_name == 'main' && 'production') || 'test' }}
98+ app_type : ' backend'
99+ secrets : inherit
0 commit comments