From 2f0d78e504d5965b48da8f235df800a68fc82e29 Mon Sep 17 00:00:00 2001 From: lvliang-intel Date: Wed, 16 Oct 2024 17:43:53 +0800 Subject: [PATCH] Add dataprep endpoint in nginx microservice (#795) Signed-off-by: lvliang-intel --- comps/nginx/Dockerfile | 2 ++ comps/nginx/README.md | 4 ++++ comps/nginx/docker-compose.yaml | 2 ++ comps/nginx/nginx.conf.template | 24 ++++++++++++++++++++++++ comps/nginx/start-nginx.sh | 2 +- 5 files changed, 33 insertions(+), 1 deletion(-) diff --git a/comps/nginx/Dockerfile b/comps/nginx/Dockerfile index 1bb40e57b..d4517ced0 100644 --- a/comps/nginx/Dockerfile +++ b/comps/nginx/Dockerfile @@ -13,6 +13,8 @@ ENV FRONTEND_SERVICE_PORT=5173 ENV BACKEND_SERVICE_NAME=chatqna ENV BACKEND_SERVICE_IP=localhost ENV BACKEND_SERVICE_PORT=8888 +ENV DATAPREP_SERVICE_IP=localhost +ENV DATAPREP_SERVICE_PORT=6007 COPY comps/nginx/start-nginx.sh /usr/local/bin/start-nginx.sh RUN chmod +x /usr/local/bin/start-nginx.sh diff --git a/comps/nginx/README.md b/comps/nginx/README.md index f7ac650df..0ccb3e0e0 100644 --- a/comps/nginx/README.md +++ b/comps/nginx/README.md @@ -23,6 +23,8 @@ export FRONTEND_SERVICE_PORT=5173 export BACKEND_SERVICE_NAME=chatqna export BACKEND_SERVICE_IP=${your_backend_service_ip} export BACKEND_SERVICE_PORT=8888 +export DATAPREP_SERVICE_IP=${your_dataprep_service_ip} +export DATAPREP_SERVICE_PORT=6007 export NGINX_PORT=${your_nginx_port} ``` @@ -53,6 +55,8 @@ docker run -d --name opea-nginx -p ${NGINX_PORT}:80 \ -e BACKEND_SERVICE_NAME=${BACKEND_SERVICE_NAME} \ -e BACKEND_SERVICE_IP=${BACKEND_SERVICE_IP} \ -e BACKEND_SERVICE_PORT=${BACKEND_SERVICE_PORT} \ + -e DATAPREP_SERVICE_IP=${DATAPREP_SERVICE_IP} \ + -e DATAPREP_SERVICE_PORT=${DATAPREP_SERVICE_PORT} \ opea/nginx:latest ``` diff --git a/comps/nginx/docker-compose.yaml b/comps/nginx/docker-compose.yaml index 757c75ca7..605d3bebb 100644 --- a/comps/nginx/docker-compose.yaml +++ b/comps/nginx/docker-compose.yaml @@ -16,6 +16,8 @@ services: - BACKEND_SERVICE_NAME=${BACKEND_SERVICE_NAME} - BACKEND_SERVICE_IP=${BACKEND_SERVICE_IP} - BACKEND_SERVICE_PORT=${BACKEND_SERVICE_PORT} + - DATAPREP_SERVICE_IP=${DATAPREP_SERVICE_IP} + - DATAPREP_SERVICE_PORT=${DATAPREP_SERVICE_PORT} ipc: host restart: always diff --git a/comps/nginx/nginx.conf.template b/comps/nginx/nginx.conf.template index 5ba7223fc..0607315a6 100644 --- a/comps/nginx/nginx.conf.template +++ b/comps/nginx/nginx.conf.template @@ -25,4 +25,28 @@ server { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } + + location /v1/dataprep { + proxy_pass http://${DATAPREP_SERVICE_IP}:${DATAPREP_SERVICE_PORT}; + 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; + } + + location /v1/dataprep/get_file { + proxy_pass http://${DATAPREP_SERVICE_IP}:${DATAPREP_SERVICE_PORT}; + 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; + } + + location /v1/dataprep/delete_file { + proxy_pass http://${DATAPREP_SERVICE_IP}:${DATAPREP_SERVICE_PORT}; + 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; + } } diff --git a/comps/nginx/start-nginx.sh b/comps/nginx/start-nginx.sh index 2a2a4d242..ed3aef76a 100644 --- a/comps/nginx/start-nginx.sh +++ b/comps/nginx/start-nginx.sh @@ -2,5 +2,5 @@ # SPDX-License-Identifier: Apache-2.0 #!/bin/sh -envsubst '${FRONTEND_SERVICE_IP} ${FRONTEND_SERVICE_PORT} ${BACKEND_SERVICE_NAME} ${BACKEND_SERVICE_IP} ${BACKEND_SERVICE_PORT}' < /etc/nginx/nginx.conf.template > /etc/nginx/conf.d/default.conf +envsubst '${FRONTEND_SERVICE_IP} ${FRONTEND_SERVICE_PORT} ${BACKEND_SERVICE_NAME} ${BACKEND_SERVICE_IP} ${BACKEND_SERVICE_PORT} ${DATAPREP_SERVICE_IP} ${DATAPREP_SERVICE_PORT}' < /etc/nginx/nginx.conf.template > /etc/nginx/conf.d/default.conf nginx -g 'daemon off;'