linuxserver / docker-netbox

GNU General Public License v3.0
79 stars 17 forks source link

Plugin install bootstrap #29

Closed omri-ice closed 1 year ago

omri-ice commented 2 years ago

linuxserver.io


Desired Behavior

Specify a list of netbox plugins to install (via ENV variable or mounting a requirements.txt file to a given directory) that on boot will install the listed packages to be used in the instance.

This option should support either pulling from pypi or installing local whl files that are mounted to the container.

Current Behavior

This function is not possible currently at runtime

Alternatives Considered

To achieve a similar result the docker image has to be built manually with the additional packages install on build.

github-actions[bot] commented 2 years ago

Thanks for opening your first issue here! Be sure to follow the bug or feature issue templates!

boomertsfx commented 2 years ago

I was just looking at this as well -- I want to enable LDAP (AD) auth, but the django-auth-ldap module isn't installed. The official https://github.com/netbox-community/netbox-docker lets you add -ldap to the image tag to get one with LDAP enabled.

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

absmith82 commented 2 years ago

I am also trying to get SAML to work using netbox-plugin-auth-saml2, and while I have gotten some things to work, I can't get it to fully provision users information due to this error.

Insufficient write permission to the media root

Having a way to bootstrap plugins would be awesome so that we don't have to hack at the container everytime a new version comes out.

lanefu commented 2 years ago

hello.. i found a work-around using some of the custom-init features baked into teh linuxserver.io base image.

since i just mount a /config volume to the container.. i created the file below, and also updated my configuration.py and it worked

root@myserver:/etc/netbox# cat config/custom-cont-init.d/00-install_netbox_plugins
pip3 install --no-cache-dir netbox-topology-views

there was a bit of an order of operations error (looked for plugin before pip) at startup in the container logs, but ultimately it all worked.

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

DarylStark commented 1 year ago

@lanefu yes, that works, but you have to start the container two times (the first one to install the plugin, the second one to include it into NetBox and create the needed tables). It might be better is the custom-cont-init.d scripts were run before the start of Netbox.

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

sgofferj commented 1 year ago

Since Netbox 3.3, the custom-cont-init.d method doesn't seem to work any more.

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

bryce-flex commented 1 year ago

So, I wanted to help the community a bit if I can. I was going to write a fix for this and push it up stream to see if linuxserver would incorporate it. Unfortunately, their support for this project seems abysmal, and I will be moving back to the official images soon.

But the community shouldn't have to suffer because of poor support as I will openly admit that linux servers docker image is significantly easier to get running. So heres a WORKAROUND for the plugin issue..

  1. make a folder and add script to folder
  2. add another folder called custom and add any netbox plugin configs as individual files .conf
  3. 
    PLUGINS_CONFIG = {

}

4. make a file called `plugin_requirements.txt` and `plugins.txt` 
plugin_requirements.txt
```file
netbox-topology-views
netbox-ipcalculator

plugins.txt

netbox_topology_views
netbox_ipcalculator
  1. Add any plugins pip requirements to plugin_requirements.txt and any netbox plugins to 'plugins.txt'
  2. Inside the dockerfile ADD <your folder> /custom-config
  3. Make the script executable RUN chmod u+x /custom-config/custom-netbox-entrypoint.sh
  4. Run this script as CMD command inside the dockerfile 'CMD /custom-config/netbox-entrypoint.sh'
  5. (this step might not be required) add ENTRYPOINT [ "/init" ]
#!/bin/bash

set -euo pipefail

# File locations
python_file="/config/configuration.py"
plugin_requirements="/custom-config/plugin_requirements.txt"
plugin_list="/custom-config/plugins.txt"

# Size check
threshold_size_kb=11                         # Specify the threshold size in bytes
threshold_size=$((threshold_size_kb * 1024)) # Convert threshold size to bytes

# Wait for file to exist and to be written to
counter=0
while true 
do
    if [ -e "$python_file" ] && [ $(stat -c %s $python_file) -ge $threshold_size ];
    then
        break
    fi
    sleep $counter
    ((counter++))
done

# Install pip plugins
pip install -r $plugin_requirements
echo "$plugin_requirements" >> "/opt/netbox/local_requirements.txt"

# Create a variable out of the text file
declare -a plugin_list
mapfile -t plugin_list < $plugin_list
plugin_string=$(printf "'%s'," "${plugin_list[@]}")
plugin_string=${plugin_string%?}

# Create the plugin string
plugin_string=$(printf "'%s'," ${plugin_list// /})
plugin_string=${plugin_string%,}

# Enable Plugins and comment logging so it can be added later
sed -i -e "s/PLUGINS *= *\[.*\]/PLUGINS = [$plugin_string]/" \
       -e "/^LOGGING = {}/s/^/# /" \
       "$python_file"

printf "\n\n## Custom Config ##\n" >> $python_file
cd /custom-config/custom
for FILE in *.conf ;
do
    echo "Adding Custom Config $FILE...";
    cat "$FILE" | tee -a "$python_file";
    printf "\n" >> $python_file
done

cd /
lanefu commented 1 year ago

was going to write a fix for this and push it up stream to see if linuxserver would incorporate it. Unfortunately, their support for this project seems abysmal, and I will be moving back to the official images soon.

Do you have a PR to reference?

bryce-flex commented 1 year ago

was going to write a fix for this and push it up stream to see if linuxserver would incorporate it. Unfortunately, their support for this project seems abysmal, and I will be moving back to the official images soon.

Do you have a PR to reference?

I just edited my original comment, should have enough information now on how to get this to work. Again, I'll be moving back to the original community edition, so I dont want to have to support this long term. Otherwise I would just write a fix to resolve this at the source.

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. This might be due to missing feedback from OP. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] commented 11 months ago

This issue is locked due to inactivity