-
Notifications
You must be signed in to change notification settings - Fork 0
316 lines (299 loc) · 9.82 KB
/
cicd.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
---
name: CI + CD
on:
push:
branches:
- "**"
env:
DEV_PORT: 50505
STAGING_PORT: 50506
PROD_PORT: 50507
SONAR_PROJECT_KEY: "bas-kirill_muse-project_c40bc999-8826-433b-bb84-8871688b1ab1"
jobs:
openapi-linter:
name: "[OpenAPI] Linter"
runs-on: kiryuxa-1
steps:
- uses: actions/checkout@v1
- name: Run Spectral Linter
run: ./tools/scripts/openapi/runLinter.sh
credentials-check:
name: "[PR] GitGuardian scan"
if: false # or in another case, there will be "Error: Server is not responding as expected."
runs-on: kiryuxa-1
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # fetch all history so multiple commits can be scanned
- name: GitGuardian scan
uses: GitGuardian/ggshield-action@v1
env:
GITHUB_PUSH_BEFORE_SHA: ${{ github.event.before }}
GITHUB_PUSH_BASE_SHA: ${{ github.event.base }}
GITHUB_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
GITGUARDIAN_API_KEY: ${{ secrets.GITGUARDIAN_API_KEY }}
client-linter:
name: "[CLIENT] Linter"
runs-on: kiryuxa-1
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Run linter
run: ./tools/scripts/client/runLinter.sh
client-static-analyzer:
name: "[CLIENT] Static Analyzer"
runs-on: kiryuxa-2
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Install dependencies
run: cd ./client && npm install
- name: Run Static Analyzer
run: ./tools/scripts/client/runStaticAnalyzer.sh
server-linter:
name: "[SERVER] Linter"
runs-on: kiryuxa-2
steps:
- name: Set up JDK 21 (Temurin)
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "21.0"
- name: Checkout Code
uses: actions/checkout@v4
- name: Run linter
run: ./tools/scripts/server/runLinter.sh
server-static-analyzer:
name: "[SERVER] Static Analyzer"
runs-on: kiryuxa-2
steps:
- name: Set up JDK 21 (Temurin)
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "21.0"
- name: Checkout Code
uses: actions/checkout@v4
- name: Run static analyzer
run: ./tools/scripts/server/runStaticAnalyzer.sh
server-sonarqube:
name: "[SERVER] Run SonarQube"
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 17
- name: Run sonarqube
uses: sonarsource/sonarqube-scan-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
SONAR_PROJECT_KEY: ${{ env.SONAR_PROJECT_KEY }}
- name: Wait for quality gate result
run: sleep 5
- uses: phwt/sonarqube-quality-gate-action@v1
id: quality-gate-check
with:
sonar-project-key: "bas-kirill_muse-project_c40bc999-8826-433b-bb84-8871688b1ab1"
sonar-host-url: ${{ secrets.SONAR_HOST_URL }}
sonar-token: ${{ secrets.SONAR_TOKEN }}
github-token: ${{ secrets.GH_TOKEN }}
- name: Output result
run: |
echo "${{ steps.quality-gate-result.outputs.project-status }}"
echo "${{ steps.quality-gate-result.outputs.quality-gate-result }}"
server-unit-tests:
name: "[SERVER] Unit Tests"
runs-on: kiryuxa-3
permissions:
contents: read
issues: read
checks: write
pull-requests: write
steps:
- name: Set up JDK 21 (Temurin)
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "21.0"
- name: Checkout Code
uses: actions/checkout@v4
- name: Run Unit Tests
env:
MUSE_JWT_SECRET_KEY: ${{ secrets.MUSE_JWT_SECRET_KEY }}
run: ./tools/scripts/server/runUnitTests.sh
# - name: Publish Unit Test Results
# if: always()
# uses: EnricoMi/[email protected]
# with:
# files: ./**/**/build/test-results/**/*.xml
# report_individual_runs: true
- name: Gather reports
uses: actions/upload-artifact@v2
if: always()
with:
name: reports
path: ./**/**/build/reports
deploy-dev:
name: "[SERVER] Deploy to Dev"
needs:
- openapi-linter
- client-linter
- client-static-analyzer
- server-linter
- server-static-analyzer
- server-unit-tests
- server-sonarqube
runs-on: ubuntu-22.04
environment:
name: dev
url: http://dev.muse.kiryuxa.com
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Deploy at home lab
run: ./tools/scripts/deploy/deployDev.sh myshx dev
env:
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
SSH_HOST: ${{ secrets.DEV_SSH_HOST }}
SSH_PORT: ${{ secrets.DEV_SSH_PORT }}
SSH_USER: ${{ secrets.DEV_SSH_USER }}
SSH_PASS: ${{ secrets.DEV_SHH_PASS }}
# deploy-staging:
# name: "[SERVER] Deploy to Staging"
# if: github.event.ref == 'refs/heads/main'
# needs:
# - openapi-linter
# - client-linter
# - client-static-analyzer
# - server-linter
# - server-static-analyzer
# - server-unit-tests
# - server-sonarqube
# runs-on: ubuntu-22.04
# environment:
# name: staging
# url: http://staging.muse.kiryuxa.com
# steps:
# - name: Set up JDK 21 (Temurin)
# uses: actions/setup-java@v4
# with:
# distribution: temurin
# java-version: "21.0"
# - name: Check out the repo
# uses: actions/checkout@v4
# - name: Log in to Docker Hub
# run: docker login -u myshx -p ${{ secrets.DOCKER_HUB_TOKEN }}
# - name: Build Server Docker Image
# run: >
# ./tools/scripts/server/buildJar.sh
#
# docker build . -t "myshx/muse-server:staging-${{ github.sha }}" -f ./server/Dockerfile
# - name: Push Server Docker Image
# run: docker push "myshx/muse-server:staging-${{ github.sha }}"
# - name: Run server at home lab
# uses: appleboy/ssh-action@master
# env:
# GIT_COMMIT_SHA: ${{ github.sha }}
# STAGING_PORT: ${{ env.STAGING_PORT }}
# with:
# host: ${{ secrets.SERVER_HOST }}
# username: ${{ secrets.SERVER_USERNAME }}
# password: ${{ secrets.SERVER_PASSWORD }}
# port: ${{ secrets.SERVER_PORT }}
# envs: GIT_COMMIT_SHA, STAGING_PORT
# script: >
# export GIT_COMMIT_SHA=$GIT_COMMIT_SHA
#
# export STAGING_PORT=$STAGING_PORT
#
#
# staging_container_ids=$(docker inspect --format='{{.Config.Image}} {{.Id}}' $(docker ps -aq) | grep -E 'myshx/muse-server:staging-\b[0-9a-f]{40}\b' | awk '{print $2}')
#
# staging_image_ids=$(docker inspect --format='{{.Config.Image}} {{.Image}}' $(docker ps -aq) | grep -E 'myshx/muse-server:staging-\b[0-9a-f]{40}\b' | awk '{print $2}')
#
#
# for container_id in $staging_container_ids; do
# docker stop "$container_id"
# done
#
#
# for container_id in $staging_container_ids; do
# docker rm "$container_id"
# done
#
#
# for image_id in $staging_image_ids; do
# docker rmi -f "$image_id";
# done
#
#
# docker run -d -p $STAGING_PORT:8080 "myshx/muse-server:staging-$GIT_COMMIT_SHA"
# deploy-prod:
# name: "[SERVER] Deploy to Prod"
# needs:
# - deploy-staging
# runs-on: ubuntu-22.04
# environment:
# name: prod
# url: http://prod.muse.kiryuxa.com
# steps:
# - name: Set up JDK 21 (Temurin)
# uses: actions/setup-java@v4
# with:
# distribution: temurin
# java-version: "21.0"
# - name: Check out the repo
# uses: actions/checkout@v4
# - name: Log in to Docker Hub
# run: docker login -u myshx -p ${{ secrets.DOCKER_HUB_TOKEN }}
# - name: Build Server Docker Image
# run: >
# ./tools/scripts/server/buildJar.sh
#
# docker build . -t "myshx/muse-server:prod-${{ github.sha }}" -f ./server/Dockerfile
# - name: Push Server Docker Image
# run: docker push "myshx/muse-server:prod-${{ github.sha }}"
# - name: Run server at home lab
# uses: appleboy/ssh-action@master
# env:
# GIT_COMMIT_SHA: ${{ github.sha }}
# PROD_PORT: ${{ env.PROD_PORT }}
# with:
# host: ${{ secrets.SERVER_HOST }}
# username: ${{ secrets.SERVER_USERNAME }}
# password: ${{ secrets.SERVER_PASSWORD }}
# port: ${{ secrets.SERVER_PORT }}
# envs: GIT_COMMIT_SHA, PROD_PORT
# script: >
# export GIT_COMMIT_SHA=$GIT_COMMIT_SHA
#
# export PROD_PORT=$PROD_PORT
#
#
# prod_container_ids=$(docker inspect --format='{{.Config.Image}} {{.Id}}' $(docker ps -aq) | grep -E 'myshx/muse-server:prod-\b[0-9a-f]{40}\b' | awk '{print $2}')
#
# prod_image_ids=$(docker inspect --format='{{.Config.Image}} {{.Image}}' $(docker ps -aq) | grep -E 'myshx/muse-server:prod-\b[0-9a-f]{40}\b' | awk '{print $2}')
#
#
# for container_id in $prod_container_ids; do
# docker stop "$container_id"
# done
#
#
# for container_id in $prod_container_ids; do
# docker rm "$container_id"
# done
#
#
# for image_id in $prod_image_ids; do
# docker rmi -f "$image_id";
# done
#
#
# docker run -d -p $PROD_PORT:8080 "myshx/muse-server:prod-$GIT_COMMIT_SHA"