I've been facing an issue with which I need some help.
We're working on a project that is dockerized and runs on a docker-compose stack. Our code is mounted in the container to allow live-reload of changes. But this project uses a proprietary library that may require changes. The goal would be to have this library mounted in the container as well since the only way currently is to install it with poetry add ../ArcheologCommon and run everything locally (without docker). This is a real pain since we have many configurations and 7+ services to run
The first solution I've found was to mount my local venv into the container but that doesn't work for multiple reasons:
- Mounting the entire venv results in hardcoded absolute paths in the
env/bin/activatefolder that is usable only by the host. - Mount only the
venv/libfolder to avoid this hardcoded path issue.
This works very well until I run the poetry add ../ArcheologCommon, which gives me a ModuleNotFoundError: No module named 'archeolog_common' exception in my container.
Looking around in what poetry did in my venv, I find that my library became an *.egg-link file containing the absolute path of my library on my laptop
~/ ➤ docker exec -ti backend bash
www-data@467190e2f634:~/backend$ cat .venv/lib/python3.8/site-packages/archeolog-common.egg-link
/home/path/to/ArcheologCommon
The only workaround I found is to mount my local copy of the code directly into the site-packages of the venv, in place of the code already present there:
services:
backend:
command: server.py --bind 0.0.0.0 --port 9000 --reload-dir /var/www/backend --reload-dir /opt/venv/lib/python3.8/site-packages/archeolog_common
# [ ...]
volumes:
- ...
- ../../ArcheologCommon/archeolog_common:/opt/venv/lib/python3.8/site-packages/archeolog_common:ro
Which results in changes properly detected and working just fine.
WARNING: StatReload detected file change in '/opt/venv/lib/python3.8/site-packages/archeolog_common/models/graph.py'. Reloading...
INFO: Shutting down
INFO: Finished server process [156]
INFO: Started server process [191]
I think this is a terrible solution (which works, so I still give it credits) but I wonder if there are any better solutions?
PS: I've found similar issues on SO about this, but none of them were about using everything in Docker containers, which is my main requirement since it's a huge hassle to work outside of our docker-compose stack.
Thanks for reading me!