From 5741d2e59cd8de3387be9c0b32c04639617c18f1 Mon Sep 17 00:00:00 2001 From: Tobias Genannt Date: Wed, 6 Sep 2023 16:26:23 +0200 Subject: [PATCH] Simplify plugin installation Netbox plugins can now be mounted into the container and will be loaded automatically from the mounted path. A configuration file to enabled the plugin in has to be mounted additionally. To install a plugin from outside the container you need to use the same Python version as is used in the container. At the moment that is Python 3.11. Assuming you are in the netbox-docker directory and using the default configuration, just run this command, to install the netbox-initializers plugin: pip install --target=plugins netbox-initializers --- Dockerfile | 4 +++- docker-compose.yml | 1 + plugins/.gitignore | 1 + plugins/.gitkeep | 0 4 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 plugins/.gitignore create mode 100644 plugins/.gitkeep diff --git a/Dockerfile b/Dockerfile index 558f764..58be608 100644 --- a/Dockerfile +++ b/Dockerfile @@ -97,9 +97,11 @@ WORKDIR /opt/netbox/netbox # Must set permissions for '/opt/netbox/netbox/media' directory # to g+w so that pictures can be uploaded to netbox. -RUN mkdir -p static /opt/unit/state/ /opt/unit/tmp/ \ +RUN mkdir -p static /opt/unit/state/ /opt/unit/tmp/ /opt/netbox/plugins \ && chown -R unit:root /opt/unit/ media reports scripts \ && chmod -R g+w /opt/unit/ media reports scripts \ + # Add additional path to sys.path, to enable plugin installation without having to build a new Docker image + && echo "/opt/netbox/plugins" > /opt/netbox/venv/lib/python3.11/site-packages/plugins.pth \ && cd /opt/netbox/ && SECRET_KEY="dummyKeyWithMinimumLength-------------------------" /opt/netbox/venv/bin/python -m mkdocs build \ --config-file /opt/netbox/mkdocs.yml --site-dir /opt/netbox/netbox/project-static/docs/ \ && SECRET_KEY="dummyKeyWithMinimumLength-------------------------" /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py collectstatic --no-input diff --git a/docker-compose.yml b/docker-compose.yml index 38cd658..a61fd69 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,6 +15,7 @@ services: test: "curl -f http://localhost:8080/api/ || exit 1" volumes: - ./configuration:/etc/netbox/config:z,ro + - ./plugins:/opt/netbox/plugins:z,ro - netbox-media-files:/opt/netbox/netbox/media:rw - netbox-reports-files:/opt/netbox/netbox/reports:rw - netbox-scripts-files:/opt/netbox/netbox/scripts:rw diff --git a/plugins/.gitignore b/plugins/.gitignore new file mode 100644 index 0000000..72e8ffc --- /dev/null +++ b/plugins/.gitignore @@ -0,0 +1 @@ +* diff --git a/plugins/.gitkeep b/plugins/.gitkeep new file mode 100644 index 0000000..e69de29