-
Notifications
You must be signed in to change notification settings - Fork 0
104 lines (87 loc) · 3.25 KB
/
deploy.yml
File metadata and controls
104 lines (87 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
name: Deploy and Update GitOps Repo
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
pull-requests: write
steps:
- name: Start Timer
run: echo "START_TIME=$(date +%s)" >> $GITHUB_ENV
- name: Checkout source repo
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Build and push Docker image
run: |
IMAGE_NAME=ghcr.io/${{ github.repository_owner }}/blog
IMAGE_TAG=$(date +%Y%m%d%H%M%S)
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
docker build -t $IMAGE_NAME:$IMAGE_TAG .
docker push $IMAGE_NAME:$IMAGE_TAG
- name: Checkout GitOps repo
uses: actions/checkout@v4
with:
repository: cobocho/gitops
token: ${{ secrets.GITOPS_REPO_ACCESS }}
path: gitops
- name: Update image tag in GitOps repo
run: |
cd gitops
FILE=./blog/blog-deploy.yaml
IMAGE_NAME=ghcr.io/cobocho/blog
sed -i "s|$IMAGE_NAME:.*|$IMAGE_NAME:${{ env.IMAGE_TAG }}|g" $FILE
- name: Create Pull Request to GitOps repo
id: cpr
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITOPS_REPO_ACCESS }}
path: gitops
commit-message: 'chore: update blog image tag to ${{ env.IMAGE_TAG }}'
branch: update/image-${{ env.IMAGE_TAG }}
title: 'Update blog image tag to ${{ env.IMAGE_TAG }}'
body: |
This PR updates the image tag in \`blog-deploy.yaml\` to \`${{ env.IMAGE_TAG }}\`.
- name: Calculate Elapsed Time
run: echo "ELAPSED_TIME=$(($(date +%s) - $START_TIME))" >> $GITHUB_ENV
if: always()
- name: Send Discord Notification (Success)
if: success()
uses: Ilshidur/action-discord@master
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL }}
with:
args: |
✅ **undefined.dev 컨테이너 업로드 완료!**
- ⏱ 소요 시간: `${{ env.ELAPSED_TIME }}`초
- 🔗 [Workflow](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
- 🔗 [Pull Request](${{ steps.cpr.outputs.pull-request-url }})
- name: Send Discord Notification (Failed)
if: failure()
uses: Ilshidur/action-discord@master
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL }}
with:
args: |
❌ **undefined.dev 컨테이너 업로드 실패!**
- 브랜치: `main`
- ⏱ 소요 시간: `${{ env.ELAPSED_TIME }}`초
- 🔗 [Workflow](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})