From d2733917732fd8c73239f50407046604f03c838d Mon Sep 17 00:00:00 2001 From: Tobias Genannt Date: Tue, 10 Nov 2020 15:23:07 +0100 Subject: [PATCH] Gunicorn is replaced with nginx-unit We now serve Netbox with an nginx-unit instance instead of Gunicorn. This allows us to get rid of the extra Nginx container because Unit is also serving the static files. The static files are now collected at container buildtime instead of every startup. --- .github/ISSUE_TEMPLATE/bug_report.md | 10 ------ .github/workflows/push.yml | 2 +- Dockerfile | 48 +++++++++++-------------- README.md | 2 +- build.sh | 14 ++++---- docker-compose.test.yml | 14 -------- docker-compose.yml | 23 +++--------- docker/configuration.docker.py | 1 + docker/docker-entrypoint.sh | 6 ++-- docker/gunicorn_config.py | 8 ----- docker/launch-netbox.sh | 53 ++++++++++++++++++++++++++++ docker/nginx-unit.json | 40 +++++++++++++++++++++ docker/nginx.conf | 44 ----------------------- requirements-container.txt | 4 +++ test.sh | 2 +- 15 files changed, 135 insertions(+), 136 deletions(-) delete mode 100644 docker/gunicorn_config.py create mode 100755 docker/launch-netbox.sh create mode 100644 docker/nginx-unit.json delete mode 100644 docker/nginx.conf create mode 100644 requirements-container.txt diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 82f22b17f..7bf063298 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -65,13 +65,3 @@ If your log is very long, create a Gist instead (and post the link to it): https ```text LOG LOG LOG ``` - -The output of `docker-compose logs nginx`: - - -```text -LOG LOG LOG -``` diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index e1780b7ba..09bc661a8 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -19,7 +19,7 @@ jobs: - ./build.sh develop docker_from: - '' # use the default of the build script - # - python:3.10-rc-alpine # disable until dependencies work + - alpine:edge fail-fast: false runs-on: ubuntu-latest name: Builds new Netbox Docker Images diff --git a/Dockerfile b/Dockerfile index 8db4cac6f..272f88246 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,27 +12,15 @@ RUN apk add --no-cache \ libffi-dev \ libxslt-dev \ openldap-dev \ - postgresql-dev - -WORKDIR /install - -RUN pip install --prefix="/install" --no-warn-script-location \ -# gunicorn is used for launching netbox - gunicorn \ - greenlet \ - eventlet \ -# napalm is used for gathering information from network devices - napalm \ -# ruamel is used in startup_scripts - 'ruamel.yaml>=0.15,<0.16' \ -# django_auth_ldap is required for ldap - django_auth_ldap \ -# django-storages was introduced in 2.7 and is optional - django-storages + postgresql-dev \ + py3-pip \ + python3-dev \ + && python3 -m venv /opt/netbox/venv \ + && /opt/netbox/venv/bin/python3 -m pip install --upgrade pip setuptools ARG NETBOX_PATH -COPY ${NETBOX_PATH}/requirements.txt / -RUN pip install --prefix="/install" --no-warn-script-location -r /requirements.txt +COPY ${NETBOX_PATH}/requirements.txt requirements-container.txt / +RUN /opt/netbox/venv/bin/pip install -r /requirements.txt -r /requirements-container.txt ### # Main stage @@ -44,6 +32,7 @@ FROM ${FROM} as main RUN apk add --no-cache \ bash \ ca-certificates \ + curl \ graphviz \ libevent \ libffi \ @@ -51,35 +40,38 @@ RUN apk add --no-cache \ libressl \ libxslt \ postgresql-libs \ - ttf-ubuntu-font-family + python3 \ + py3-pip \ + ttf-ubuntu-font-family \ + unit \ + unit-python3 WORKDIR /opt -COPY --from=builder /install /usr/local +COPY --from=builder /opt/netbox/venv /opt/netbox/venv ARG NETBOX_PATH COPY ${NETBOX_PATH} /opt/netbox COPY docker/configuration.docker.py /opt/netbox/netbox/netbox/configuration.py -COPY docker/gunicorn_config.py /etc/netbox/ -COPY docker/nginx.conf /etc/netbox-nginx/nginx.conf COPY docker/docker-entrypoint.sh /opt/netbox/docker-entrypoint.sh +COPY docker/launch-netbox.sh /opt/netbox/launch-netbox.sh COPY startup_scripts/ /opt/netbox/startup_scripts/ COPY initializers/ /opt/netbox/initializers/ COPY configuration/ /etc/netbox/config/ +COPY docker/nginx-unit.json /etc/unit/ WORKDIR /opt/netbox/netbox -# Must set permissions for '/opt/netbox/netbox/static' directory -# to g+w so that `./manage.py collectstatic` can be executed during -# container startup. # Must set permissions for '/opt/netbox/netbox/media' directory # to g+w so that pictures can be uploaded to netbox. -RUN mkdir static && chmod -R g+w static media +RUN mkdir -p static /opt/unit/state/ /opt/unit/tmp/ \ + && chmod -R g+w media /opt/unit/ \ + && SECRET_KEY="dummy" /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py collectstatic --no-input ENTRYPOINT [ "/opt/netbox/docker-entrypoint.sh" ] -CMD ["gunicorn", "-c /etc/netbox/gunicorn_config.py", "netbox.wsgi"] +CMD [ "/opt/netbox/launch-netbox.sh" ] LABEL ORIGINAL_TAG="" \ NETBOX_GIT_BRANCH="" \ diff --git a/README.md b/README.md index 11edf52b9..0125c29aa 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ cd netbox-docker tee docker-compose.override.yml <=0.15,<0.16 +django-auth-ldap==2.2.0 +django-storages==1.10.1 \ No newline at end of file diff --git a/test.sh b/test.sh index fa6fa38c2..2249316af 100755 --- a/test.sh +++ b/test.sh @@ -35,7 +35,7 @@ if [ -z "${IMAGE}" ]; then fi # The docker compose command to use -doco="docker-compose -f docker-compose.test.yml" +doco="docker-compose --file docker-compose.test.yml --project-name netbox_docker_test_${1}" INITIALIZERS_DIR=".initializers"