Plugin development workflow with docker

61 views
Skip to first unread message

Hoanh An

unread,
Apr 23, 2020, 4:28:45 PM4/23/20
to NetBox
I've been following the documentation to develop a plugin for the new 2.8 release. Now I want to be able to use and verify its use cases, preferably using Docker. It seems like the way netbox-docker works is that it always clones the latest version on Github and build the Dockerfiles. However, what if I have the new release 2.8 and make changes to use the new plugin that I just develop, how can I build Docker on top of these new changes and verify if it works?

Sander Steffann

unread,
Apr 23, 2020, 4:37:46 PM4/23/20
to Hoanh An, NetBox
Hi,

> I've been following the documentation to develop a plugin for the new 2.8 release. Now I want to be able to use and verify its use cases, preferably using Docker. It seems like the way netbox-docker works is that it always clones the latest version on Github and build the Dockerfiles. However, what if I have the new release 2.8 and make changes to use the new plugin that I just develop, how can I build Docker on top of these new changes and verify if it works?

I'd take the netbox-docker image as the base and then add the plugin you're developing to it. During development doing that with a bind mount will allow you to change the code of your plugin without rebuilding the container on every single change.

Cheers,
Sander

signature.asc

Hoanh An

unread,
Apr 23, 2020, 4:54:53 PM4/23/20
to NetBox
Thanks for the quick reply. I understand that I would need to use the netbox-docker image as the base and add the plugin to it, though I am not sure how to do so. How would I make a Docker build out of the new changes that I just apply locally to my netbox repo? Since ever time I run `docker-compose up` within netbox-docker, it will clone a new copy of the latest and build from there (but not my new changes)? How can I build Dockerfile directly from my netbox repo?

Sander Steffann

unread,
Apr 24, 2020, 6:35:08 AM4/24/20
to Hoanh An, NetBox
Hi,

> Thanks for the quick reply. I understand that I would need to use the netbox-docker image as the base and add the plugin to it, though I am not sure how to do so. How would I make a Docker build out of the new changes that I just apply locally to my netbox repo? Since ever time I run `docker-compose up` within netbox-docker, it will clone a new copy of the latest and build from there (but not my new changes)? How can I build Dockerfile directly from my netbox repo?

For plugin development you shouldn't be touching the NetBox code itself. Store your plugin with a bind mount somewhere in the container, and add `-d /somewhere/in/your/container` to /opt/netbox/local_requirements.txt. Adjust your configuration.py accordingly, and you should have a docker development container for your plugin.

Cheers,
Sander

signature.asc

Christopher Mills

unread,
Apr 24, 2020, 7:10:14 AM4/24/20
to NetBox
I'm not sure whether this is the right way to do this, but I have a similar requirement for a custom image and here is what I do. I am developing a custom script that requires additional Python modules. I am using Ansible to deploy netbox-docker to my host. Rather than rebuilding the base image all the time, what I do is, prior to running 'docker-compose up', I build a new docker image based on netboxcommunity/netbox:latest, tag it as netbox:some_custom_tag then inject a docker-compose.override.yml file which contains (amongst other stuff):

services:
  netbox:
    image: netbox:some_custom_tag

When you then run docker-compose up, it will launch your custom image for the netbox image rather than the stock one, leaving all the others as they are.

Seems to work!

I'd combine this with a bind mount so you can make changes to your plugin code without having to rebuild and restart your image as suggested above.

Hoanh An

unread,
Apr 28, 2020, 5:25:15 PM4/28/20
to NetBox
I am not sure what you mean by "add `-d /somewhere/in/your/container` to /opt/netbox/local_requirements.txt".

Given this plugin example (https://github.com/netbox-community/netbox-animal-sounds), I tried to bind mount it my netbox container, exec-ed there, and installed it directly. I also updated the configuration.py on my host machine to include my plugin as well. It did not seem to work as I did not see anything changed in the Netbox UI (or maybe I was not sure how to find them). These two documentations are the ones that I tried to follow through:

Any pointer on how that work would be really helpful. Thanks
Reply all
Reply to author
Forward
0 new messages