Skip to content

Commit 6114a76

Browse files
committed
add polite_guard to tests and workflows
1 parent be910a0 commit 6114a76

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

.github/workflows/docker/compose/guardrails-compose.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ services:
1919
build:
2020
dockerfile: comps/guardrails/src/pii_detection/Dockerfile
2121
image: ${REGISTRY:-opea}/guardrails-pii-predictionguard:${TAG:-latest}
22+
guardrails-polite-guard:
23+
build:
24+
dockerfile: comps/guardrails/src/polite_guard/Dockerfile
25+
image: ${REGISTRY:-opea}/guardrails-polite-guard:${TAG:-latest}
2226
guardrails-toxicity-predictionguard:
2327
build:
2428
dockerfile: comps/guardrails/src/toxicity_detection/Dockerfile
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
# Copyright (C) 2024 Intel Corporation
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
set -x
6+
7+
WORKPATH=$(dirname "$PWD")
8+
ip_address=$(hostname -I | awk '{print $1}')
9+
10+
function build_docker_images() {
11+
echo "Start building docker images for microservice"
12+
cd $WORKPATH
13+
docker build --no-cache -t opea/guardrails-polite-guard:comps --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/guardrails/src/polite_guard/Dockerfile .
14+
if [ $? -ne 0 ]; then
15+
echo "opea/guardrails-polite-guard built fail"
16+
exit 1
17+
else
18+
echo "opea/guardrails-polite-guard built successful"
19+
fi
20+
}
21+
22+
function start_service() {
23+
echo "Starting microservice"
24+
export POLITE_GUARD_PORT=11301
25+
export TAG=comps
26+
service_name="guardrails-polite-guard-server"
27+
cd $WORKPATH
28+
cd comps/guardrails/deployment/docker_compose/
29+
docker compose up ${service_name} -d
30+
sleep 15
31+
echo "Microservice started"
32+
}
33+
34+
function validate_microservice() {
35+
echo "Validate microservice started"
36+
echo "test 1 - Impolite"
37+
result=$(curl localhost:11301/v1/polite -X POST -d '{"text":"He is stupid"}' -H 'Content-Type: application/json')
38+
if [[ $result == *"Violated"* ]]; then
39+
echo "Result correct."
40+
else
41+
docker logs guardrails-polite-guard-server
42+
exit 1
43+
fi
44+
echo "test 2 - Polite"
45+
result=$(curl localhost:11301/v1/polite -X POST -d '{"text":"He is kind"}' -H 'Content-Type: application/json')
46+
if [[ $result == *"kind"* ]]; then
47+
echo "Result correct."
48+
else
49+
echo "Result wrong."
50+
docker logs guardrails-polite-guard-server
51+
exit 1
52+
fi
53+
echo "Validate microservice completed"
54+
}
55+
56+
function stop_docker() {
57+
cid=$(docker ps -aq --filter "name=guardrails-polite-guard-server")
58+
echo "Shutdown legacy containers "$cid
59+
if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid && sleep 1s; fi
60+
}
61+
62+
function main() {
63+
64+
stop_docker
65+
66+
build_docker_images
67+
start_service
68+
69+
validate_microservice
70+
71+
stop_docker
72+
echo "cleanup container images and volumes"
73+
echo y | docker system prune 2>&1 > /dev/null
74+
75+
}
76+
77+
main

0 commit comments

Comments
 (0)