Skip to content

Commit 742560c

Browse files
authored
Merge pull request #361 from tobiasge/nginx-unit
Use Nginx Unit to serve the application
2 parents 380cb77 + d273391 commit 742560c

15 files changed

+135
-136
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,3 @@ If your log is very long, create a Gist instead (and post the link to it): https
6565
```text
6666
LOG LOG LOG
6767
```
68-
69-
The output of `docker-compose logs nginx`:
70-
<!--
71-
Only if you have gotten a 5xx http error, else delete this section.
72-
If your log is very long, create a Gist instead (and post the link to it): https://gist.github.com
73-
-->
74-
75-
```text
76-
LOG LOG LOG
77-
```

.github/workflows/push.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- ./build.sh develop
2020
docker_from:
2121
- '' # use the default of the build script
22-
# - python:3.10-rc-alpine # disable until dependencies work
22+
- alpine:edge
2323
fail-fast: false
2424
runs-on: ubuntu-latest
2525
name: Builds new Netbox Docker Images

Dockerfile

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,15 @@ RUN apk add --no-cache \
1212
libffi-dev \
1313
libxslt-dev \
1414
openldap-dev \
15-
postgresql-dev
16-
17-
WORKDIR /install
18-
19-
RUN pip install --prefix="/install" --no-warn-script-location \
20-
# gunicorn is used for launching netbox
21-
gunicorn \
22-
greenlet \
23-
eventlet \
24-
# napalm is used for gathering information from network devices
25-
napalm \
26-
# ruamel is used in startup_scripts
27-
'ruamel.yaml>=0.15,<0.16' \
28-
# django_auth_ldap is required for ldap
29-
django_auth_ldap \
30-
# django-storages was introduced in 2.7 and is optional
31-
django-storages
15+
postgresql-dev \
16+
py3-pip \
17+
python3-dev \
18+
&& python3 -m venv /opt/netbox/venv \
19+
&& /opt/netbox/venv/bin/python3 -m pip install --upgrade pip setuptools
3220

3321
ARG NETBOX_PATH
34-
COPY ${NETBOX_PATH}/requirements.txt /
35-
RUN pip install --prefix="/install" --no-warn-script-location -r /requirements.txt
22+
COPY ${NETBOX_PATH}/requirements.txt requirements-container.txt /
23+
RUN /opt/netbox/venv/bin/pip install -r /requirements.txt -r /requirements-container.txt
3624

3725
###
3826
# Main stage
@@ -44,42 +32,46 @@ FROM ${FROM} as main
4432
RUN apk add --no-cache \
4533
bash \
4634
ca-certificates \
35+
curl \
4736
graphviz \
4837
libevent \
4938
libffi \
5039
libjpeg-turbo \
5140
libressl \
5241
libxslt \
5342
postgresql-libs \
54-
ttf-ubuntu-font-family
43+
python3 \
44+
py3-pip \
45+
ttf-ubuntu-font-family \
46+
unit \
47+
unit-python3
5548

5649
WORKDIR /opt
5750

58-
COPY --from=builder /install /usr/local
51+
COPY --from=builder /opt/netbox/venv /opt/netbox/venv
5952

6053
ARG NETBOX_PATH
6154
COPY ${NETBOX_PATH} /opt/netbox
6255

6356
COPY docker/configuration.docker.py /opt/netbox/netbox/netbox/configuration.py
64-
COPY docker/gunicorn_config.py /etc/netbox/
65-
COPY docker/nginx.conf /etc/netbox-nginx/nginx.conf
6657
COPY docker/docker-entrypoint.sh /opt/netbox/docker-entrypoint.sh
58+
COPY docker/launch-netbox.sh /opt/netbox/launch-netbox.sh
6759
COPY startup_scripts/ /opt/netbox/startup_scripts/
6860
COPY initializers/ /opt/netbox/initializers/
6961
COPY configuration/ /etc/netbox/config/
62+
COPY docker/nginx-unit.json /etc/unit/
7063

7164
WORKDIR /opt/netbox/netbox
7265

73-
# Must set permissions for '/opt/netbox/netbox/static' directory
74-
# to g+w so that `./manage.py collectstatic` can be executed during
75-
# container startup.
7666
# Must set permissions for '/opt/netbox/netbox/media' directory
7767
# to g+w so that pictures can be uploaded to netbox.
78-
RUN mkdir static && chmod -R g+w static media
68+
RUN mkdir -p static /opt/unit/state/ /opt/unit/tmp/ \
69+
&& chmod -R g+w media /opt/unit/ \
70+
&& SECRET_KEY="dummy" /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py collectstatic --no-input
7971

8072
ENTRYPOINT [ "/opt/netbox/docker-entrypoint.sh" ]
8173

82-
CMD ["gunicorn", "-c /etc/netbox/gunicorn_config.py", "netbox.wsgi"]
74+
CMD [ "/opt/netbox/launch-netbox.sh" ]
8375

8476
LABEL ORIGINAL_TAG="" \
8577
NETBOX_GIT_BRANCH="" \

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ cd netbox-docker
5656
tee docker-compose.override.yml <<EOF
5757
version: '3.4'
5858
services:
59-
nginx:
59+
netbox:
6060
ports:
6161
- 8000:8080
6262
EOF

build.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ if [ "${1}x" == "x" ] || [ "${1}" == "--help" ] || [ "${1}" == "-h" ]; then
4949
echo " DOCKERFILE The name of Dockerfile to use."
5050
echo " Default: Dockerfile"
5151
echo " DOCKER_FROM The base image to use."
52-
echo " Default: 'python:3.9-alpine'"
52+
echo " Default: 'alpine:3.13'"
5353
echo " DOCKER_TARGET A specific target to build."
5454
echo " It's currently not possible to pass multiple targets."
5555
echo " Default: main ldap"
@@ -106,7 +106,7 @@ else
106106
fi
107107

108108
###
109-
# Variables for fetching the source
109+
# Variables for fetching the Netbox source
110110
###
111111
SRC_ORG="${SRC_ORG-netbox-community}"
112112
SRC_REPO="${SRC_REPO-netbox}"
@@ -115,10 +115,10 @@ URL="${URL-https://github.com/${SRC_ORG}/${SRC_REPO}.git}"
115115
NETBOX_PATH="${NETBOX_PATH-.netbox}"
116116

117117
###
118-
# Fetching the source
118+
# Fetching the Netbox source
119119
###
120120
if [ "${2}" != "--push-only" ] && [ -z "${SKIP_GIT}" ] ; then
121-
echo "🌐 Checking out '${NETBOX_BRANCH}' of netbox from the url '${URL}' into '${NETBOX_PATH}'"
121+
echo "🌐 Checking out '${NETBOX_BRANCH}' of Netbox from the url '${URL}' into '${NETBOX_PATH}'"
122122
if [ ! -d "${NETBOX_PATH}" ]; then
123123
$DRY git clone -q --depth 10 -b "${NETBOX_BRANCH}" "${URL}" "${NETBOX_PATH}"
124124
fi
@@ -135,7 +135,7 @@ if [ "${2}" != "--push-only" ] && [ -z "${SKIP_GIT}" ] ; then
135135
$DRY git checkout -qf FETCH_HEAD
136136
$DRY git prune
137137
)
138-
echo "✅ Checked out netbox"
138+
echo "✅ Checked out Netbox"
139139
fi
140140

141141
###
@@ -157,7 +157,7 @@ fi
157157
# Determining the value for DOCKER_FROM
158158
###
159159
if [ -z "$DOCKER_FROM" ]; then
160-
DOCKER_FROM="python:3.9-alpine"
160+
DOCKER_FROM="alpine:3.13"
161161
fi
162162

163163
###
@@ -271,7 +271,7 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do
271271

272272
if ! printf '%s\n' "${IMAGES_LAYERS_OLD[@]}" | grep -q -P "^${PYTHON_LAST_LAYER}\$"; then
273273
SHOULD_BUILD="true"
274-
BUILD_REASON="${BUILD_REASON} python"
274+
BUILD_REASON="${BUILD_REASON} alpine"
275275
fi
276276
if [ "${NETBOX_GIT_REF}" != "${NETBOX_GIT_REF_OLD}" ]; then
277277
SHOULD_BUILD="true"

docker-compose.test.yml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,9 @@ services:
1414
- ./configuration:/etc/netbox/config:z,ro
1515
- ./reports:/etc/netbox/reports:z,ro
1616
- ./scripts:/etc/netbox/scripts:z,ro
17-
- netbox-nginx-config:/etc/netbox-nginx:z
18-
- netbox-static-files:/opt/netbox/netbox/static:z
1917
- netbox-media-files:/opt/netbox/netbox/media:z
20-
nginx:
21-
command: nginx -c /etc/netbox-nginx/nginx.conf
22-
image: nginx:1.19-alpine
23-
depends_on:
24-
- netbox
2518
ports:
2619
- 8080
27-
volumes:
28-
- netbox-static-files:/opt/netbox/netbox/static:ro
29-
- netbox-nginx-config:/etc/netbox-nginx/:ro
3020
postgres:
3121
image: postgres:12-alpine
3222
env_file: env/postgres.env
@@ -45,9 +35,5 @@ services:
4535
- redis-server --requirepass $$REDIS_PASSWORD ## $$ because of docker-compose
4636
env_file: env/redis-cache.env
4737
volumes:
48-
netbox-static-files:
49-
driver: local
50-
netbox-nginx-config:
51-
driver: local
5238
netbox-media-files:
5339
driver: local

docker-compose.yml

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,19 @@ services:
1515
- ./configuration:/etc/netbox/config:z,ro
1616
- ./reports:/etc/netbox/reports:z,ro
1717
- ./scripts:/etc/netbox/scripts:z,ro
18-
- netbox-nginx-config:/etc/netbox-nginx:z
19-
- netbox-static-files:/opt/netbox/netbox/static:z
2018
- netbox-media-files:/opt/netbox/netbox/media:z
19+
ports:
20+
- "8080"
2121
netbox-worker:
2222
<<: *netbox
2323
depends_on:
2424
- redis
2525
entrypoint:
26-
- python3
26+
- /opt/netbox/venv/bin/python
2727
- /opt/netbox/netbox/manage.py
2828
command:
2929
- rqworker
30-
31-
# nginx
32-
nginx:
33-
command: nginx -c /etc/netbox-nginx/nginx.conf
34-
image: nginx:1.19-alpine
35-
depends_on:
36-
- netbox
37-
ports:
38-
- 8080
39-
volumes:
40-
- netbox-static-files:/opt/netbox/netbox/static:ro
41-
- netbox-nginx-config:/etc/netbox-nginx/:ro
30+
ports: []
4231

4332
# postgres
4433
postgres:
@@ -66,10 +55,6 @@ services:
6655
env_file: env/redis-cache.env
6756

6857
volumes:
69-
netbox-static-files:
70-
driver: local
71-
netbox-nginx-config:
72-
driver: local
7358
netbox-media-files:
7459
driver: local
7560
netbox-postgres-data:

docker/configuration.docker.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import importlib.util
1010
import sys
1111

12+
1213
def _filename(f):
1314
return f.name
1415

docker/docker-entrypoint.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ set -e
77
# Allows Netbox to be run as non-root users
88
umask 002
99

10+
# Load correct Python3 env
11+
source /opt/netbox/venv/bin/activate
12+
1013
# Try to connect to the DB
1114
DB_WAIT_TIMEOUT=${DB_WAIT_TIMEOUT-3}
1215
MAX_DB_WAIT_TIME=${MAX_DB_WAIT_TIME-30}
@@ -60,9 +63,6 @@ else
6063
echo "import runpy; runpy.run_path('../startup_scripts')" | ./manage.py shell --interface python
6164
fi
6265

63-
# Copy static files
64-
./manage.py collectstatic --no-input
65-
6666
echo "✅ Initialisation is done."
6767

6868
# Launch whatever is passed by docker

docker/gunicorn_config.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)