-
-
Notifications
You must be signed in to change notification settings - Fork 802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Load custom fields when creating the container #39
Conversation
docker/docker-entrypoint.sh
Outdated
for script in startup_scripts/*.py; do | ||
./manage.py shell --plain < $script | ||
done | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This opens a lot of possibilities for many customizations.
Dockerfile
Outdated
@@ -29,6 +29,7 @@ WORKDIR /opt/netbox | |||
RUN pip install -r requirements.txt | |||
|
|||
COPY docker/configuration.docker.py /opt/netbox/netbox/netbox/configuration.py | |||
COPY docker/startup_scripts /opt/netbox/netbox/startup_scripts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two ways to use this feature for our users, actually. But in order to be generally useful, having this in the Dockerfile
seems to be the wrong way..
User can either base of the original image and build their own Docker container (see example Dockerfile below), or they can just mount such files into the container using docker-compose (or whatever mechanism; see the example further down).
So, something like the following should probably be added to the README, along with a short explanation of the feature.
FROM ninech/netbox
COPY docker/startup_scripts /opt/netbox/netbox/startup_scripts
And I think it would be nice to adjust the default docker-compose.yml
file to include the following:
services:
netbox:
volumes:
- ./startup_scripts:/opt/netbox/netbox/startup_scripts
This would also require a .gitkeep
file in the folder ./startup_scripts/
.
) | ||
|
||
nine_urn.obj_type.add(device) | ||
nine_urn.obj_type.add(device_type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file seems to contain internal code, but it would suit as a good example as part of the README.md
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
docker/docker-entrypoint.sh
Outdated
@@ -39,6 +39,10 @@ if not User.objects.filter(username='${SUPERUSER_NAME}'): | |||
Token.objects.create(user=u, key='${SUPERUSER_API_TOKEN}') | |||
END | |||
|
|||
for script in startup_scripts/*.py; do | |||
./manage.py shell --plain < $script |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The files are launched every time the container starts, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should put quotation marks around $script
, in case a file is saved with a space in the name:
"${script}"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
ed3c341
to
759a2d5
Compare
README.md
Outdated
description='My own custom field' | ||
) | ||
|
||
my_custom_field.obj_type.add(device) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What impact does it have if the same obj_type is added over and over again with every start?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks to my out-of-this-world python skills and CustomField.objects.get_or_create
, not much: it will first try to fetch it, and if not present, will create it.
759a2d5
to
8e98b8d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you a lot for this contribution!
What's new?
This is a general mechanism to launch python scripts for Netbox: All the scripts put inside the
docker/startup_scripts
folder will be executed.