Skip to content
Snippets Groups Projects
Commit 52521186 authored by René Schöne's avatar René Schöne
Browse files

enable dockerized, configurable build

parent fb52508d
No related branches found
No related tags found
No related merge requests found
FROM python:3.9
COPY requirements.txt /requirements.txt
RUN pip install -r requirements.txt
COPY main.py utils.py cgv_connector_pb2.py /app/
COPY config/ /app/config
WORKDIR "/app"
ENTRYPOINT "python" "main.py"
# enter path to ros3rag/ros3rag.placeB/images
# image_directory: null
image_directory: /data/git/jastadd/ros3rag/ros3rag.placeB/images
# enter IP or hostname of mqtt broker
mqtt_server: "192.168.0.122"
......@@ -5,6 +5,8 @@ import threading
import time
import base64
import flask
import yaml
import sys
import dash
from dash import dcc
......@@ -17,15 +19,11 @@ from google.protobuf import json_format
import cgv_connector_pb2
import utils
CONFIG_FILENAME = 'config.yaml'
config = {}
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
fixed_svg_filename = "ros3rag/ros3rag.placeB/images/2022-05-04T10-19-30-9155.svg"
fixed_svg_filename = "2022-05-04T10-19-30-9155.svg"
# fixed_svg_filename = ""
image_directory = '/data/git/jastadd/ros3rag/ros3rag.placeB/images/'
static_image_route = '/static/'
MQTT_SERVER = '192.168.0.122'
# MQTT_SERVER = 'localhost'
mqttc = mqtt.Client()
# mqtt client connected?
......@@ -300,7 +298,7 @@ app.layout = html.Div([
html.P(id='model-b-svg-name', style={"margin-left": "15px"}),
], className='row', style=dict(display='flex')),
html.Div([
html.Img(id='model-b-svg-img', src="/static/{}".format(fixed_svg_filename))
html.Img(id='model-b-svg-img', src="/static/{}".format("undefined.svg"))
], style=dict(position='fixed', overflow='scroll', width='100%')),
# html.Img(src="data:image/svg;base64,{}".format(base64.b64encode(open(fixed_svg_filename, 'rb').read()).decode()))
], style=tab_style, selected_style=tab_style) # Tab "SVG Model B"
......@@ -558,6 +556,7 @@ def update_svg_name(name):
@app.server.route('{}<image_path>.svg'.format(static_image_route))
def serve_image(image_path):
image_name = '{}.svg'.format(image_path)
image_directory = config['image_directory']
print('{}/{}'.format(image_directory, image_name))
# if image_name not in list_of_images:
# raise Exception('"{}" is excluded from the allowed static files'.format(image_path))
......@@ -566,7 +565,7 @@ def serve_image(image_path):
def on_mqtt_connect(_client, _userdata, _flags, _rc, _properties=None):
# Callback for mqtt client when connected
print(f'\nConnected to {MQTT_SERVER} at {datetime.datetime.now().isoformat()}')
print(f'\nConnected to {config["mqtt_server"]} at {datetime.datetime.now().isoformat()}')
ready_event.set()
mqttc.subscribe(topic='#')
threading.Thread(target=publish_test_message).start()
......@@ -610,12 +609,30 @@ def publish_test_message():
if __name__ == '__main__':
print('Starting web-ros3rag')
try:
with open(CONFIG_FILENAME, 'r') as fd:
config = yaml.safe_load(fd)
except FileNotFoundError as e:
print(f'Could not open {CONFIG_FILENAME}. Aborting.')
sys.exit(1)
if not config['image_directory']:
print('image_directory not specified. Aborting.')
sys.exit(1)
dockerized = config.get('docker')
mqttc.on_connect = on_mqtt_connect
mqttc.on_disconnect = on_mqtt_disconnect
mqttc.on_message = on_mqtt_message
mqttc.reconnect_delay_set(max_delay=2)
mqttc.connect_async(MQTT_SERVER)
mqttc.connect_async(config['mqtt_server'])
mqttc.loop_start()
if not ready_event.wait(2.0): # wait 2 seconds
print('Could not connect to mqtt in time!')
app.run_server(debug=True)
print(f'Could not connect to mqtt at {config["mqtt_server"]} in time!')
if dockerized:
app.run_server(host='0.0.0.0', port=8050)
else:
app.run_server(debug=True, port=8050)
......@@ -2,3 +2,4 @@ paho-mqtt~=1.6.1
dash~=2.3.1
visdcc~=0.0.50
protobuf~=3.20.0
pyyaml~=6.0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment