diff --git a/open_webui.sh b/open_webui.sh new file mode 100755 index 0000000000000000000000000000000000000000..83d25d9c784067c4a54398ac57a8958e477ecb2c --- /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 f47f04f1b7cd6e9023dd8508d31a2075e85a5219..e4ea65f4a93fa9a5d04d4c2bc796310b40294797 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 17d63932a6302c4a0f099f70f846ce7d2b164228..c1e328e2b17622f38705868cb9bd5c73fa0f0bff 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 0a64c038431ca3a99e584d7493c207484b0e919d..28197a9f58e5031d1a308262779e42df7598ca25 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 ee49d8cb6ac011d6234cd9cc4dd72dcd4fbf0d58..08ccdea4a94122a61c4875ddf520d544b5d2d4d1 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()