44 push :
55 branches :
66 - main
7- paths :
8- - ' Dockerfile'
9- - ' apps/blog/**'
10- - ' .github/workflows/deploy.yml'
117
128jobs :
13- build-and-push :
9+ deploy :
1410 runs-on : ubuntu-latest
1511
1612 permissions :
1713 contents : write
1814 packages : write
19-
20- outputs :
21- image_tag : ${{ steps.set-tag.outputs.image_tag }}
15+ pull-requests : write
2216
2317 steps :
2418 - name : Start Timer
2721 - name : Checkout source repo
2822 uses : actions/checkout@v4
2923
30- - name : Setup pnpm store cache
31- uses : actions/cache@v4
32- with :
33- path : ~/.pnpm-store
34- key : ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
35- restore-keys : |
36- ${{ runner.os }}-pnpm-store-
37-
3824 - name : Install pnpm
3925 uses : pnpm/action-setup@v2
4026 with :
@@ -49,37 +35,20 @@ jobs:
4935 - name : Install dependencies
5036 run : pnpm install
5137
52- - name : Set image tag
53- id : set-tag
54- run : echo "image_tag=$(date +%Y%m%d%H%M%S)" >> $GITHUB_OUTPUT
55-
5638 - name : Set up Docker Buildx
5739 uses : docker/setup-buildx-action@v3
5840
5941 - name : Login to GHCR
6042 run : echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
6143
62- - name : Build and push Docker image with cache
63- uses : docker/build-push-action@v5
64- with :
65- context : .
66- push : true
67- tags : ghcr.io/${{ github.repository_owner }}/blog:${{ steps.set-tag.outputs.image_tag }}
68- cache-from : type=gha
69- cache-to : type=gha,mode=max
70-
71- update-gitops :
72- runs-on : ubuntu-latest
73- needs : build-and-push
74-
75- permissions :
76- contents : write
77- pull-requests : write
78-
79- outputs :
80- pr_url : ${{ steps.cpr.outputs.pull-request-url }}
44+ - name : Build and push Docker image
45+ run : |
46+ IMAGE_NAME=ghcr.io/${{ github.repository_owner }}/blog
47+ IMAGE_TAG=$(date +%Y%m%d%H%M%S)
48+ echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
49+ docker build -t $IMAGE_NAME:$IMAGE_TAG .
50+ docker push $IMAGE_NAME:$IMAGE_TAG
8151
82- steps :
8352 - name : Checkout GitOps repo
8453 uses : actions/checkout@v4
8554 with :
@@ -88,46 +57,30 @@ jobs:
8857 path : gitops
8958
9059 - name : Update image tag in GitOps repo
91- id : update-tag
9260 run : |
9361 cd gitops
9462 FILE=./blog/blog-deploy.yaml
9563 IMAGE_NAME=ghcr.io/cobocho/blog
96- OLD_TAG=$(grep "$IMAGE_NAME" $FILE | sed 's/.*://')
97- NEW_TAG=${{ needs.build-and-push.outputs.image_tag }}
98- if [ "$OLD_TAG" = "$NEW_TAG" ]; then
99- echo "No change in tag. Skipping PR."
100- echo "skip_pr=true" >> $GITHUB_OUTPUT
101- exit 0
102- fi
103- sed -i "s|$IMAGE_NAME:.*|$IMAGE_NAME:$NEW_TAG|g" $FILE
104- echo "skip_pr=false" >> $GITHUB_OUTPUT
105-
106- - name : Create Pull Request
107- if : steps.update-tag.outputs.skip_pr == 'false'
64+ sed -i "s|$IMAGE_NAME:.*|$IMAGE_NAME:${{ env.IMAGE_TAG }}|g" $FILE
65+
66+ - name : Create Pull Request to GitOps repo
10867 id : cpr
10968 uses : peter-evans/create-pull-request@v6
11069 with :
11170 token : ${{ secrets.GITOPS_REPO_ACCESS }}
11271 path : gitops
113- commit-message : ' chore: update blog image tag to ${{ needs.build-and-push.outputs.image_tag }}'
114- branch : update/image-${{ needs.build-and-push.outputs.image_tag }}
115- title : ' Update blog image tag to ${{ needs.build-and-push.outputs.image_tag }}'
72+ commit-message : ' chore: update blog image tag to ${{ env.IMAGE_TAG }}'
73+ branch : update/image-${{ env.IMAGE_TAG }}
74+ title : ' Update blog image tag to ${{ env.IMAGE_TAG }}'
11675 body : |
117- This PR updates the image tag in \`blog-deploy.yaml\` to \`${{ needs.build-and-push.outputs.image_tag }}\`.
118-
119- notify :
120- runs-on : ubuntu-latest
121- needs : [build-and-push, update-gitops]
76+ This PR updates the image tag in \`blog-deploy.yaml\` to \`${{ env.IMAGE_TAG }}\`.
12277
123- if : always()
124-
125- steps :
12678 - name : Calculate Elapsed Time
12779 run : echo "ELAPSED_TIME=$(($(date +%s) - $START_TIME))" >> $GITHUB_ENV
80+ if : always()
12881
12982 - name : Send Discord Notification (Success)
130- if : ${{ success() }}
83+ if : success()
13184 uses : Ilshidur/action-discord@master
13285 env :
13386 DISCORD_WEBHOOK : ${{ secrets.DISCORD_WEBHOOK_URL }}
@@ -136,10 +89,10 @@ jobs:
13689 ✅ **undefined.dev 컨테이너 업로드 완료!**
13790 - ⏱ 소요 시간: `${{ env.ELAPSED_TIME }}`초
13891 - 🔗 [Workflow](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
139- - 🔗 [Pull Request](${{ needs.update-gitops .outputs.pr_url }})
92+ - 🔗 [Pull Request](${{ steps.cpr .outputs.pull-request-url }})
14093
14194 - name : Send Discord Notification (Failed)
142- if : ${{ failure() }}
95+ if : failure()
14396 uses : Ilshidur/action-discord@master
14497 env :
14598 DISCORD_WEBHOOK : ${{ secrets.DISCORD_WEBHOOK_URL }}
0 commit comments