Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added container for Netbox housekeeping command #571

Merged
merged 3 commits into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ RUN apk add --no-cache \
libevent \
libffi \
libjpeg-turbo \
openssl \
libxslt \
openssl \
postgresql-libs \
python3 \
py3-pip \
python3 \
tini \
unit \
unit-python3

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

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

ENTRYPOINT [ "/opt/netbox/docker-entrypoint.sh" ]
ENTRYPOINT [ "/sbin/tini", "--" ]

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

LABEL ORIGINAL_TAG="" \
NETBOX_GIT_BRANCH="" \
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ services:
- ./reports:/etc/netbox/reports:z,ro
- ./scripts:/etc/netbox/scripts:z,ro
- netbox-media-files:/opt/netbox/netbox/media:z
ports:
- 8080
postgres:
image: postgres:13-alpine
env_file: env/postgres.env
Expand Down
11 changes: 9 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@ services:
<<: *netbox
depends_on:
- redis
entrypoint:
- postgres
command:
- /opt/netbox/venv/bin/python
- /opt/netbox/netbox/manage.py
command:
- rqworker
netbox-housekeeping:
<<: *netbox
depends_on:
- redis
- postgres
command:
- /opt/netbox/housekeeping.sh

# postgres
postgres:
Expand Down
8 changes: 8 additions & 0 deletions docker/housekeeping.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
SECONDS=${HOUSEKEEPING_INTERVAL:=86400}
echo "Interval set to ${SECONDS} seconds"
while true; do
date
/opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py housekeeping
sleep "${SECONDS}s"
done
1 change: 1 addition & 0 deletions env/netbox.env
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ EMAIL_USERNAME=netbox
# EMAIL_USE_SSL and EMAIL_USE_TLS are mutually exclusive, i.e. they can't both be `true`!
EMAIL_USE_SSL=false
EMAIL_USE_TLS=false
HOUSEKEEPING_INTERVAL=86400
MAX_PAGE_SIZE=1000
MEDIA_ROOT=/opt/netbox/netbox/media
METRICS_ENABLED=false
Expand Down
4 changes: 2 additions & 2 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ test_setup() {

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

test_initializers() {
echo "🏭 Testing Initializers"
export INITIALIZERS_DIR
$doco run --rm netbox ./manage.py check
$doco run --rm netbox /opt/netbox/docker-entrypoint.sh ./manage.py check
}

test_cleanup() {
Expand Down