From b88974ef9f1cc044fa7d5588729cd01737dbe5f6 Mon Sep 17 00:00:00 2001 From: Brady Lamprecht Date: Fri, 10 Aug 2018 17:55:09 -0600 Subject: [PATCH] Working implementation of webhooks using new 'redis' container --- Dockerfile | 15 ++++++++++++--- configuration/configuration.py | 13 +++++++++++++ configuration/supervisord.conf | 16 ++++++++++++++++ docker-compose.yml | 18 ++++++++++++++++++ netbox.env | 2 ++ redis-pass | 1 + 6 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 configuration/supervisord.conf create mode 100644 redis-pass diff --git a/Dockerfile b/Dockerfile index aece64e..b6f0fe7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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" diff --git a/configuration/configuration.py b/configuration/configuration.py index f65356e..4154092 100644 --- a/configuration/configuration.py +++ b/configuration/configuration.py @@ -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') diff --git a/configuration/supervisord.conf b/configuration/supervisord.conf new file mode 100644 index 0000000..423e7b3 --- /dev/null +++ b/configuration/supervisord.conf @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index d227b86..b6d825b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/netbox.env b/netbox.env index a9958ea..9efe6c7 100644 --- a/netbox.env +++ b/netbox.env @@ -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 diff --git a/redis-pass b/redis-pass new file mode 100644 index 0000000..d9fb997 --- /dev/null +++ b/redis-pass @@ -0,0 +1 @@ +J5brHrAXFLQSif0K