Skip to content

Commit 8703749

Browse files
authored
Merge pull request #571 from tobiasge/house
Added container for Netbox housekeeping command
2 parents d432a84 + a8b6883 commit 8703749

File tree

6 files changed

+26
-10
lines changed

6 files changed

+26
-10
lines changed

Dockerfile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,12 @@ RUN apk add --no-cache \
6262
libevent \
6363
libffi \
6464
libjpeg-turbo \
65-
openssl \
6665
libxslt \
66+
openssl \
6767
postgresql-libs \
68-
python3 \
6968
py3-pip \
69+
python3 \
70+
tini \
7071
unit \
7172
unit-python3
7273

@@ -82,6 +83,7 @@ COPY ${NETBOX_PATH} /opt/netbox
8283

8384
COPY docker/configuration.docker.py /opt/netbox/netbox/netbox/configuration.py
8485
COPY docker/docker-entrypoint.sh /opt/netbox/docker-entrypoint.sh
86+
COPY docker/housekeeping.sh /opt/netbox/housekeeping.sh
8587
COPY docker/launch-netbox.sh /opt/netbox/launch-netbox.sh
8688
COPY startup_scripts/ /opt/netbox/startup_scripts/
8789
COPY initializers/ /opt/netbox/initializers/
@@ -98,9 +100,9 @@ RUN mkdir -p static /opt/unit/state/ /opt/unit/tmp/ \
98100
--config-file /opt/netbox/mkdocs.yml --site-dir /opt/netbox/netbox/project-static/docs/ \
99101
&& SECRET_KEY="dummy" /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py collectstatic --no-input
100102

101-
ENTRYPOINT [ "/opt/netbox/docker-entrypoint.sh" ]
103+
ENTRYPOINT [ "/sbin/tini", "--" ]
102104

103-
CMD [ "/opt/netbox/launch-netbox.sh" ]
105+
CMD [ "/opt/netbox/docker-entrypoint.sh", "/opt/netbox/launch-netbox.sh" ]
104106

105107
LABEL ORIGINAL_TAG="" \
106108
NETBOX_GIT_BRANCH="" \

docker-compose.test.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ services:
1717
- ./reports:/etc/netbox/reports:z,ro
1818
- ./scripts:/etc/netbox/scripts:z,ro
1919
- netbox-media-files:/opt/netbox/netbox/media:z
20-
ports:
21-
- 8080
2220
postgres:
2321
image: postgres:13-alpine
2422
env_file: env/postgres.env

docker-compose.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,18 @@ services:
2020
<<: *netbox
2121
depends_on:
2222
- redis
23-
entrypoint:
23+
- postgres
24+
command:
2425
- /opt/netbox/venv/bin/python
2526
- /opt/netbox/netbox/manage.py
26-
command:
2727
- rqworker
28+
netbox-housekeeping:
29+
<<: *netbox
30+
depends_on:
31+
- redis
32+
- postgres
33+
command:
34+
- /opt/netbox/housekeeping.sh
2835

2936
# postgres
3037
postgres:

docker/housekeeping.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
SECONDS=${HOUSEKEEPING_INTERVAL:=86400}
3+
echo "Interval set to ${SECONDS} seconds"
4+
while true; do
5+
date
6+
/opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py housekeeping
7+
sleep "${SECONDS}s"
8+
done

env/netbox.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ EMAIL_USERNAME=netbox
1414
# EMAIL_USE_SSL and EMAIL_USE_TLS are mutually exclusive, i.e. they can't both be `true`!
1515
EMAIL_USE_SSL=false
1616
EMAIL_USE_TLS=false
17+
HOUSEKEEPING_INTERVAL=86400
1718
MAX_PAGE_SIZE=1000
1819
MEDIA_ROOT=/opt/netbox/netbox/media
1920
METRICS_ENABLED=false

test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ test_setup() {
5656

5757
test_netbox_unit_tests() {
5858
echo "⏱ Running NetBox Unit Tests"
59-
SKIP_STARTUP_SCRIPTS=true $doco run --rm netbox ./manage.py test
59+
$doco run --rm netbox /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py test
6060
}
6161

6262
test_initializers() {
6363
echo "🏭 Testing Initializers"
6464
export INITIALIZERS_DIR
65-
$doco run --rm netbox ./manage.py check
65+
$doco run --rm netbox /opt/netbox/docker-entrypoint.sh ./manage.py check
6666
}
6767

6868
test_cleanup() {

0 commit comments

Comments
 (0)