From def19b449e505562aeefe22c20ac9154ad9ebf59 Mon Sep 17 00:00:00 2001 From: lvliang-intel Date: Mon, 9 Sep 2024 09:35:57 +0800 Subject: [PATCH] Enable nginx for VisualQnA (#754) Signed-off-by: lvliang-intel Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- VisualQnA/docker/docker_build_compose.yaml | 6 ++ VisualQnA/docker/gaudi/compose.yaml | 19 +++++ VisualQnA/docker/gaudi/set_env.sh | 5 ++ VisualQnA/docker/ui/svelte/.env | 2 +- VisualQnA/docker/xeon/compose.yaml | 19 +++++ VisualQnA/docker/xeon/set_env.sh | 5 ++ .../kubernetes/manifests/gaudi/visualqna.yaml | 72 +++++++++++++++++++ .../kubernetes/manifests/xeon/visualqna.yaml | 72 +++++++++++++++++++ VisualQnA/tests/test_visualqna_on_gaudi.sh | 35 ++++++++- VisualQnA/tests/test_visualqna_on_xeon.sh | 35 ++++++++- 10 files changed, 267 insertions(+), 3 deletions(-) diff --git a/VisualQnA/docker/docker_build_compose.yaml b/VisualQnA/docker/docker_build_compose.yaml index a5f1b5891..c0b1fd967 100644 --- a/VisualQnA/docker/docker_build_compose.yaml +++ b/VisualQnA/docker/docker_build_compose.yaml @@ -22,3 +22,9 @@ services: dockerfile: comps/lvms/Dockerfile_tgi extends: visualqna image: ${REGISTRY:-opea}/lvm-tgi:${TAG:-latest} + nginx: + build: + context: GenAIComps + dockerfile: comps/nginx/docker/Dockerfile + extends: visualqna + image: ${REGISTRY:-opea}/nginx:${TAG:-latest} diff --git a/VisualQnA/docker/gaudi/compose.yaml b/VisualQnA/docker/gaudi/compose.yaml index 1500cc11e..687e2ab03 100644 --- a/VisualQnA/docker/gaudi/compose.yaml +++ b/VisualQnA/docker/gaudi/compose.yaml @@ -68,6 +68,25 @@ services: - BACKEND_BASE_URL=${BACKEND_SERVICE_ENDPOINT} ipc: host restart: always + visualqna-gaudi-nginx-server: + image: ${REGISTRY:-opea}/nginx:${TAG:-latest} + container_name: visualqna-gaudi-nginx-server + depends_on: + - visualqna-gaudi-backend-server + - visualqna-gaudi-ui-server + ports: + - "${NGINX_PORT:-80}:80" + environment: + - no_proxy=${no_proxy} + - https_proxy=${https_proxy} + - http_proxy=${http_proxy} + - FRONTEND_SERVICE_IP=${FRONTEND_SERVICE_IP} + - FRONTEND_SERVICE_PORT=${FRONTEND_SERVICE_PORT} + - BACKEND_SERVICE_NAME=${BACKEND_SERVICE_NAME} + - BACKEND_SERVICE_IP=${BACKEND_SERVICE_IP} + - BACKEND_SERVICE_PORT=${BACKEND_SERVICE_PORT} + ipc: host + restart: always networks: default: diff --git a/VisualQnA/docker/gaudi/set_env.sh b/VisualQnA/docker/gaudi/set_env.sh index f9cd92cc6..2e294e006 100644 --- a/VisualQnA/docker/gaudi/set_env.sh +++ b/VisualQnA/docker/gaudi/set_env.sh @@ -9,3 +9,8 @@ export LVM_SERVICE_PORT=9399 export MEGA_SERVICE_HOST_IP=${host_ip} export LVM_SERVICE_HOST_IP=${host_ip} export BACKEND_SERVICE_ENDPOINT="http://${host_ip}:8888/v1/visualqna" +export FRONTEND_SERVICE_IP=${host_ip} +export FRONTEND_SERVICE_PORT=5173 +export BACKEND_SERVICE_NAME=visualqna +export BACKEND_SERVICE_IP=${host_ip} +export BACKEND_SERVICE_PORT=8888 diff --git a/VisualQnA/docker/ui/svelte/.env b/VisualQnA/docker/ui/svelte/.env index c6eadaf96..e3086b4e0 100644 --- a/VisualQnA/docker/ui/svelte/.env +++ b/VisualQnA/docker/ui/svelte/.env @@ -1 +1 @@ -BACKEND_BASE_URL = 'http://backend_address:8888/v1/visualqna' \ No newline at end of file +BACKEND_BASE_URL = '/v1/visualqna' \ No newline at end of file diff --git a/VisualQnA/docker/xeon/compose.yaml b/VisualQnA/docker/xeon/compose.yaml index 4e2261896..553b13908 100644 --- a/VisualQnA/docker/xeon/compose.yaml +++ b/VisualQnA/docker/xeon/compose.yaml @@ -63,6 +63,25 @@ services: - BACKEND_BASE_URL=${BACKEND_SERVICE_ENDPOINT} ipc: host restart: always + visualqna-xeon-nginx-server: + image: ${REGISTRY:-opea}/nginx:${TAG:-latest} + container_name: visualqna-xeon-nginx-server + depends_on: + - visualqna-xeon-backend-server + - visualqna-xeon-ui-server + ports: + - "${NGINX_PORT:-80}:80" + environment: + - no_proxy=${no_proxy} + - https_proxy=${https_proxy} + - http_proxy=${http_proxy} + - FRONTEND_SERVICE_IP=${FRONTEND_SERVICE_IP} + - FRONTEND_SERVICE_PORT=${FRONTEND_SERVICE_PORT} + - BACKEND_SERVICE_NAME=${BACKEND_SERVICE_NAME} + - BACKEND_SERVICE_IP=${BACKEND_SERVICE_IP} + - BACKEND_SERVICE_PORT=${BACKEND_SERVICE_PORT} + ipc: host + restart: always networks: default: diff --git a/VisualQnA/docker/xeon/set_env.sh b/VisualQnA/docker/xeon/set_env.sh index 44ca0bc3b..aba1e7a7f 100644 --- a/VisualQnA/docker/xeon/set_env.sh +++ b/VisualQnA/docker/xeon/set_env.sh @@ -10,3 +10,8 @@ export LVM_SERVICE_PORT=9399 export MEGA_SERVICE_HOST_IP=${host_ip} export LVM_SERVICE_HOST_IP=${host_ip} export BACKEND_SERVICE_ENDPOINT="http://${host_ip}:8888/v1/visualqna" +export FRONTEND_SERVICE_IP=${host_ip} +export FRONTEND_SERVICE_PORT=5173 +export BACKEND_SERVICE_NAME=visualqna +export BACKEND_SERVICE_IP=${host_ip} +export BACKEND_SERVICE_PORT=8888 diff --git a/VisualQnA/kubernetes/manifests/gaudi/visualqna.yaml b/VisualQnA/kubernetes/manifests/gaudi/visualqna.yaml index 6f00bfb8c..ab0e1763f 100644 --- a/VisualQnA/kubernetes/manifests/gaudi/visualqna.yaml +++ b/VisualQnA/kubernetes/manifests/gaudi/visualqna.yaml @@ -296,3 +296,75 @@ spec: volumes: - name: tmp emptyDir: {} +--- +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +apiVersion: v1 +kind: ConfigMap +metadata: + name: visualqna-nginx-config +data: + default.conf: | + server { + listen 80; + listen [::]:80; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + } + + location /v1/visualqna { + proxy_pass http://visualqna:8888; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + } +--- +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: visualqna-nginx-deployment +spec: + replicas: 1 + selector: + matchLabels: + app: nginx + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx:latest + ports: + - containerPort: 80 + volumeMounts: + - name: nginx-config-volume + mountPath: /etc/nginx/conf.d/default.conf + subPath: default.conf + volumes: + - name: nginx-config-volume + configMap: + name: visualqna-nginx-config +--- +kind: Service +apiVersion: v1 +metadata: + name: nginx-svc +spec: + selector: + app: nginx + ports: + - protocol: TCP + port: 80 + targetPort: 80 + nodePort: 30789 + type: NodePort diff --git a/VisualQnA/kubernetes/manifests/xeon/visualqna.yaml b/VisualQnA/kubernetes/manifests/xeon/visualqna.yaml index 744853d81..c9a3ef32e 100644 --- a/VisualQnA/kubernetes/manifests/xeon/visualqna.yaml +++ b/VisualQnA/kubernetes/manifests/xeon/visualqna.yaml @@ -296,3 +296,75 @@ spec: volumes: - name: tmp emptyDir: {} +--- +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +apiVersion: v1 +kind: ConfigMap +metadata: + name: visualqna-nginx-config +data: + default.conf: | + server { + listen 80; + listen [::]:80; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + } + + location /v1/visualqna { + proxy_pass http://visualqna:8888; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + } +--- +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: visualqna-nginx-deployment +spec: + replicas: 1 + selector: + matchLabels: + app: nginx + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx:latest + ports: + - containerPort: 80 + volumeMounts: + - name: nginx-config-volume + mountPath: /etc/nginx/conf.d/default.conf + subPath: default.conf + volumes: + - name: nginx-config-volume + configMap: + name: visualqna-nginx-config +--- +kind: Service +apiVersion: v1 +metadata: + name: nginx-svc +spec: + selector: + app: nginx + ports: + - protocol: TCP + port: 80 + targetPort: 80 + nodePort: 30789 + type: NodePort diff --git a/VisualQnA/tests/test_visualqna_on_gaudi.sh b/VisualQnA/tests/test_visualqna_on_gaudi.sh index 1bfb10d98..eec7e6f59 100644 --- a/VisualQnA/tests/test_visualqna_on_gaudi.sh +++ b/VisualQnA/tests/test_visualqna_on_gaudi.sh @@ -19,7 +19,7 @@ function build_docker_images() { git clone https://github.com/opea-project/GenAIComps.git echo "Build all the images with --no-cache, check docker_image_build.log for details..." - service_list="visualqna visualqna-ui llm-visualqna-tgi" + service_list="visualqna visualqna-ui llm-visualqna-tgi nginx" docker compose -f docker_build_compose.yaml build ${service_list} --no-cache > ${LOG_PATH}/docker_image_build.log docker pull ghcr.io/huggingface/tgi-gaudi:2.0.4 @@ -36,6 +36,12 @@ function start_services() { export MEGA_SERVICE_HOST_IP=${ip_address} export LVM_SERVICE_HOST_IP=${ip_address} export BACKEND_SERVICE_ENDPOINT="http://${ip_address}:8888/v1/visualqna" + export FRONTEND_SERVICE_IP=${ip_address} + export FRONTEND_SERVICE_PORT=5173 + export BACKEND_SERVICE_NAME=visualqna + export BACKEND_SERVICE_IP=${ip_address} + export BACKEND_SERVICE_PORT=8888 + export NGINX_PORT=80 sed -i "s/backend_address/$ip_address/g" $WORKPATH/docker/ui/svelte/.env @@ -120,6 +126,33 @@ function validate_megaservice() { ], "max_tokens": 300 }' + + # test the megeservice via nginx + validate_services \ + "${ip_address}:80/v1/visualqna" \ + "The image" \ + "visualqna-gaudi-nginx-server" \ + "visualqna-gaudi-nginx-server" \ + '{ + "messages": [ + { + "role": "user", + "content": [ + { + "type": "text", + "text": "What'\''s in this image?" + }, + { + "type": "image_url", + "image_url": { + "url": "https://www.ilankelman.org/stopsigns/australia.jpg" + } + } + ] + } + ], + "max_tokens": 300 + }' } function validate_frontend() { diff --git a/VisualQnA/tests/test_visualqna_on_xeon.sh b/VisualQnA/tests/test_visualqna_on_xeon.sh index 78ccb85cc..7df5da8c9 100644 --- a/VisualQnA/tests/test_visualqna_on_xeon.sh +++ b/VisualQnA/tests/test_visualqna_on_xeon.sh @@ -19,7 +19,7 @@ function build_docker_images() { git clone https://github.com/opea-project/GenAIComps.git echo "Build all the images with --no-cache, check docker_image_build.log for details..." - service_list="visualqna visualqna-ui llm-visualqna-tgi" + service_list="visualqna visualqna-ui llm-visualqna-tgi nginx" docker compose -f docker_build_compose.yaml build ${service_list} --no-cache > ${LOG_PATH}/docker_image_build.log docker pull ghcr.io/huggingface/text-generation-inference:2.2.0 @@ -36,6 +36,12 @@ function start_services() { export MEGA_SERVICE_HOST_IP=${ip_address} export LVM_SERVICE_HOST_IP=${ip_address} export BACKEND_SERVICE_ENDPOINT="http://${ip_address}:8888/v1/visualqna" + export FRONTEND_SERVICE_IP=${ip_address} + export FRONTEND_SERVICE_PORT=5173 + export BACKEND_SERVICE_NAME=visualqna + export BACKEND_SERVICE_IP=${ip_address} + export BACKEND_SERVICE_PORT=8888 + export NGINX_PORT=80 sed -i "s/backend_address/$ip_address/g" $WORKPATH/docker/ui/svelte/.env @@ -120,6 +126,33 @@ function validate_megaservice() { ], "max_tokens": 300 }' + + # test the megeservice via nginx + validate_services \ + "${ip_address}:80/v1/visualqna" \ + "The image" \ + "visualqna-xeon-nginx-server" \ + "visualqna-xeon-nginx-server" \ + '{ + "messages": [ + { + "role": "user", + "content": [ + { + "type": "text", + "text": "What'\''s in this image?" + }, + { + "type": "image_url", + "image_url": { + "url": "https://www.ilankelman.org/stopsigns/australia.jpg" + } + } + ] + } + ], + "max_tokens": 300 + }' } function validate_frontend() {