-
Notifications
You must be signed in to change notification settings - Fork 1
337 lines (305 loc) · 12.6 KB
/
CI-CD.yaml
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
name: Deploy to Google Cloud VM
on:
push:
branches:
- main
paths-ignore:
- 'ReadMe.md'
- 'epoch_tests_results/**'
- 'epoch_tests_results/*'
- 'epoch_tests_results/'
- 'epoch_tests_results'
- 'epoch_project_documents/**'
- 'epoch_project_documents/*'
- 'epoch_project_documents/'
- 'epoch_project_documents'
jobs:
security-scan:
permissions: write-all
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args:
-Dsonar.projectKey=Aymanhki_Epoch
-Dsonar.organization=aymanhki
local-test-new-build:
runs-on: ubuntu-latest
permissions: write-all
needs: security-scan
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Install SSH Client and sshpass
run: |
sudo apt-get update
sudo apt-get install -y openssh-client sshpass
- name: SSH into Google Cloud VM for testing
run: |
set -e
sshpass -p ${{ secrets.TESTER_SSH_PASSWORD }} ssh -t -o StrictHostKeyChecking=no ${{ secrets.TESTER_SSH_USERNAME }} << EOF
echo "Current directory path: $(pwd)"
cd
rm -rf Epoch
git clone https://github.com/Aymanhki/Epoch.git
cd
cp credentials/db_params.json Epoch/epoch_backend/assets/
cp credentials/virtual-bonito-412515-d7dae3104a12.json Epoch/epoch_backend/assets/
cp credentials/fullchain.pem Epoch/epoch_backend/assets/
cp credentials/privkey.pem Epoch/epoch_backend/assets/
cp credentials/db_params.json Epoch/epoch_frontend/
cp credentials/virtual-bonito-412515-d7dae3104a12.json Epoch/epoch_frontend/
cp credentials/fullchain.pem Epoch/epoch_frontend/
cp credentials/privkey.pem Epoch/epoch_frontend/
cd Epoch/epoch_frontend/
npm install
cd ..
pkill selenium
pkill chromedriver
pkill geckodriver
pkill firefox
export CI=true
if ! pytest --cov=epoch_backend -rA --color=yes --disable-warnings --disable-pytest-warnings --show-capture=no ./epoch_backend/tests/integration_tests.py ./epoch_backend/tests/webserver_tests.py ./epoch_backend/tests/following_unit_tests.py; then
echo "Webserver Backend Test(s) failed. Exiting with status 1."
exit 1
fi
sudo fuser -k -n tcp 443
sudo fuser -k -n tcp 8080
sudo fuser -k -n tcp 80
sudo fuser -k -n tcp 8000
lsof -t -i:8080 | xargs kill -9
lsof -t -i:80 | xargs kill -9
lsof -t -i:443 | xargs kill -9
lsof -t -i:8000 | xargs kill -9
cd epoch_frontend/
if ! npm test; then
echo "Frontend server Test(s) failed. Exiting with status 1."
exit 1
fi
exit 0
EOF
clean-old-build:
needs: local-test-new-build
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Install SSH Client and sshpass
run: |
sudo apt-get update
sudo apt-get install -y openssh-client sshpass
- name: SSH into Google Cloud VM for cleanup
run: |
sshpass -p ${{ secrets.SSH_PASSWORD }} ssh -t -o StrictHostKeyChecking=no ${{ secrets.SSH_USERNAME }} << EOF
echo "Current directory path: $(pwd)"
cd
rm -rf Epoch
sudo fuser -k -n tcp 443
sudo fuser -k -n tcp 8080
sudo fuser -k -n tcp 80
sudo fuser -k -n tcp 8000
docker stop \$(docker ps -q)
docker rm \$(docker ps -aq)
docker rmi \$(docker images -q)
git clone https://github.com/Aymanhki/Epoch.git
cd
cp credentials/db_params.json Epoch/epoch_backend/assets/
cp credentials/virtual-bonito-412515-d7dae3104a12.json Epoch/epoch_backend/assets/
cp credentials/fullchain.pem Epoch/epoch_backend/assets/
cp credentials/privkey.pem Epoch/epoch_backend/assets/
cp credentials/db_params.json Epoch/epoch_frontend/assets/
cp credentials/virtual-bonito-412515-d7dae3104a12.json Epoch/epoch_frontend/assets/
cp credentials/fullchain.pem Epoch/epoch_frontend/
cp credentials/privkey.pem Epoch/epoch_frontend/
cd
cp credentials/get_version.sh Epoch/epoch_backend/
cp credentials/get_version.sh Epoch/epoch_frontend/
exit
EOF
deploy-new-build:
permissions: write-all
needs: clean-old-build
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Install SSH Client and sshpass
run: |
sudo apt-get update
sudo apt-get install -y openssh-client sshpass
- name: Get Docker Version for Backend
id: get_version_backend
run: |
version="v2.0.9"
latest_tag=$(curl -s "https://registry.hub.docker.com/v2/repositories/$DOCKER_USERNAME/epoch_frontend/tags/?page_size=1" | jq -r '.results[0].name')
if [ -z "$latest_tag" ]; then
version="v2.0.9"
elif [ "$latest_tag" == "latest" ]; then
version="v2.0.9"
else
major=$(echo "$latest_tag" | awk -F '.' '{print $1}')
minor=$(echo "$latest_tag" | awk -F '.' '{print $2}')
patch=$(echo "$latest_tag" | awk -F '.' '{print $3}')
major=$(echo $major | sed 's/v//')
new_patch=0
new_minor=0
new_major=0
if [ "$patch" -lt 9 ]; then
new_patch=$((patch+1))
version="v$major.$minor.$new_patch"
else
new_patch=0
if [ "$minor" -lt 9 ]; then
new_minor=$((minor+1))
version="v$major.$new_minor.$new_patch"
else
new_minor=0
new_major=$((major+1))
version="v$new_major.$new_minor.$new_patch"
fi
fi
fi
echo "::set-output name=version::$version"
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
- name: Get Docker Version for Frontend
id: get_version_frontend
run: |
version="v2.0.9"
latest_tag=$(curl -s "https://registry.hub.docker.com/v2/repositories/$DOCKER_USERNAME/epoch_frontend/tags/?page_size=1" | jq -r '.results[0].name')
if [ -z "$latest_tag" ]; then
version="v2.0.9"
elif [ "$latest_tag" == "latest" ]; then
version="v2.0.9"
else
major=$(echo "$latest_tag" | awk -F '.' '{print $1}')
minor=$(echo "$latest_tag" | awk -F '.' '{print $2}')
patch=$(echo "$latest_tag" | awk -F '.' '{print $3}')
major=$(echo $major | sed 's/v//')
new_patch=0
new_minor=0
new_major=0
if [ "$patch" -lt 9 ]; then
new_patch=$((patch+1))
version="v$major.$minor.$new_patch"
else
new_patch=0
if [ "$minor" -lt 9 ]; then
new_minor=$((minor+1))
version="v$major.$new_minor.$new_patch"
else
new_minor=0
new_major=$((major+1))
version="v$new_major.$new_minor.$new_patch"
fi
fi
fi
echo "::set-output name=version::$version"
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
- name: Is This Major Version
id: is_major
run: |
major=$(echo "${{ steps.get_version_frontend.outputs.version }}" | awk -F '.' '{print $1}')
minor=$(echo "${{ steps.get_version_frontend.outputs.version }}" | awk -F '.' '{print $2}')
patch=$(echo "${{ steps.get_version_frontend.outputs.version }}" | awk -F '.' '{print $3}')
major=$(echo $major | sed 's/v//')
if [ "$patch" -eq 0 ] && [ "$minor" -eq 0 ]; then
echo "This is a major version"
echo "::set-output name=is_major::true"
else
echo "This is not a major version"
echo "::set-output name=is_major::false"
fi
- name: Create Release
if: always()
uses: actions/create-release@v1
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_version_backend.outputs.version }}
release_name: ${{ steps.get_version_backend.outputs.version }}
- name: Deploying Backend (Build and Run Backend Docker Container)
run: |
sshpass -p ${{ secrets.SSH_PASSWORD }} ssh -t -o StrictHostKeyChecking=no ${{ secrets.SSH_USERNAME }} << EOF
echo "Current directory path: $(pwd)"
cd
cd Epoch/epoch_backend/
echo "Version for backend Docker image: $VERSION"
docker build -t epoch_backend:$VERSION ./
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
docker tag epoch_backend:$VERSION $DOCKER_USERNAME/epoch_backend:$VERSION
docker push $DOCKER_USERNAME/epoch_backend:$VERSION
docker run -d -p 8080:8080 epoch_backend:$VERSION
exit
EOF
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
VERSION: ${{ steps.get_version_backend.outputs.version }}
if: success()
- name: Deploying Frontend (Build and Run Frontend Docker Container)
run: |
sshpass -p ${{ secrets.SSH_PASSWORD }} ssh -t -o StrictHostKeyChecking=no ${{ secrets.SSH_USERNAME }} << EOF
echo "Current directory path: $(pwd)"
cd
cd Epoch/epoch_frontend/
echo "Version for backend Docker image: $VERSION"
docker build -t epoch_frontend:$VERSION ./
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
docker tag epoch_frontend:$VERSION $DOCKER_USERNAME/epoch_frontend:$VERSION
docker push $DOCKER_USERNAME/epoch_frontend:$VERSION
docker run -d -p 443:443 epoch_frontend:$VERSION
exit
EOF
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
VERSION: ${{ steps.get_version_frontend.outputs.version }}
if: success()
server-test-new-build:
runs-on: ubuntu-latest
permissions: write-all
needs: deploy-new-build
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Install SSH Client and sshpass
run: |
sudo apt-get update
sudo apt-get install -y openssh-client sshpass
- name: SSH into Google Cloud VM for testing
run: |
set -e
sshpass -p ${{ secrets.TESTER_SSH_PASSWORD }} ssh -t -o StrictHostKeyChecking=no ${{ secrets.TESTER_SSH_USERNAME }} << EOF
echo "Current directory path: $(pwd)"
cd
rm -rf epoch_tests_results
mkdir epoch_tests_results
jmeter -n -t EpochLoadTestPlan.jmx -l ./epoch_tests_results/test_results_$(curl -s "https://registry.hub.docker.com/v2/repositories/$DOCKER_USERNAME/epoch_frontend/tags/?page_size=1" | jq -r '.results[0].name')_$(date +%Y-%m-%d_%H-%M-%S).csv
cd Epoch/
rm -rf epoch_tests_results
cd ..
mv epoch_tests_results Epoch/
cd Epoch/
git add epoch_tests_results
git commit -m "Load Test results for $(curl -s "https://registry.hub.docker.com/v2/repositories/$DOCKER_USERNAME/epoch_backend/tags/?page_size=1" | jq -r '.results[0].name')_$(date +%Y-%m-%d_%H-%M-%S).csv"
git config --global user.email $EMAIL
git config --global user.name $NAME
git push https://$NAME:${{ secrets.GIT_PAT }}@github.com/$NAME/Epoch
exit
EOF
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
GIT_PAT: ${{ secrets.GIT_PAT }}
EMAIL: ${{ secrets.EMAIL }}
NAME: ${{ secrets.NAME }}