Plugin development #746
Replies: 9 comments 16 replies
-
Reloading the container each time we change a .py file takes a few minutes. Is there a faster/better approach than reloading the entire container? |
Beta Was this translation helpful? Give feedback.
-
Here's how I'm doing it:
I hope this helps you a little bit.
FROM netboxcommunity/netbox:latest
# repeat the last line for every plugin you want to load editable and customize the path
COPY ./plugins /plugins
RUN /opt/netbox/venv/bin/pip install --editable /plugins/netbox-plugin-demo
version: '3.4'
services:
netbox:
ports:
- 8000:8080
build:
context: .
dockerfile: Dockerfile-Plugins
image: netbox:latest-plugins
volumes:
- ./plugins:/plugins
netbox-worker:
image: netbox:latest-plugins
build:
context: .
dockerfile: Dockerfile-Plugins
netbox-housekeeping:
image: netbox:latest-plugins
build:
context: .
dockerfile: Dockerfile-Plugins |
Beta Was this translation helpful? Give feedback.
-
@ryanmerolle A thousand thank-you's for creating a portable dev environment. I will be using it to develop my own plugin! May I make a suggestion? It would be good to create a repo that could serve as a template for the dev environment so your users don't have to weed out all the netbox-acls stuff to start using it. =) I'm happy to contribute if you need help. |
Beta Was this translation helpful? Give feedback.
-
I have not touched it in some time. I’m happy for someone to fork and improve the devcontianer portion or pr changes into the netbox-ACLs repo. |
Beta Was this translation helpful? Give feedback.
-
I just updated my open statement with a setup that (at least for me) works very well for both script/report and plugin development (with hot reload). Use it as a docker-compose override file. Warning Do not use it in production |
Beta Was this translation helpful? Give feedback.
-
Hi, I just came across this discussion.
More precisely, we need something like the following two changes in # Load correct Python3 env
# shellcheck disable=SC1091
source /opt/netbox/venv/bin/activate
INSTALL_CMD="/opt/netbox/venv/bin/pip install"
if [[ $DEVELOPMENT = "true" ]]; then
INSTALL_CMD="$INSTALL_CMD -e"
fi
for plugin in $(find /opt/netbox/netbox/plugins/ -mindepth 1 -maxdepth 1 -type d);
do
$INSTALL_CMD $plugin;
done # Launch whatever is passed by docker
# (i.e. the RUN instruction in the Dockerfile)
CMD="$@"
if [[ $DEVELOPMENT = "true" ]]; then
CMD="watchmedo auto-restart -d /opt/netbox/netbox/plugins/ bash -- -c 'exec $CMD'"
fi
echo "Starting Command: $CMD"
exec "$CMD" and the folder Now we only need to mount our plugins in the docker image and add an environment variable. |
Beta Was this translation helpful? Give feedback.
-
plugins.py is your friend, at least when it comes to netbox-docker. Late reply, but can help others. I'll write a summary on the appoach to netbox-docker and plugins when I get the time, try to iron out some quirks, and get more people onboard. The docker approach is in most cases the fastest, and especially for testing. But to reply to original question, both configuration.py and plugins.py will work, but plugins.py is preferred, and consider configuration.py static, or at least edited by the development. A tip vs pull, and redoing it after initial build. This is mostly for people new to docker and it's quirks, and if I can help just 1 person, then this is worth it. ;-) |
Beta Was this translation helpful? Give feedback.
-
I was wanting to solve this problem as well, combined some of the examples from this thread as well as how some of the other developers are handling it for their plugins and put it together in a repo to quickly spin up developer eviroments, install the plugin, and hot reload when working on plugins. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I was reworking my netbox docker setup but I found some difficulties to understand the wiki section about plugins. In particular it only mention how to import a plugin that is already on PyPi (https://github.com/netbox-community/netbox-docker/wiki/Using-Netbox-Plugins), but what if I'm developing my own without publishing it? Currently I have a custom docker file that place plugin projects inside
/opt/netbox/netbox
. This works, even without runningsetup.py install
command.Another confusing thing is the presence of plugins settings. In wiki it is stated to use
configuration.py
and I'm using it, but here is also aplugins.py
file. Which is the main difference here?During plugin developing things becomes a bit messy, I looked around in other repos and people are countering in different ways (mostly building their own docker image). My current setup is a docker-compose override that mount my plugin project folder as a bind volume inside
/opt/netbox/netbox
and overrides user and command statement, but the main image is always the official netbox-docker.Compose updated: 14/01/2024
This setup is also valid for reports and scripts.
Dockerfile:
Directory tree:
Docker-compose:
Warning
Do not use this docker compose override in production
With this approach I achieved a fully working dev environment with auto reload and will also extract migration files that may be generated. Right now I was wondering: "What if I have to develop another plugin? Is this the right way?"
For clarification here is my directory tree inside
/opt/netbox/netbox
:Atm I cannot put another setup.py from another custom plugin.
Beta Was this translation helpful? Give feedback.
All reactions