Skip to content

Commit 3c6db17

Browse files
authored
Merge pull request #1 from belajarqywok/development
Update: CI/CD Pipeline, Unit testing, and Load testing using Locust
2 parents 0e3ea3d + 3288045 commit 3c6db17

11 files changed

+153
-7
lines changed

.github/workflows/development.yaml

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
name: Development Pipeline
2+
3+
on:
4+
push:
5+
branches:
6+
- development
7+
tags:
8+
- '*'
9+
10+
permissions:
11+
contents: read
12+
13+
env:
14+
host: "172.17.0.1"
15+
16+
jobs:
17+
# Unit Testing
18+
unit_testing:
19+
name: Unit Testing
20+
runs-on: ubuntu-latest
21+
environment: testing
22+
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v3
26+
27+
- name: Unit Testing
28+
run: |
29+
pip3 install nose2 nose2[coverage_plugin] scikit-learn \
30+
numpy keras tensorflow keras_preprocessing
31+
32+
nose2 --start-dir tests \
33+
--verbose \
34+
--pretty-assert \
35+
--with-coverage
36+
37+
# Performance and Load Testing
38+
performance_and_load_testing:
39+
name: Performance and Load Testing
40+
runs-on: ubuntu-latest
41+
environment: testing
42+
needs: unit_testing
43+
44+
steps:
45+
- name: Checkout
46+
uses: actions/checkout@v3
47+
48+
- name: Build Docker Image
49+
run: |
50+
docker build --tag ml_service:1.0 \
51+
--file deployment/development.dockerfile .
52+
53+
- name: Deploy Database (PostgreSQL) and Service
54+
run: |
55+
docker container create \
56+
--name pgserver \
57+
-p 5432:5432 \
58+
-e POSTGRES_USER=postgres \
59+
-e POSTGRES_PASSWORD=admin \
60+
-e POSTGRES_DB=coba_capstone \
61+
postgres:11
62+
63+
docker container create --name ml_service \
64+
-p 80:80 \
65+
-e VERSION=v1 \
66+
-e JWT_ACCESS_TOKEN_SECRET=AHBiadbiaeud92uedb9ub9wue92 \
67+
-e JWT_REFRESH_TOKEN_SECRET=eu92uidbsAHBiadbiauedb9ub9wue92eu \
68+
-e JWT_ALGORITHM=HS512 \
69+
-e JWT_ACCESS_TOKEN_EXPIRE=1 \
70+
-e JWT_REFRESH_TOKEN_EXPIRE=7 \
71+
-e POSTGRES_HOST=$host \
72+
-e POSTGRES_PORT=5432 \
73+
-e POSTGRES_USER=postgres \
74+
-e POSTGRES_PASS=admin \
75+
-e POSTGRES_DB=coba_capstone \
76+
ml_service:1.0
77+
78+
docker container start pgserver
79+
sleep 5
80+
docker container start ml_service
81+
sleep 5
82+
docker container ls
83+
sleep 5
84+
85+
- name: liveness checking
86+
run: |
87+
while true; do
88+
if docker logs ml_service 2>&1 | grep -q "Application startup complete."; then
89+
echo "Application startup is complete. Stopping the loop."
90+
break
91+
fi
92+
sleep 5
93+
clear
94+
done
95+
curl http://$host/liveness_check
96+
97+
- name: Performance & Load Testing
98+
run: |
99+
pip3 install locust
100+
locust --headless \
101+
--run-time 60s \
102+
--users 400 \
103+
--spawn-rate 50 \
104+
-H http://$host \
105+
--locustfile locust/configuration.py
106+
107+
# Vulnerability Scanning
108+
vulnerability_scanning:
109+
name: Vulnerability Scanning
110+
runs-on: ubuntu-latest
111+
environment: testing
112+
needs: performance_and_load_testing
113+
114+
steps:
115+
- name: Checkout
116+
uses: actions/checkout@v3
117+
118+
- name: Vulnerability Scanning
119+
run: |
120+
pip3 install pip-audit
121+
pip-audit --requirement ./linux.requirements.txt
122+

Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ postgres:
1414
jaeger-test:
1515
uvicorn --host 0.0.0.0 --port 3000 --reload --workers 10 jaeger_test:app
1616

17+
load_test:
18+
locust --headless --run-time 10s --users 100 --spawn-rate 10 -H http://192.168.137.1:3000 --locustfile locust/configuration.py
1719

locust/configuration.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from locust import HttpUser, task
2+
3+
class main_routes(HttpUser):
4+
@task
5+
def main_route(self):
6+
self.client.get("/")
7+
8+
class ml_routes(HttpUser):
9+
@task
10+
def liveness_check_route(self):
11+
self.client.get("/liveness_check")
Binary file not shown.
Binary file not shown.

src/services/ml_services/nlp_service.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ def predict_question(self, question: str) -> str:
2626
# Inverse Transform Label Encoder
2727
return self.__NLP_UTILS.label_encoder.inverse_transform(
2828
[argmax(predict)]
29-
)[0]
29+
)[0]
30+
Binary file not shown.
Binary file not shown.

src/utilities/nlp_utils.py

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ def clean_stopwords(self, sentence: str) -> str:
3636

3737
return temp.strip()
3838

39-
4039
# Model
4140
@property
4241
def model(self) -> Any:

tests/test_ml_services.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import unittest
2+
from src.services.ml_services.nlp_service import nlp_service
3+
4+
class ml_service_tests(unittest.TestCase):
5+
# NLP Service Test
6+
def test_nlp_service(self) -> None:
7+
# Question
8+
question: str = "mental"
9+
10+
# NLP Service
11+
service = nlp_service()
12+
13+
# Answer
14+
answer: str = service.predict_question(question)
15+
16+
self.assertTrue(question in answer.lower())

tests/test_utilities.py

-5
This file was deleted.

0 commit comments

Comments
 (0)