Working implementation of webhooks using new 'redis' container

This commit is contained in:
Brady Lamprecht 2018-08-10 17:55:09 -06:00
parent 6b5a4cf1db
commit b88974ef9f
6 changed files with 62 additions and 3 deletions

View File

@ -13,7 +13,8 @@ RUN apk add --no-cache \
libxslt-dev \
openldap-dev \
postgresql-dev \
wget
wget \
supervisor
RUN pip install \
# gunicorn is used for launching netbox
@ -21,7 +22,14 @@ RUN pip install \
# napalm is used for gathering information from network devices
napalm \
# ruamel is used in startup_scripts
ruamel.yaml
ruamel.yaml \
# if the Django package is not installed here to this pinned version
# django-rq will install the latest version (currently 2.1)
# then, when the requirements.txt of netbox is run, it will be
# uninstalled because it currently causes problems with netbox
Django==2.0.8 \
# django-rq is used for webhooks
django-rq
WORKDIR /opt
@ -40,6 +48,7 @@ COPY docker/docker-entrypoint.sh docker-entrypoint.sh
COPY startup_scripts/ /opt/netbox/startup_scripts/
COPY initializers/ /opt/netbox/initializers/
COPY configuration/configuration.py /etc/netbox/config/configuration.py
COPY configuration/supervisord.conf /etc/supervisord.conf
WORKDIR /opt/netbox/netbox
@ -47,7 +56,7 @@ ENTRYPOINT [ "/opt/netbox/docker-entrypoint.sh" ]
VOLUME ["/etc/netbox-nginx/"]
CMD ["gunicorn", "-c /etc/netbox/config/gunicorn_config.py", "netbox.wsgi"]
CMD ["supervisord", "-c /etc/supervisord.conf"]
LABEL SRC_URL="$URL"

View File

@ -139,6 +139,19 @@ PAGINATE_COUNT = int(os.environ.get('PAGINATE_COUNT', 50))
# prefer IPv4 instead.
PREFER_IPV4 = os.environ.get('PREFER_IPV4', 'False').lower() == 'true'
# The Webhook event backend is disabled by default. Set this to True to enable it. Note that this requires a Redis
# database be configured and accessible by NetBox (see `REDIS` below).
WEBHOOKS_ENABLED = os.environ.get('WEBHOOKS_ENABLED', 'True').lower() == 'true'
# Redis database settings (optional). A Redis database is required only if the webhooks backend is enabled.
REDIS = {
'HOST': os.environ.get('REDIS_HOST', 'localhost'),
'PORT': os.environ.get('REDIS_PORT', '6379'),
'PASSWORD': os.environ.get('REDIS_PASSWORD', ''),
'DATABASE': os.environ.get('REDIS_DATABASE', '0'),
'DEFAULT_TIMEOUT': os.environ.get('REDIS_TIMEOUT', '300'),
}
# The file path where custom reports will be stored. A trailing slash is not needed. Note that the default value of
# this setting is derived from the installed location.
REPORTS_ROOT = os.environ.get('REPORTS_ROOT', '/etc/netbox/reports')

View File

@ -0,0 +1,16 @@
[supervisord]
nodaemon=true
[supervisorctl]
[program:netbox]
command = gunicorn -c /etc/netbox/config/gunicorn_config.py netbox.wsgi
directory = /opt/netbox/netbox/
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
user = nobody
[program:netbox-rqworker]
command = python3 /opt/netbox/netbox/manage.py rqworker
directory = /opt/netbox/netbox/
user = nobody

View File

@ -8,6 +8,7 @@ services:
image: ninech/netbox:${VERSION-latest}
depends_on:
- postgres
- redis
env_file: netbox.env
volumes:
- ./startup_scripts:/opt/netbox/startup_scripts:ro
@ -32,6 +33,21 @@ services:
env_file: postgres.env
volumes:
- netbox-postgres-data:/var/lib/postgresql/data
redis:
image: redis:4-alpine
environment:
REDIS_PASS_FILE: /run/secrets/redis-pass
command: [
"sh", "-c",
'
docker-entrypoint.sh
--appendonly yes
--requirepass "$$(cat $$REDIS_PASS_FILE)"
'
]
volumes:
- ./redis-pass:/run/secrets/redis-pass
- netbox-redis-data:/data
volumes:
netbox-static-files:
@ -44,3 +60,5 @@ volumes:
driver: local
netbox-postgres-data:
driver: local
netbox-redis-data:
driver: local

View File

@ -13,6 +13,8 @@ NAPALM_USERNAME=
NAPALM_PASSWORD=
NAPALM_TIMEOUT=10
MAX_PAGE_SIZE=0
REDIS_HOST=redis
REDIS_PASSWORD=J5brHrAXFLQSif0K
SECRET_KEY=r8OwDznj!!dci#P9ghmRfdu1Ysxm0AiPeDCQhKE+N_rClfWNj
SUPERUSER_NAME=admin
SUPERUSER_EMAIL=admin@example.com

1
redis-pass Normal file
View File

@ -0,0 +1 @@
J5brHrAXFLQSif0K