-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from belajarqywok/development
Update: CI/CD Pipeline, Unit testing, and Load testing using Locust
- Loading branch information
Showing
11 changed files
with
153 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
name: Development Pipeline | ||
|
||
on: | ||
push: | ||
branches: | ||
- development | ||
tags: | ||
- '*' | ||
|
||
permissions: | ||
contents: read | ||
|
||
env: | ||
host: "172.17.0.1" | ||
|
||
jobs: | ||
# Unit Testing | ||
unit_testing: | ||
name: Unit Testing | ||
runs-on: ubuntu-latest | ||
environment: testing | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Unit Testing | ||
run: | | ||
pip3 install nose2 nose2[coverage_plugin] scikit-learn \ | ||
numpy keras tensorflow keras_preprocessing | ||
nose2 --start-dir tests \ | ||
--verbose \ | ||
--pretty-assert \ | ||
--with-coverage | ||
# Performance and Load Testing | ||
performance_and_load_testing: | ||
name: Performance and Load Testing | ||
runs-on: ubuntu-latest | ||
environment: testing | ||
needs: unit_testing | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Build Docker Image | ||
run: | | ||
docker build --tag ml_service:1.0 \ | ||
--file deployment/development.dockerfile . | ||
- name: Deploy Database (PostgreSQL) and Service | ||
run: | | ||
docker container create \ | ||
--name pgserver \ | ||
-p 5432:5432 \ | ||
-e POSTGRES_USER=postgres \ | ||
-e POSTGRES_PASSWORD=admin \ | ||
-e POSTGRES_DB=coba_capstone \ | ||
postgres:11 | ||
docker container create --name ml_service \ | ||
-p 80:80 \ | ||
-e VERSION=v1 \ | ||
-e JWT_ACCESS_TOKEN_SECRET=AHBiadbiaeud92uedb9ub9wue92 \ | ||
-e JWT_REFRESH_TOKEN_SECRET=eu92uidbsAHBiadbiauedb9ub9wue92eu \ | ||
-e JWT_ALGORITHM=HS512 \ | ||
-e JWT_ACCESS_TOKEN_EXPIRE=1 \ | ||
-e JWT_REFRESH_TOKEN_EXPIRE=7 \ | ||
-e POSTGRES_HOST=$host \ | ||
-e POSTGRES_PORT=5432 \ | ||
-e POSTGRES_USER=postgres \ | ||
-e POSTGRES_PASS=admin \ | ||
-e POSTGRES_DB=coba_capstone \ | ||
ml_service:1.0 | ||
docker container start pgserver | ||
sleep 5 | ||
docker container start ml_service | ||
sleep 5 | ||
docker container ls | ||
sleep 5 | ||
- name: liveness checking | ||
run: | | ||
while true; do | ||
if docker logs ml_service 2>&1 | grep -q "Application startup complete."; then | ||
echo "Application startup is complete. Stopping the loop." | ||
break | ||
fi | ||
sleep 5 | ||
clear | ||
done | ||
curl http://$host/liveness_check | ||
- name: Performance & Load Testing | ||
run: | | ||
pip3 install locust | ||
locust --headless \ | ||
--run-time 60s \ | ||
--users 400 \ | ||
--spawn-rate 50 \ | ||
-H http://$host \ | ||
--locustfile locust/configuration.py | ||
# Vulnerability Scanning | ||
vulnerability_scanning: | ||
name: Vulnerability Scanning | ||
runs-on: ubuntu-latest | ||
environment: testing | ||
needs: performance_and_load_testing | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Vulnerability Scanning | ||
run: | | ||
pip3 install pip-audit | ||
pip-audit --requirement ./linux.requirements.txt | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from locust import HttpUser, task | ||
|
||
class main_routes(HttpUser): | ||
@task | ||
def main_route(self): | ||
self.client.get("/") | ||
|
||
class ml_routes(HttpUser): | ||
@task | ||
def liveness_check_route(self): | ||
self.client.get("/liveness_check") |
Binary file modified
BIN
+0 Bytes
(100%)
src/services/ml_services/__pycache__/image_recog_service.cpython-39.pyc
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
src/services/ml_services/__pycache__/nlp_service.cpython-39.pyc
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import unittest | ||
from src.services.ml_services.nlp_service import nlp_service | ||
|
||
class ml_service_tests(unittest.TestCase): | ||
# NLP Service Test | ||
def test_nlp_service(self) -> None: | ||
# Question | ||
question: str = "mental" | ||
|
||
# NLP Service | ||
service = nlp_service() | ||
|
||
# Answer | ||
answer: str = service.predict_question(question) | ||
|
||
self.assertTrue(question in answer.lower()) |
This file was deleted.
Oops, something went wrong.