Closed rduivenvoorde closed 2 years ago
That's because it runs the setup.py inside the docker build. That is also installing thingsboard-gateway it self inside the site-packages directory. If you should replace the setup.py with pip install -e .
then the thingsboard-gateway directory will stay where it is placed.
@LennardWesterveld mmm, ok, so then is this considered an issue in the container run?
Then I see 2 options:
The gateway SHOULD be installed in the containers python, but then the pythonpath used by the internals should be fixed to pickup the /thingsboard_gateway/extensions
The gateway should be ran from the . dir, without installing. Not sure what the 'setup.py' is adding? Also not sure if the extensions dir is picked up then...
Anybody can give info about what would be the best option here?
@rduivenvoorde this would help you I guess ;) https://gist.github.com/LennardWesterveld/bb8c2c95c2f6649c1306c56478caebd2 this is my docker file for now. In my opinion thingsboard-gateway, docker file itself should also move towards this setup.
@samson0v yes, thanks that is what I do now. In that issue, you say: "Hi ilseva, we fixed this bug so in the next release you can use docker image without extra configurations." That was nov 2021, did that already land in a (docker)-release?
Hi @rduivenvoorde it partially solved the problem but as you can see there are some exceptions. Will fix.
Hi, I also ran into this issue and I would suggest to keep this issue open until it is fixed. ie docker image users can use the ~/.tb-gateway/extensions
folder to put in their custom converter.
Describe the bug
In a setup running containers I fail to use a custom mqtt python extension in the mounted
/thingsboard_gateway/extensions
directory.The gateway only 'finds' the custom python code when I copy it IN the running container in:
/usr/local/lib/python3.9/site-packages/thingsboard_gateway-3.0.1-py3.9.egg/thingsboard_gateway/extensions/mqtt
To reproduce, I went back to a minimal setup by just using a official docker image on a laptop and copy the custom extension in it:
1) run vanilla official image:
docker run -it -v ~/.tb-gateway/logs:/thingsboard_gateway/logs -v ~/.tb-gateway/extensions:/thingsboard_gateway/extensions -v ~/.tb-gateway/config:/thingsboard_gateway/config --name tb-gateway thingsboard/tb-gateway
2) bring down, edit mqtt.json so it connects to an actual local broker, edit tb_gateway.yaml to connect to thingsboard.cloud for example
3) copy the available default
~/.tb-gateway/extensions:/thingsboard_gateway/extensions/mqtt/custom_mqtt_uplink_converter.py
and create acustom_mqtt_uplink_converter2.py
next to it (also edit the classname in it fromCustomMqttUplinkConverter
toCustomMqttUplinkConverter2
4) now edit the mqtt.json in
~/.tb-gateway/config:/thingsboard_gateway/config
to include a new topic, copy the custom/sensors one so it should use the new CustomMqttUplinkConverter2 classNow fire up the container again, and note the following in the output:
""2022-03-10 11:35:58" - |ERROR| - [mqtt_connector.py] - mqtt_connector - _on_connect - 269 - Cannot find converter for /custom/sensors2/+ topic"
I think I went pretty far in debugging this (adding some tools to an images, editing the python files to see some output, see https://github.com/thingsboard/thingsboard-gateway/issues/750), and I think the crux is that the pythonpath in the container is NOT picking up the python code in the
/thingsboard_gateway/extensions
directory.By going into the container and trying to call/see
TBModuleLoader.find_paths()
andTBModuleLoader.import_module(...)
I see:While I think(!) that that should also show the
/thingsboard_gateway/extensions
directory, isn't it?Going INTO the container:
docker exec -it tb-gateway /bin/bash
, you can see the custom_mqtt_uplink_converter2.py is there:but apparently not found... But copy it to the python install in the container:
cp /thingsboard_gateway/extensions/mqtt/custom_mqtt_uplink_converter2.py /usr/local//lib/python3.9/site-packages/thingsboard_gateway-3.0.1-py3.9.egg/thingsboard_gateway/extensions/mqtt/
And restarting the container:
docker start -a -i tb-gateway
and you will see the CustomMqttUplinkConverter2 being loaded:
I hope others can reproduce this in this way, Thanks.
Connector name (If bug in the some connector): mqtt (extension
Error traceback (If available):
Versions (please complete the following information):