-
Notifications
You must be signed in to change notification settings - Fork 5
166 lines (149 loc) · 4.94 KB
/
backend_cd.yml
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
name: Backend CD
on:
workflow_dispatch:
push:
branches:
- main
paths:
- backend/**
env:
ARTIFACT_NAME: develup-0.0.1-SNAPSHOT
ARTIFACT_DIRECTORY: ./backend/build/libs
jobs:
build:
name: 🏗️ Build Jar and Upload Artifact
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: 🏗️ Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: 21
- name: 🏗️ Set up Gradle
uses: gradle/actions/setup-gradle@v3
- name: 🏗️ Build with Gradle
run: |
cd backend
./gradlew clean bootJar
- name: 📤 Upload Artifact File
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.ARTIFACT_DIRECTORY }}/${{ env.ARTIFACT_NAME }}.jar
deploy:
name: 🚀 Server Deployment
needs: build
runs-on: self-hosted
steps:
- name: 📥 Download Artifact File
uses: actions/download-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.ARTIFACT_DIRECTORY }}
- name: 🔴 Stop Server
run: |
PID=$(sudo lsof -t -i:8080 || true)
if [ -n "$PID" ]; then
sudo kill -15 $PID
tail --pid=$PID -f /dev/null
echo "Server has been stopped. PID: $PID"
else
echo "No server is running."
fi
- name: 🟢 Start Server
run: |
sudo nohup java \
-Dauth.github.client-id=${{ secrets.CLIENT_ID_GITHUB }} \
-Dauth.github.client-secret=${{ secrets.CLIENT_SECRET_GITHUB }} \
-Dspring.profiles.active=dev \
-Dserver.port=8080 \
-jar ${{ env.ARTIFACT_DIRECTORY }}/${{ env.ARTIFACT_NAME }}.jar &
slack-notify_success:
runs-on: ubuntu-latest
needs:
- build
- deploy
if: success()
steps:
- name: Extract Commit Title
run: |
COMMIT_TITLE=$(echo "${{ github.event.head_commit.message }}" | head -n 1)
echo "COMMIT_TITLE=$COMMIT_TITLE" >> $GITHUB_ENV
- name: Build and Deploy Success
uses: slackapi/[email protected]
with:
channel-id: ${{ secrets.ISSUE_CHANNEL }}
payload: |
{
"text": "Build and Deploy Status",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "<!channel> \n 📣 Server Build & Deploy 결과를 안내 드립니다. 📣 \n\t • 🚀 Build Success \n\t • 🟢 Deploy Success \n\t • 🏷️ 관련 Commit: <${{ github.event.head_commit.url }}|${{ env.COMMIT_TITLE }}>"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
slack-notify_build-fail:
runs-on: ubuntu-latest
needs:
- build
if: failure()
steps:
- name: Extract Commit Title
run: |
COMMIT_TITLE=$(echo "${{ github.event.head_commit.message }}" | head -n 1)
echo "COMMIT_TITLE=$COMMIT_TITLE" >> $GITHUB_ENV
- name: Build Fail
uses: slackapi/[email protected]
with:
channel-id: ${{ secrets.ISSUE_CHANNEL }}
payload: |
{
"text": "Build and Deploy Status",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "<!channel> \n 📣 Server Build & Deploy 결과를 안내 드립니다. 📣 \n\t • 🔴 Build Fail \n\t • 🏷️ 관련 Commit: <${{ github.event.head_commit.url }}|${{ env.COMMIT_TITLE }}>"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
slack-notify_deploy-fail:
runs-on: ubuntu-latest
needs:
- deploy
if: failure()
steps:
- name: Extract Commit Title
run: |
COMMIT_TITLE=$(echo "${{ github.event.head_commit.message }}" | head -n 1)
echo "COMMIT_TITLE=$COMMIT_TITLE" >> $GITHUB_ENV
- name: Deploy Fail
uses: slackapi/[email protected]
with:
channel-id: ${{ secrets.ISSUE_CHANNEL }}
payload: |
{
"text": "Build and Deploy Status",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "<!channel> \n 📣 Server Build & Deploy 결과를 안내 드립니다. 📣 \n\t • 🚀Build Success \n\t • 🔴Deploy Fail \n\t • 🏷️ 관련 Commit: <${{ github.event.head_commit.url }}|${{ env.COMMIT_TITLE }}>"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.BOT_TOKEN }}