From 8655c7b4a426188814b5a743bfad5d0d536de672 Mon Sep 17 00:00:00 2001 From: Carlos Natalino <carlos.natalino@chalmers.se> Date: Wed, 2 Feb 2022 10:12:00 +0000 Subject: [PATCH] Fixing name resolution and Docker image. --- open_webui.sh | 12 ++++++++++ src/webui/Config.py | 6 ++--- src/webui/Dockerfile | 38 +++++++++++++++++--------------- src/webui/service/__init__.py | 1 + src/webui/service/main/routes.py | 5 ++++- 5 files changed, 40 insertions(+), 22 deletions(-) create mode 100755 open_webui.sh diff --git a/open_webui.sh b/open_webui.sh new file mode 100755 index 000000000..83d25d9c7 --- /dev/null +++ b/open_webui.sh @@ -0,0 +1,12 @@ +# this script opens the webui + +WEBUI_PROTO=`kubectl get service/webuiservice -n tf-dev -o jsonpath='{.spec.ports[0].name}'` +WEBUI_IP=`kubectl get service/webuiservice -n tf-dev -o jsonpath='{.spec.clusterIP}'` +WEBUI_PORT=`kubectl get service/webuiservice -n tf-dev -o jsonpath='{.spec.ports[0].port}'` +URL=${WEBUI_PROTO}://${WEBUI_IP}:${WEBUI_PORT} + +echo Opening web UI on URL ${URL} + +# curl -kL ${URL} + +python3 -m webbrowser ${URL} \ No newline at end of file diff --git a/src/webui/Config.py b/src/webui/Config.py index f47f04f1b..e4ea65f4a 100644 --- a/src/webui/Config.py +++ b/src/webui/Config.py @@ -2,7 +2,7 @@ import os import logging # General settings -LOG_LEVEL = logging.WARNING +LOG_LEVEL = logging.DEBUG # gRPC settings WEBUI_SERVICE_PORT = 8004 @@ -16,8 +16,8 @@ HOST = '0.0.0.0' # accepts connections coming from any ADDRESS DEBUG=False -CONTEXT_SERVICE_ADDRESS = os.environ.get('CONTEXT_SERVICE_ADDRESS', 'context') +CONTEXT_SERVICE_ADDRESS = os.environ.get('CONTEXTSERVICE_SERVICE_HOST', 'contextservice') CONTEXT_SERVICE_PORT = 1010 -DEVICE_SERVICE_ADDRESS = os.environ.get('DEVICE_SERVICE_ADDRESS', 'device') +DEVICE_SERVICE_ADDRESS = os.environ.get('DEVICESERVICE_SERVICE_HOST', 'deviceservice') DEVICE_SERVICE_PORT = 2020 diff --git a/src/webui/Dockerfile b/src/webui/Dockerfile index 17d63932a..c1e328e2b 100644 --- a/src/webui/Dockerfile +++ b/src/webui/Dockerfile @@ -14,29 +14,31 @@ ENV PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION='python' # wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \ # chmod +x /bin/grpc_health_probe -# Get generic Python packages -RUN python3 -m pip install --upgrade pip setuptools wheel pip-tools +# creating a user for security reasons +RUN groupadd -r webui && useradd --no-log-init -r -m -g webui webui +USER webui -# Set working directory -WORKDIR /var/teraflow - -# Create module sub-folders -RUN mkdir -p /var/teraflow/webui +# set working directory +RUN mkdir -p /home/webui/teraflow +WORKDIR /home/webui/teraflow # Get Python packages per module -COPY webui/requirements.in webui/requirements.in -RUN pip-compile --output-file=webui/requirements.txt webui/requirements.in -RUN python3 -m pip install -r webui/requirements.txt +ENV VIRTUAL_ENV=/home/webui/venv +RUN python3 -m venv ${VIRTUAL_ENV} +ENV PATH="${VIRTUAL_ENV}/bin:${PATH}" +COPY --chown=webui:webui webui/requirements.in /home/webui/teraflow/webui/requirements.in +RUN pip install --upgrade "pip<22" setuptools wheel pip-tools && pip-compile --output-file=webui/requirements.txt webui/requirements.in +RUN pip install -r webui/requirements.txt # Add files into working directory -COPY common/. common -COPY context/__init__.py context/__init__.py -COPY context/proto/. context/proto -COPY context/client/. context/client -COPY device/__init__.py device/__init__.py -COPY device/proto/. device/proto -COPY device/client/. device/client -COPY webui/. webui +COPY --chown=webui:webui common/. common +COPY --chown=webui:webui context/__init__.py context/__init__.py +COPY --chown=webui:webui context/proto/. context/proto +COPY --chown=webui:webui context/client/. context/client +COPY --chown=webui:webui device/__init__.py device/__init__.py +COPY --chown=webui:webui device/proto/. device/proto +COPY --chown=webui:webui device/client/. device/client +COPY --chown=webui:webui webui/. webui # Start webui service ENTRYPOINT ["python", "-m", "webui.service"] diff --git a/src/webui/service/__init__.py b/src/webui/service/__init__.py index 0a64c0384..28197a9f5 100644 --- a/src/webui/service/__init__.py +++ b/src/webui/service/__init__.py @@ -2,6 +2,7 @@ import os from flask import Flask, session from flask_healthz import healthz, HealthError +from webui.proto.context_pb2 import Empty from device.client.DeviceClient import DeviceClient from context.client.ContextClient import ContextClient from webui.Config import (CONTEXT_SERVICE_ADDRESS, CONTEXT_SERVICE_PORT, diff --git a/src/webui/service/main/routes.py b/src/webui/service/main/routes.py index ee49d8cb6..08ccdea4a 100644 --- a/src/webui/service/main/routes.py +++ b/src/webui/service/main/routes.py @@ -1,3 +1,5 @@ +import logging +import sys from flask import render_template, Blueprint, flash, session from webui.Config import CONTEXT_SERVICE_ADDRESS, CONTEXT_SERVICE_PORT from context.client.ContextClient import ContextClient @@ -8,11 +10,12 @@ main = Blueprint('main', __name__) context_client: ContextClient = ContextClient(CONTEXT_SERVICE_ADDRESS, CONTEXT_SERVICE_PORT) +logger = logging.getLogger(__name__) + @main.route('/', methods=['GET', 'POST']) def home(): # flash('This is an info message', 'info') # flash('This is a danger message', 'danger') - context_client.connect() response = context_client.ListContextIds(Empty()) context_client.close() -- GitLab