|
| 1 | +# Copyright (C) 2024 Intel Corporation |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +set -x |
| 5 | +IMAGE_REPO=${IMAGE_REPO:-"opea"} |
| 6 | +IMAGE_TAG=${IMAGE_TAG:-"latest"} |
| 7 | +echo "REGISTRY=IMAGE_REPO=${IMAGE_REPO}" |
| 8 | +echo "TAG=IMAGE_TAG=${IMAGE_TAG}" |
| 9 | +export REGISTRY=${IMAGE_REPO} |
| 10 | +export TAG=${IMAGE_TAG} |
| 11 | + |
| 12 | +WORKPATH=$(dirname "$PWD") |
| 13 | +LOG_PATH="$WORKPATH/tests" |
| 14 | +ip_address=$(hostname -I | awk '{print $1}') |
| 15 | +text2image_service_port=9379 |
| 16 | +MODEL=stabilityai/stable-diffusion-2-1 |
| 17 | + |
| 18 | +function build_docker_images() { |
| 19 | + cd $WORKPATH/docker_image_build |
| 20 | + if [ ! -d "GenAIComps" ] ; then |
| 21 | + git clone https://github.com/opea-project/GenAIComps.git |
| 22 | + fi |
| 23 | + docker compose -f build.yaml build --no-cache > ${LOG_PATH}/docker_image_build.log |
| 24 | +} |
| 25 | + |
| 26 | +function start_service() { |
| 27 | + export no_proxy="localhost,127.0.0.1,"${ip_address} |
| 28 | + docker run -d --name="text2image-server" -p $text2image_service_port:$text2image_service_port --runtime=runc --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e MODEL=$MODEL -e no_proxy=$no_proxy ${IMAGE_REPO}/text2image:${IMAGE_TAG} |
| 29 | + sleep 30s |
| 30 | +} |
| 31 | + |
| 32 | +function validate_microservice() { |
| 33 | + cd $LOG_PATH |
| 34 | + export no_proxy="localhost,127.0.0.1,"${ip_address} |
| 35 | + |
| 36 | + # test /v1/text2image generate image |
| 37 | + URL="http://${ip_address}:$text2image_service_port/v1/text2image" |
| 38 | + HTTP_RESPONSE=$(curl --silent --write-out "HTTPSTATUS:%{http_code}" -X POST -d '{"prompt":"An astronaut riding a green horse", "num_images_per_prompt":1}' -H 'Content-Type: application/json' "$URL") |
| 39 | + HTTP_STATUS=$(echo $HTTP_RESPONSE | tr -d '\n' | sed -e 's/.*HTTPSTATUS://') |
| 40 | + RESPONSE_BODY=$(echo $HTTP_RESPONSE | sed -e 's/HTTPSTATUS\:.*//g') |
| 41 | + SERVICE_NAME="text2image-server - generate image" |
| 42 | + |
| 43 | + if [ "$HTTP_STATUS" -ne "200" ]; then |
| 44 | + echo "[ $SERVICE_NAME ] HTTP status is not 200. Received status was $HTTP_STATUS" |
| 45 | + docker logs text2image-server >> ${LOG_PATH}/text2image-server_generate_image.log |
| 46 | + exit 1 |
| 47 | + else |
| 48 | + echo "[ $SERVICE_NAME ] HTTP status is 200. Checking content..." |
| 49 | + fi |
| 50 | + # Check if the parsed values match the expected values |
| 51 | + if [[ $RESPONSE_BODY == *"images"* ]]; then |
| 52 | + echo "Content correct." |
| 53 | + else |
| 54 | + echo "Content wrong." |
| 55 | + docker logs text2image-server >> ${LOG_PATH}/text2image-server_generate_image.log |
| 56 | + exit 1 |
| 57 | + fi |
| 58 | +} |
| 59 | + |
| 60 | +function stop_docker() { |
| 61 | + cid=$(docker ps -aq --filter "name=text2image-server*") |
| 62 | + if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid && sleep 1s; fi |
| 63 | +} |
| 64 | + |
| 65 | +function main() { |
| 66 | + |
| 67 | + stop_docker |
| 68 | + |
| 69 | + build_docker_images |
| 70 | + start_service |
| 71 | + |
| 72 | + validate_microservice |
| 73 | + |
| 74 | + stop_docker |
| 75 | + echo y | docker system prune |
| 76 | + |
| 77 | +} |
| 78 | + |
| 79 | +main |
0 commit comments