Pull local pip config or patches into netbox environment during upgrade #5700

Closed
opened 2025-12-29 19:31:36 +01:00 by adam · 2 comments
Owner

Originally created by @amk1969 on GitHub (Nov 21, 2021).

NetBox version

v3.0.10

Feature type

Change to existing functionality

Proposed functionality

The upgrade.sh script requires manual updates in case site specific pip configuration of patches are needed. Hereby I would like to propose minor update to the script that would consider pip.conf and patch files placed into /opt/netbox (similar to local_requirements.txt) and apply them during upgrade process.

I have added 2 lines to the upgrade script and a related information into documentation, but before submitting the pull request it seems that a feature should be accepted, hence this entry.

Use case

Admin who requires his specific configuration into Netbox virtual environment does not need to edit the upgrade script but can carry over pip.conf and eventual patch files from the previous version of Netbox.

Database changes

None

External dependencies

None

Originally created by @amk1969 on GitHub (Nov 21, 2021). ### NetBox version v3.0.10 ### Feature type Change to existing functionality ### Proposed functionality The upgrade.sh script requires manual updates in case site specific pip configuration of patches are needed. Hereby I would like to propose minor update to the script that would consider pip.conf and patch files placed into /opt/netbox (similar to local_requirements.txt) and apply them during upgrade process. I have added 2 lines to the upgrade script and a related information into documentation, but before submitting the pull request it seems that a feature should be accepted, hence this entry. ### Use case Admin who requires his specific configuration into Netbox virtual environment does not need to edit the upgrade script but can carry over pip.conf and eventual patch files from the previous version of Netbox. ### Database changes None ### External dependencies None
adam added the type: feature label 2025-12-29 19:31:36 +01:00
adam closed this issue 2025-12-29 19:31:36 +01:00
Author
Owner

@jeremystretch commented on GitHub (Nov 22, 2021):

The upgrade.sh script requires manual updates in case site specific pip configuration of patches are needed.

Unfortunately, we need to draw the line somewhere with regard to how much customization of the upgrade process the maintainers will support, and IMO we've found a good balance. If you need to customize the installation or upgrade processes beyond the tooling already provided, you are certainly free to do so but you'll need to develop and maintain your own tooling to support these.

@jeremystretch commented on GitHub (Nov 22, 2021): > The upgrade.sh script requires manual updates in case site specific pip configuration of patches are needed. Unfortunately, we need to draw the line somewhere with regard to how much customization of the upgrade process the maintainers will support, and IMO we've found a good balance. If you need to customize the installation or upgrade processes beyond the tooling already provided, you are certainly free to do so but you'll need to develop and maintain your own tooling to support these.
Author
Owner

@amk1969 commented on GitHub (Nov 22, 2021):

I somehow do not get how can my suggestion destroy some balance that is forcing others to reinvent the wheel, but I do not need to understand it. I would for example also update the documentation with some instructions for activation of an outgoing proxy or trusted root certificate for the install process. And remove the bogus claim about Centos repositories missing python beyond 3.6.

Rejecting the contribution does not prevent me to put the diff here for the benefit of others who need to use an internal pypi repository. From the blob below, the last line with pip.conf needs to be placed into upgrade.sh at the appropriate place, without the leading '+'

diff --git a/docs/installation/3-netbox.md b/docs/installation/3-netbox.md
index 8b31ed67d..4bc2d0503 100644
--- a/docs/installation/3-netbox.md
+++ b/docs/installation/3-netbox.md
@@ -220,6 +220,16 @@ By default, NetBox will use the local filesystem to store uploaded files. To use
 sudo sh -c "echo 'django-storages' >> /opt/netbox/local_requirements.txt"
 ```
 
+In case your site has specific requirement for pip configuration, create a pip.conf file that will be taken into the virtual environment. In similar fashion, also all `*.patch` files in /opt/netbox will be applied after install.
+
+```no-highlight
+cat <<EOT | sudo tee /opt/netbox/pip.conf >/dev/null
+[global]
+index-url = http://local-repository/simple
+trusted-host = local-repository
+EOT
+```
+
 ## Run the Upgrade Script
 
 Once NetBox has been configured, we're ready to proceed with the actual installation. We'll run the packaged upgrade script (`upgrade.sh`) to perform the following actions:
diff --git a/docs/installation/upgrading.md b/docs/installation/upgrading.md
index 4bc0b2377..6b953c01b 100644
--- a/docs/installation/upgrading.md
+++ b/docs/installation/upgrading.md
@@ -30,10 +30,11 @@ sudo tar -xzf vX.Y.Z.tar.gz -C /opt
 sudo ln -sfn /opt/netbox-X.Y.Z/ /opt/netbox
 ```
 
-Copy `local_requirements.txt`, `configuration.py`, and `ldap_config.py` (if present) from the current installation to the new version:
+Copy `local_requirements.txt`, `configuration.py`, and `ldap_config.py` or `pip.conf` (if present) from the current installation to the new version:
 
 ```no-highlight
 sudo cp /opt/netbox-X.Y.Z/local_requirements.txt /opt/netbox/
+sudo cp /opt/netbox-X.Y.Z/pip.conf /opt/netbox/
 sudo cp /opt/netbox-X.Y.Z/netbox/netbox/configuration.py /opt/netbox/netbox/netbox/
 sudo cp /opt/netbox-X.Y.Z/netbox/netbox/ldap_config.py /opt/netbox/netbox/netbox/
 ```
diff --git a/upgrade.sh b/upgrade.sh
index 67b8aaa89..bc367fd93 100755
--- a/upgrade.sh
+++ b/upgrade.sh
@@ -31,6 +31,9 @@ eval $COMMAND || {
   exit 1
 }
 
+# Copy site specific pip configuration to the virtual environment
+[ -f pip.conf ] && { cp pip.conf ${VIRTUALENV} || exit 1 ;}
+
 # Activate the virtual environment
 source "${VIRTUALENV}/bin/activate"

@@ -61,6 +64,9 @@ else
   echo "Skipping local dependencies (local_requirements.txt not found)"
 fi
 
+# Apply site specific patches to the installed packages
+find . -maxdepth 1 -name '*.patch' -print0 | xargs -0 -n1 bash -c "patch -N -p1 <\"\$0\" || { echo in file \"\$0\" ; exit 255 ;}"
+
 # Apply any database migrations
 COMMAND="python3 netbox/manage.py migrate"
 echo "Applying database migrations ($COMMAND)..."
@amk1969 commented on GitHub (Nov 22, 2021): I somehow do not get how can my suggestion destroy some balance that is forcing others to reinvent the wheel, but I do not need to understand it. I would for example also update the documentation with some instructions for activation of an outgoing proxy or trusted root certificate for the install process. And remove the bogus claim about Centos repositories missing python beyond 3.6. Rejecting the contribution does not prevent me to put the diff here for the benefit of others who need to use an internal pypi repository. From the blob below, the last line with pip.conf needs to be placed into upgrade.sh at the appropriate place, without the leading '+' ```` diff --git a/docs/installation/3-netbox.md b/docs/installation/3-netbox.md index 8b31ed67d..4bc2d0503 100644 --- a/docs/installation/3-netbox.md +++ b/docs/installation/3-netbox.md @@ -220,6 +220,16 @@ By default, NetBox will use the local filesystem to store uploaded files. To use sudo sh -c "echo 'django-storages' >> /opt/netbox/local_requirements.txt" ``` +In case your site has specific requirement for pip configuration, create a pip.conf file that will be taken into the virtual environment. In similar fashion, also all `*.patch` files in /opt/netbox will be applied after install. + +```no-highlight +cat <<EOT | sudo tee /opt/netbox/pip.conf >/dev/null +[global] +index-url = http://local-repository/simple +trusted-host = local-repository +EOT +``` + ## Run the Upgrade Script Once NetBox has been configured, we're ready to proceed with the actual installation. We'll run the packaged upgrade script (`upgrade.sh`) to perform the following actions: diff --git a/docs/installation/upgrading.md b/docs/installation/upgrading.md index 4bc0b2377..6b953c01b 100644 --- a/docs/installation/upgrading.md +++ b/docs/installation/upgrading.md @@ -30,10 +30,11 @@ sudo tar -xzf vX.Y.Z.tar.gz -C /opt sudo ln -sfn /opt/netbox-X.Y.Z/ /opt/netbox ``` -Copy `local_requirements.txt`, `configuration.py`, and `ldap_config.py` (if present) from the current installation to the new version: +Copy `local_requirements.txt`, `configuration.py`, and `ldap_config.py` or `pip.conf` (if present) from the current installation to the new version: ```no-highlight sudo cp /opt/netbox-X.Y.Z/local_requirements.txt /opt/netbox/ +sudo cp /opt/netbox-X.Y.Z/pip.conf /opt/netbox/ sudo cp /opt/netbox-X.Y.Z/netbox/netbox/configuration.py /opt/netbox/netbox/netbox/ sudo cp /opt/netbox-X.Y.Z/netbox/netbox/ldap_config.py /opt/netbox/netbox/netbox/ ``` diff --git a/upgrade.sh b/upgrade.sh index 67b8aaa89..bc367fd93 100755 --- a/upgrade.sh +++ b/upgrade.sh @@ -31,6 +31,9 @@ eval $COMMAND || { exit 1 } +# Copy site specific pip configuration to the virtual environment +[ -f pip.conf ] && { cp pip.conf ${VIRTUALENV} || exit 1 ;} + # Activate the virtual environment source "${VIRTUALENV}/bin/activate" @@ -61,6 +64,9 @@ else echo "Skipping local dependencies (local_requirements.txt not found)" fi +# Apply site specific patches to the installed packages +find . -maxdepth 1 -name '*.patch' -print0 | xargs -0 -n1 bash -c "patch -N -p1 <\"\$0\" || { echo in file \"\$0\" ; exit 255 ;}" + # Apply any database migrations COMMAND="python3 netbox/manage.py migrate" echo "Applying database migrations ($COMMAND)..." ````
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#5700