Skip to content

Docker venv - #8502

Closed
SchrodingersGat wants to merge 3 commits into
inventree:masterfrom
SchrodingersGat:docker-venv
Closed

SchrodingersGat wants to merge 3 commits into
inventree:masterfrom
SchrodingersGat:docker-venv

Conversation

@SchrodingersGat

@SchrodingersGat SchrodingersGat commented Nov 16, 2024 •

Copy link
Copy Markdown
Member

This PR changes behavior under docker, using the python virtual environment even in "production" mode.

The purpose for this is to ensure that any extra python packages that get installed (i.e. plugins) persist between container runs, and across the webserver and worker containers.

The Problem

Ref: #7709

The webserver and background worker processes run on separate container instances - meaning that they have different python package installation environments.

Thus, if a plugin is installed via the webserver (in the admin interface), it gets installed into the webserver container instance, but the background worker instance does not have a copy of the newly installed plugin code. When it tries to find it, it fails, and can result in some different subtle bugs (as well as the obvious "plugin does not work" issue).

As an added complication, if the background worker process is restarted, it may successfully result in the plugin being correctly installed inside that container, due to the auto-install behaviour of plugins.txt - however, this is kinda flaky and the static files don't get copied across reliably in this scenario.

The Solution

In the init.sh entrypoint script for both containers, active a python virtual environment which points to a subdirectory on the externally mounted volume. This means that:

A) Installed plugin packages persist on the host machine (via mounted volume)
B) Installed plugin packages are shared between the webserver and background worker containers

Testing

You can test that this works on an existing docker installation by adding the following line to the .env file:

# Enable python virtual environment
INVENTREE_PY_ENV=/home/inventree/data/venv

Then, restart the docker containers.

Install a new plugin and verify that the plugin has been installed in the <data>/venv/ subdirectory in the mounted volume

Base Packages

Base python packages (that is, everything in requirements.txt needed for core InvenTree functionality) is installed inside the container image - when the container is built. Thus, only secondary packages (user installed plugins, etc) will persist in the external venv.

@SchrodingersGat SchrodingersGat added bug Identifies a bug which needs to be addressed plugin Plugin ecosystem docker Docker / docker-compose setup Relates to the InvenTree setup / installation process breaking Indicates a major update or change which breaks compatibility documentation backport Apply this label to a PR to enable auto-backport action backport-to-0.16.x labels Nov 16, 2024
@SchrodingersGat SchrodingersGat added this to the 0.17.0 milestone Nov 16, 2024
@netlify

netlify Bot commented Nov 16, 2024 •

Copy link
Copy Markdown

✅ Deploy Preview for inventree-web-pui-preview canceled.

Name Link
🔨 Latest commit ffdca02
🔍 Latest deploy log https://app.netlify.com/sites/inventree-web-pui-preview/deploys/673915f346e35c000894a75d

@wolflu05 wolflu05 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for investigating this. This could indeed fix the issues. I will have to take a closer look and test this myself the next days. This may also explain the <property xxx> strings shown instead of the plugin names, but not sure about that one.

Comment thread contrib/container/Dockerfile Resolved
env -> venv
@SchrodingersGat

SchrodingersGat commented Nov 16, 2024 •

Copy link
Copy Markdown
Member Author

It does not appear to by working correctly yet, as the server runs system python and invoke binnaries (/usr/local/bin/python) rather than the python in the "venv" directory (/home/inventree/data/venv/bin/python) - which means that the venv is bypassed anyway.

A fully functional solution might be a ltitle trickier here. What we want is for:

a) All base-level packages are installed into the docker image (to prevent changes to versions of pinned packages, and ensure the image is distributed with a known set of python packages
b) All "plugin" (user installed) packages should be installed to a persistent directory in the mounted volume
c) Ideally, the python executable is the system one, not located in the external volume

Perhaps instead of using a venv for docker, we want to expose the --user directory to the external volume?

@SchrodingersGat

Copy link
Copy Markdown
Member Author

Closing this out in favour of #8503

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport Apply this label to a PR to enable auto-backport action breaking Indicates a major update or change which breaks compatibility bug Identifies a bug which needs to be addressed docker Docker / docker-compose documentation plugin Plugin ecosystem setup Relates to the InvenTree setup / installation process

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants