Skip to content

Commit b45934c

Browse files
authored
Merge pull request #796 from netbox-community/develop
Version 2.0.0
2 parents 61a3afb + fceb6e0 commit b45934c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1045
-263
lines changed

.github/workflows/push.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ jobs:
1717
with:
1818
# Full git history is needed to get a proper list of changed files within `super-linter`
1919
fetch-depth: 0
20-
- uses: actions/setup-python@v3
20+
- uses: actions/setup-python@v4
21+
with:
22+
python-version: '3.9'
2123
- name: Lint Code Base
2224
uses: github/super-linter@v4
2325
env:

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
# docker.io
4343
-
4444
name: Login to docker.io
45-
uses: docker/login-action@v1
45+
uses: docker/login-action@v2
4646
with:
4747
registry: docker.io
4848
username: ${{ secrets.dockerhub_username }}
@@ -56,7 +56,7 @@ jobs:
5656
# quay.io
5757
-
5858
name: Login to Quay.io
59-
uses: docker/login-action@v1
59+
uses: docker/login-action@v2
6060
with:
6161
registry: quay.io
6262
username: ${{ secrets.quayio_username }}
@@ -72,7 +72,7 @@ jobs:
7272
# ghcr.io
7373
-
7474
name: Login to GitHub Container Registry
75-
uses: docker/login-action@v1
75+
uses: docker/login-action@v2
7676
with:
7777
registry: ghcr.io
7878
username: ${{ github.repository_owner }}

.hadolint.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
ignored:
22
- DL3006
3-
- DL3018
3+
- DL3008
4+
- DL3003

Dockerfile

Lines changed: 41 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,27 @@
11
ARG FROM
22
FROM ${FROM} as builder
33

4-
RUN apk add --no-cache \
5-
bash \
6-
build-base \
7-
cargo \
4+
RUN export DEBIAN_FRONTEND=noninteractive \
5+
&& apt-get update -qq \
6+
&& apt-get upgrade \
7+
--yes -qq --no-install-recommends \
8+
&& apt-get install \
9+
--yes -qq --no-install-recommends \
10+
build-essential \
811
ca-certificates \
9-
cmake \
10-
cyrus-sasl-dev \
11-
git \
12-
graphviz \
13-
jpeg-dev \
14-
libevent-dev \
15-
libffi-dev \
16-
libxslt-dev \
17-
make \
18-
musl-dev \
19-
openldap-dev \
20-
postgresql-dev \
21-
py3-pip \
12+
libldap-dev \
13+
libpq-dev \
14+
libsasl2-dev \
15+
libssl-dev \
2216
python3-dev \
23-
&& python3 -m venv /opt/netbox/venv \
24-
&& /opt/netbox/venv/bin/python3 -m pip install --upgrade \
17+
python3-pip \
18+
python3-venv \
19+
&& python3 -m venv /opt/netbox/venv \
20+
&& /opt/netbox/venv/bin/python3 -m pip install --upgrade \
2521
pip \
2622
setuptools \
2723
wheel
2824

29-
# Build libcrc32c for google-crc32c python module
30-
RUN git clone https://github.com/google/crc32c \
31-
&& cd crc32c \
32-
&& git submodule update --init --recursive \
33-
&& mkdir build \
34-
&& cd build \
35-
&& cmake \
36-
-DCMAKE_BUILD_TYPE=Release \
37-
-DCRC32C_BUILD_TESTS=no \
38-
-DCRC32C_BUILD_BENCHMARKS=no \
39-
-DBUILD_SHARED_LIBS=yes \
40-
.. \
41-
&& make all install
42-
4325
ARG NETBOX_PATH
4426
COPY ${NETBOX_PATH}/requirements.txt requirements-container.txt /
4527
RUN /opt/netbox/venv/bin/pip install \
@@ -53,35 +35,37 @@ RUN /opt/netbox/venv/bin/pip install \
5335
ARG FROM
5436
FROM ${FROM} as main
5537

56-
RUN apk add --no-cache \
57-
bash \
38+
RUN export DEBIAN_FRONTEND=noninteractive \
39+
&& apt-get update -qq \
40+
&& apt-get upgrade \
41+
--yes -qq --no-install-recommends \
42+
&& apt-get install \
43+
--yes -qq --no-install-recommends \
5844
ca-certificates \
5945
curl \
60-
graphviz \
61-
libevent \
62-
libffi \
63-
libjpeg-turbo \
64-
libxslt \
46+
libpq5 \
6547
openssl \
66-
postgresql-client \
67-
postgresql-libs \
68-
py3-pip \
6948
python3 \
49+
python3-distutils \
7050
tini \
71-
unit \
72-
unit-python3
73-
74-
WORKDIR /opt
51+
&& curl -sL https://nginx.org/keys/nginx_signing.key \
52+
> /etc/apt/trusted.gpg.d/nginx.asc && \
53+
echo "deb https://packages.nginx.org/unit/debian/ bullseye unit" \
54+
> /etc/apt/sources.list.d/unit.list \
55+
&& apt-get update -qq \
56+
&& apt-get install \
57+
--yes -qq --no-install-recommends \
58+
unit=1.27.0-1~bullseye \
59+
unit-python3.9=1.27.0-1~bullseye \
60+
&& rm -rf /var/lib/apt/lists/*
7561

76-
COPY --from=builder /usr/local/lib/libcrc32c.* /usr/local/lib/
77-
COPY --from=builder /usr/local/include/crc32c /usr/local/include
78-
COPY --from=builder /usr/local/lib/cmake/Crc32c /usr/local/lib/cmake/
7962
COPY --from=builder /opt/netbox/venv /opt/netbox/venv
8063

8164
ARG NETBOX_PATH
8265
COPY ${NETBOX_PATH} /opt/netbox
8366

8467
COPY docker/configuration.docker.py /opt/netbox/netbox/netbox/configuration.py
68+
COPY docker/ldap_config.docker.py /opt/netbox/netbox/netbox/ldap_config.py
8569
COPY docker/docker-entrypoint.sh /opt/netbox/docker-entrypoint.sh
8670
COPY docker/housekeeping.sh /opt/netbox/housekeeping.sh
8771
COPY docker/launch-netbox.sh /opt/netbox/launch-netbox.sh
@@ -101,26 +85,15 @@ RUN mkdir -p static /opt/unit/state/ /opt/unit/tmp/ \
10185
--config-file /opt/netbox/mkdocs.yml --site-dir /opt/netbox/netbox/project-static/docs/ \
10286
&& SECRET_KEY="dummy" /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py collectstatic --no-input
10387

104-
ENTRYPOINT [ "/sbin/tini", "--" ]
88+
ENV LANG=C.UTF-8
89+
ENTRYPOINT [ "/usr/bin/tini", "--" ]
10590

10691
CMD [ "/opt/netbox/docker-entrypoint.sh", "/opt/netbox/launch-netbox.sh" ]
10792

108-
LABEL ORIGINAL_TAG="" \
109-
NETBOX_GIT_BRANCH="" \
110-
NETBOX_GIT_REF="" \
111-
NETBOX_GIT_URL="" \
112-
# See http://label-schema.org/rc1/#build-time-labels
113-
# Also https://microbadger.com/labels
114-
org.label-schema.schema-version="1.0" \
115-
org.label-schema.build-date="" \
116-
org.label-schema.name="NetBox Docker" \
117-
org.label-schema.description="A container based distribution of NetBox, the free and open IPAM and DCIM solution." \
118-
org.label-schema.vendor="The netbox-docker contributors." \
119-
org.label-schema.url="https://github.com/netbox-community/netbox-docker" \
120-
org.label-schema.usage="https://github.com/netbox-community/netbox-docker/wiki" \
121-
org.label-schema.vcs-url="https://github.com/netbox-community/netbox-docker.git" \
122-
org.label-schema.vcs-ref="" \
123-
org.label-schema.version="snapshot" \
93+
LABEL netbox.original-tag="" \
94+
netbox.git-branch="" \
95+
netbox.git-ref="" \
96+
netbox.git-url="" \
12497
# See https://github.com/opencontainers/image-spec/blob/master/annotations.md#pre-defined-annotation-keys
12598
org.opencontainers.image.created="" \
12699
org.opencontainers.image.title="NetBox Docker" \
@@ -132,17 +105,4 @@ LABEL ORIGINAL_TAG="" \
132105
org.opencontainers.image.documentation="https://github.com/netbox-community/netbox-docker/wiki" \
133106
org.opencontainers.image.source="https://github.com/netbox-community/netbox-docker.git" \
134107
org.opencontainers.image.revision="" \
135-
org.opencontainers.image.version="snapshot"
136-
137-
#####
138-
## LDAP specific configuration
139-
#####
140-
141-
FROM main as ldap
142-
143-
RUN apk add --no-cache \
144-
libsasl \
145-
libldap \
146-
util-linux
147-
148-
COPY docker/ldap_config.docker.py /opt/netbox/netbox/netbox/ldap_config.py
108+
org.opencontainers.image.version=""

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.6.1
1+
2.0.0

build.sh

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ 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: 'alpine:3.14'"
52+
echo " Default: 'debian:11-slim'"
5353
echo " DOCKER_TARGET A specific target to build."
5454
echo " It's currently not possible to pass multiple targets."
55-
echo " Default: main ldap"
55+
echo " Default: main"
5656
echo " HTTP_PROXY The proxy to use for http requests."
5757
echo " Example: http://proxy.domain.tld:3128"
5858
echo " Default: undefined"
@@ -170,23 +170,23 @@ fi
170170
# Determining the value for DOCKER_FROM
171171
###
172172
if [ -z "$DOCKER_FROM" ]; then
173-
DOCKER_FROM="alpine:3.14"
173+
DOCKER_FROM="debian:11-slim"
174174
fi
175175

176176
###
177177
# Variables for labelling the docker image
178178
###
179179
BUILD_DATE="$(date -u '+%Y-%m-%dT%H:%M+00:00')"
180180

181-
if [ -d ".git" ]; then
181+
if [ -d ".git" ] && [ -z "${SKIP_GIT}" ]; then
182182
GIT_REF="$(git rev-parse HEAD)"
183183
fi
184184

185185
# Read the project version from the `VERSION` file and trim it, see https://stackoverflow.com/a/3232433/172132
186186
PROJECT_VERSION="${PROJECT_VERSION-$(sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' VERSION)}"
187187

188188
# Get the Git information from the netbox directory
189-
if [ -d "${NETBOX_PATH}/.git" ]; then
189+
if [ -d "${NETBOX_PATH}/.git" ] && [ -z "${SKIP_GIT}" ]; then
190190
NETBOX_GIT_REF=$(
191191
cd "${NETBOX_PATH}"
192192
git rev-parse HEAD
@@ -222,7 +222,7 @@ esac
222222
###
223223
# Determine targets to build
224224
###
225-
DEFAULT_DOCKER_TARGETS=("main" "ldap")
225+
DEFAULT_DOCKER_TARGETS=("main")
226226
DOCKER_TARGETS=("${DOCKER_TARGET:-"${DEFAULT_DOCKER_TARGETS[@]}"}")
227227
echo "🏭 Building the following targets:" "${DOCKER_TARGETS[@]}"
228228

@@ -277,9 +277,9 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do
277277
###
278278
# Checking if the build is necessary,
279279
# meaning build only if one of those values changed:
280-
# - Python base image digest (Label: PYTHON_BASE_DIGEST)
281-
# - netbox git ref (Label: NETBOX_GIT_REF)
282-
# - netbox-docker git ref (Label: org.label-schema.vcs-ref)
280+
# - base image digest
281+
# - netbox git ref (Label: netbox.git-ref)
282+
# - netbox-docker git ref (Label: org.opencontainers.image.revision)
283283
###
284284
# Load information from registry (only for docker.io)
285285
SHOULD_BUILD="false"
@@ -295,14 +295,14 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do
295295
# Need to use "library/..." for images the have no two part name
296296
DOCKER_FROM_SPLIT[0]="library/${DOCKER_FROM_SPLIT[0]}"
297297
fi
298-
PYTHON_LAST_LAYER=$(get_image_last_layer "${DOCKER_FROM_SPLIT[0]}" "${DOCKER_FROM_SPLIT[1]}")
298+
BASE_LAST_LAYER=$(get_image_last_layer "${DOCKER_FROM_SPLIT[0]}" "${DOCKER_FROM_SPLIT[1]}")
299299
mapfile -t IMAGES_LAYERS_OLD < <(get_image_layers "${DOCKER_ORG}"/"${DOCKER_REPO}" "${TAG}")
300-
NETBOX_GIT_REF_OLD=$(get_image_label NETBOX_GIT_REF "${DOCKER_ORG}"/"${DOCKER_REPO}" "${TAG}")
301-
GIT_REF_OLD=$(get_image_label org.label-schema.vcs-ref "${DOCKER_ORG}"/"${DOCKER_REPO}" "${TAG}")
300+
NETBOX_GIT_REF_OLD=$(get_image_label netbox.git-ref "${DOCKER_ORG}"/"${DOCKER_REPO}" "${TAG}")
301+
GIT_REF_OLD=$(get_image_label org.opencontainers.image.revision "${DOCKER_ORG}"/"${DOCKER_REPO}" "${TAG}")
302302

303-
if ! printf '%s\n' "${IMAGES_LAYERS_OLD[@]}" | grep -q -P "^${PYTHON_LAST_LAYER}\$"; then
303+
if ! printf '%s\n' "${IMAGES_LAYERS_OLD[@]}" | grep -q -P "^${BASE_LAST_LAYER}\$"; then
304304
SHOULD_BUILD="true"
305-
BUILD_REASON="${BUILD_REASON} alpine"
305+
BUILD_REASON="${BUILD_REASON} debian"
306306
fi
307307
if [ "${NETBOX_GIT_REF}" != "${NETBOX_GIT_REF_OLD}" ]; then
308308
SHOULD_BUILD="true"
@@ -335,30 +335,25 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do
335335

336336
# --label
337337
DOCKER_BUILD_ARGS+=(
338-
--label "ORIGINAL_TAG=${TARGET_DOCKER_TAG_PROJECT}"
339-
340-
--label "org.label-schema.build-date=${BUILD_DATE}"
338+
--label "netbox.original-tag=${TARGET_DOCKER_TAG_PROJECT}"
341339
--label "org.opencontainers.image.created=${BUILD_DATE}"
342-
343-
--label "org.label-schema.version=${PROJECT_VERSION}"
344340
--label "org.opencontainers.image.version=${PROJECT_VERSION}"
345341
)
346342
if [ -d ".git" ]; then
347343
DOCKER_BUILD_ARGS+=(
348-
--label "org.label-schema.vcs-ref=${GIT_REF}"
349344
--label "org.opencontainers.image.revision=${GIT_REF}"
350345
)
351346
fi
352347
if [ -d "${NETBOX_PATH}/.git" ]; then
353348
DOCKER_BUILD_ARGS+=(
354-
--label "NETBOX_GIT_BRANCH=${NETBOX_GIT_BRANCH}"
355-
--label "NETBOX_GIT_REF=${NETBOX_GIT_REF}"
356-
--label "NETBOX_GIT_URL=${NETBOX_GIT_URL}"
349+
--label "netbox.git-branch=${NETBOX_GIT_BRANCH}"
350+
--label "netbox.git-ref=${NETBOX_GIT_REF}"
351+
--label "netbox.git-url=${NETBOX_GIT_URL}"
357352
)
358353
fi
359354
if [ -n "${BUILD_REASON}" ]; then
360355
BUILD_REASON=$(sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' <<<"$BUILD_REASON")
361-
DOCKER_BUILD_ARGS+=(--label "BUILD_REASON=${BUILD_REASON}")
356+
DOCKER_BUILD_ARGS+=(--label "netbox.build-reason=${BUILD_REASON}")
362357
fi
363358

364359
# --build-arg
@@ -385,7 +380,7 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do
385380
$DRY docker build "${DOCKER_BUILD_ARGS[@]}" .
386381
echo "✅ Finished building the Docker images '${TARGET_DOCKER_TAG_PROJECT}'"
387382
echo "🔎 Inspecting labels on '${TARGET_DOCKER_TAG_PROJECT}'"
388-
$DRY docker inspect "${TARGET_DOCKER_TAG_PROJECT}" --format "{{json .Config.Labels}}"
383+
$DRY docker inspect "${TARGET_DOCKER_TAG_PROJECT}" --format "{{json .Config.Labels}}" | jq
389384
else
390385
echo "Build skipped because sources didn't change"
391386
echo "::set-output name=skipped::true"

configuration/configuration.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ def _read_secret(secret_name, default = None):
120120
CORS_ORIGIN_WHITELIST = list(filter(None, environ.get('CORS_ORIGIN_WHITELIST', 'https://localhost').split(' ')))
121121
CORS_ORIGIN_REGEX_WHITELIST = [re.compile(r) for r in list(filter(None, environ.get('CORS_ORIGIN_REGEX_WHITELIST', '').split(' ')))]
122122

123+
# Cross-Site-Request-Forgery-Attack settings. If Netbox is sitting behind a reverse proxy, you might need to set the CSRF_TRUSTED_ORIGINS flag.
124+
# Django 4.0 requires to specify the URL Scheme in this setting. An example environment variable could be specified like:
125+
# CSRF_TRUSTED_ORIGINS=https://demo.netbox.dev http://demo.netbox.dev
126+
CSRF_TRUSTED_ORIGINS = list(filter(None, environ.get('CSRF_TRUSTED_ORIGINS', '').split(' ')))
127+
123128
# Set to True to enable server debugging. WARNING: Debugging introduces a substantial performance penalty and may reveal
124129
# sensitive information about your installation. Only enable debugging while performing testing. Never enable debugging
125130
# on a production system.
@@ -165,6 +170,9 @@ def _read_secret(secret_name, default = None):
165170
# Setting this to True will display a "maintenance mode" banner at the top of every page.
166171
MAINTENANCE_MODE = environ.get('MAINTENANCE_MODE', 'False').lower() == 'true'
167172

173+
# Maps provider
174+
MAPS_URL = environ.get('MAPS_URL', None)
175+
168176
# An API consumer can request an arbitrary number of objects =by appending the "limit" parameter to the URL (e.g.
169177
# "?limit=1000"). This setting defines the maximum limit. Setting it to 0 or None will allow an API consumer to request
170178
# all objects by specifying "?limit=0".

docker-compose.test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ services:
2121
image: postgres:14-alpine
2222
env_file: env/postgres.env
2323
redis:
24-
image: redis:6-alpine
24+
image: redis:7-alpine
2525
command:
2626
- sh
2727
- -c # this is to evaluate the $REDIS_PASSWORD from the env
2828
- redis-server --appendonly yes --requirepass $$REDIS_PASSWORD ## $$ because of docker-compose
2929
env_file: env/redis.env
3030
redis-cache:
31-
image: redis:6-alpine
31+
image: redis:7-alpine
3232
command:
3333
- sh
3434
- -c # this is to evaluate the $REDIS_PASSWORD from the env

0 commit comments

Comments
 (0)