|
| 1 | +#!/bin/bash |
| 2 | +# Copyright (C) 2025 Huawei Technologies Co., Ltd. |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +set -xe |
| 6 | +IMAGE_REPO=${IMAGE_REPO:-"opea"} |
| 7 | +IMAGE_TAG=${IMAGE_TAG:-"latest"}-openeuler |
| 8 | +echo "REGISTRY=IMAGE_REPO=${IMAGE_REPO}" |
| 9 | +echo "TAG=IMAGE_TAG=${IMAGE_TAG}" |
| 10 | +export REGISTRY=${IMAGE_REPO} |
| 11 | +export TAG=${IMAGE_TAG} |
| 12 | +export MODEL_CACHE=${model_cache:-"./data"} |
| 13 | + |
| 14 | +WORKPATH=$(dirname "$PWD") |
| 15 | +LOG_PATH="$WORKPATH/tests" |
| 16 | +ip_address=$(hostname -I | awk '{print $1}') |
| 17 | + |
| 18 | +function build_docker_images() { |
| 19 | + opea_branch=${opea_branch:-"main"} |
| 20 | + cd $WORKPATH/docker_image_build |
| 21 | + git clone --depth 1 --branch ${opea_branch} https://github.com/opea-project/GenAIComps.git |
| 22 | + pushd GenAIComps |
| 23 | + echo "GenAIComps test commit is $(git rev-parse HEAD)" |
| 24 | + docker build --no-cache -t ${REGISTRY}/comps-base:${TAG} --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f Dockerfile.openEuler . |
| 25 | + popd && sleep 1s |
| 26 | + |
| 27 | + |
| 28 | + echo "Build all the images with --no-cache, check docker_image_build.log for details..." |
| 29 | + service_list="chatqna-openeuler chatqna-ui-openeuler dataprep-openeuler retriever-openeuler nginx-openeuler" |
| 30 | + docker compose -f build.yaml build ${service_list} --no-cache > ${LOG_PATH}/docker_image_build.log |
| 31 | + |
| 32 | + docker images && sleep 1s |
| 33 | +} |
| 34 | + |
| 35 | +function start_services() { |
| 36 | + cd $WORKPATH/docker_compose/intel/cpu/xeon |
| 37 | + |
| 38 | + source set_env.sh |
| 39 | + |
| 40 | + # Start Docker Containers |
| 41 | + docker compose -f compose_openeuler.yaml -f compose.telemetry.yaml up -d --quiet-pull > ${LOG_PATH}/start_services_with_compose.log |
| 42 | + n=0 |
| 43 | + until [[ "$n" -ge 100 ]]; do |
| 44 | + docker logs vllm-service > ${LOG_PATH}/vllm_service_start.log 2>&1 |
| 45 | + if grep -q complete ${LOG_PATH}/vllm_service_start.log; then |
| 46 | + break |
| 47 | + fi |
| 48 | + sleep 5s |
| 49 | + n=$((n+1)) |
| 50 | + done |
| 51 | +} |
| 52 | + |
| 53 | +function validate_service() { |
| 54 | + local URL="$1" |
| 55 | + local EXPECTED_RESULT="$2" |
| 56 | + local SERVICE_NAME="$3" |
| 57 | + local DOCKER_NAME="$4" |
| 58 | + local INPUT_DATA="$5" |
| 59 | + |
| 60 | + local HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X POST -d "$INPUT_DATA" -H 'Content-Type: application/json' "$URL") |
| 61 | + if [ "$HTTP_STATUS" -eq 200 ]; then |
| 62 | + echo "[ $SERVICE_NAME ] HTTP status is 200. Checking content..." |
| 63 | + |
| 64 | + local CONTENT=$(curl -s -X POST -d "$INPUT_DATA" -H 'Content-Type: application/json' "$URL" | tee ${LOG_PATH}/${SERVICE_NAME}.log) |
| 65 | + |
| 66 | + if echo "$CONTENT" | grep -q "$EXPECTED_RESULT"; then |
| 67 | + echo "[ $SERVICE_NAME ] Content is as expected." |
| 68 | + else |
| 69 | + echo "[ $SERVICE_NAME ] Content does not match the expected result: $CONTENT" |
| 70 | + docker logs ${DOCKER_NAME} >> ${LOG_PATH}/${SERVICE_NAME}.log |
| 71 | + exit 1 |
| 72 | + fi |
| 73 | + else |
| 74 | + echo "[ $SERVICE_NAME ] HTTP status is not 200. Received status was $HTTP_STATUS" |
| 75 | + docker logs ${DOCKER_NAME} >> ${LOG_PATH}/${SERVICE_NAME}.log |
| 76 | + exit 1 |
| 77 | + fi |
| 78 | + sleep 1s |
| 79 | +} |
| 80 | + |
| 81 | +function validate_microservices() { |
| 82 | + # Check if the microservices are running correctly. |
| 83 | + sleep 3m |
| 84 | + |
| 85 | + # tei for embedding service |
| 86 | + validate_service \ |
| 87 | + "${ip_address}:6006/embed" \ |
| 88 | + "\[\[" \ |
| 89 | + "tei-embedding" \ |
| 90 | + "tei-embedding-server" \ |
| 91 | + '{"inputs":"What is Deep Learning?"}' |
| 92 | + |
| 93 | + # retrieval microservice |
| 94 | + test_embedding=$(python3 -c "import random; embedding = [random.uniform(-1, 1) for _ in range(768)]; print(embedding)") |
| 95 | + validate_service \ |
| 96 | + "${ip_address}:7000/v1/retrieval" \ |
| 97 | + " " \ |
| 98 | + "retrieval" \ |
| 99 | + "retriever-redis-server" \ |
| 100 | + "{\"text\":\"What is the revenue of Nike in 2023?\",\"embedding\":${test_embedding}}" |
| 101 | + |
| 102 | + # tei for rerank microservice |
| 103 | + validate_service \ |
| 104 | + "${ip_address}:8808/rerank" \ |
| 105 | + '{"index":1,"score":' \ |
| 106 | + "tei-rerank" \ |
| 107 | + "tei-reranking-server" \ |
| 108 | + '{"query":"What is Deep Learning?", "texts": ["Deep Learning is not...", "Deep learning is..."]}' |
| 109 | + |
| 110 | + # vllm for llm service |
| 111 | + validate_service \ |
| 112 | + "${ip_address}:9009/v1/chat/completions" \ |
| 113 | + "content" \ |
| 114 | + "vllm-llm" \ |
| 115 | + "vllm-service" \ |
| 116 | + '{"model": "Qwen/Qwen3-4B", "messages": [{"role": "user", "content": "What is Deep Learning?"}], "max_tokens": 17}' |
| 117 | +} |
| 118 | + |
| 119 | +function validate_megaservice() { |
| 120 | + # Curl the Mega Service |
| 121 | + validate_service \ |
| 122 | + "${ip_address}:8888/v1/chatqna" \ |
| 123 | + "Nike" \ |
| 124 | + "mega-chatqna" \ |
| 125 | + "chatqna-xeon-backend-server" \ |
| 126 | + '{"messages": "What is the revenue of Nike in 2023?"}' |
| 127 | + |
| 128 | +} |
| 129 | + |
| 130 | +function validate_frontend() { |
| 131 | + cd $WORKPATH/ui/svelte |
| 132 | + |
| 133 | + # use the official Playwright image to run the tests |
| 134 | + docker run --rm -it \ |
| 135 | + -v $(pwd):/workspace \ |
| 136 | + -w /workspace \ |
| 137 | + -e CI=true \ |
| 138 | + -e PLAYWRIGHT_BROWSERS_PATH=/ms-playwright \ |
| 139 | + mcr.microsoft.com/playwright:v1.37.0-focal \ |
| 140 | + /bin/bash -c " |
| 141 | + apt-get update && \ |
| 142 | + apt-get install -y curl && \ |
| 143 | + curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \ |
| 144 | + apt-get install -y nodejs && \ |
| 145 | + node -v && npm -v && \ |
| 146 | + npm install && npm ci && npx playwright install --with-deps && |
| 147 | + sed -i 's/localhost/$ip_address/g' playwright.config.ts && |
| 148 | + npx playwright test |
| 149 | + " |
| 150 | + |
| 151 | + if [ $? -ne 0 ]; then |
| 152 | + echo "[TEST INFO]: ---------frontend test failed---------" |
| 153 | + exit 1 |
| 154 | + else |
| 155 | + echo "[TEST INFO]: ---------frontend test passed---------" |
| 156 | + fi |
| 157 | +} |
| 158 | + |
| 159 | +function stop_docker() { |
| 160 | + cd $WORKPATH/docker_compose/intel/cpu/xeon |
| 161 | + docker compose -f compose_openeuler.yaml -f compose.telemetry.yaml down |
| 162 | +} |
| 163 | + |
| 164 | +function main() { |
| 165 | + |
| 166 | + echo "::group::stop_docker" |
| 167 | + stop_docker |
| 168 | + echo "::endgroup::" |
| 169 | + |
| 170 | + echo "::group::build_docker_images" |
| 171 | + if [[ "$IMAGE_REPO" == "opea" ]]; then build_docker_images; fi |
| 172 | + echo "::endgroup::" |
| 173 | + |
| 174 | + echo "::group::start_services" |
| 175 | + start_services |
| 176 | + echo "::endgroup::" |
| 177 | + |
| 178 | + echo "::group::validate_microservices" |
| 179 | + validate_microservices |
| 180 | + echo "::endgroup::" |
| 181 | + |
| 182 | + echo "::group::validate_megaservice" |
| 183 | + validate_megaservice |
| 184 | + echo "::endgroup::" |
| 185 | + |
| 186 | + echo "::group::validate_frontend" |
| 187 | + validate_frontend |
| 188 | + echo "::endgroup::" |
| 189 | + |
| 190 | + echo "::group::stop_docker" |
| 191 | + stop_docker |
| 192 | + echo "::endgroup::" |
| 193 | + |
| 194 | + docker system prune -f |
| 195 | + |
| 196 | +} |
| 197 | + |
| 198 | +main |
0 commit comments