Skip to content

Commit 7bf7255

Browse files
committed
๐Ÿš€ DevOps์—์„œ ๋ฐฐํฌํ•  ์ˆ˜ ์žˆ๋„๋ก workflow ์ „๋‹ฌ ๋กœ์ง ์ถ”๊ฐ€
1 parent 34367ed commit 7bf7255

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

โ€Ž.github/workflows/upload_docker_image_to_acr.ymlโ€Ž

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and Push Backend Image to ACR
1+
name: Build, Push Backend Image to ACR and Trigger Deployment
22

33
# ์›Œํฌํ”Œ๋กœ์šฐ ํŠธ๋ฆฌ๊ฑฐ ์„ค์ •
44
on:
@@ -9,6 +9,8 @@ on:
99
jobs:
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
@@ -58,4 +60,40 @@ jobs:
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

Comments
ย (0)