From 19937b06b37dcfd7429fb339fd02200f032fc36c Mon Sep 17 00:00:00 2001 From: Marcus Weiner Date: Sun, 14 Jul 2024 00:41:13 +0200 Subject: [PATCH] Start netbox in docker for acceptance tests --- GNUmakefile | 14 ++++++++++- docker-compose.yaml | 47 ++++++++++++++++++++++++++++++++++++ tools/integration/Dockerfile | 8 ++++++ tools/integration/plugins.py | 5 ++++ 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 docker-compose.yaml create mode 100644 tools/integration/Dockerfile create mode 100644 tools/integration/plugins.py diff --git a/GNUmakefile b/GNUmakefile index 7771cd6..77691b9 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,6 +1,18 @@ +DOCKER_COMPOSE=docker compose + +export NETBOX_SERVER_URL=http://localhost:8001 +export NETBOX_API_TOKEN=0123456789abcdef0123456789abcdef01234567 + default: testacc # Run acceptance tests .PHONY: testacc -testacc: +testacc: docker-up TF_ACC=1 go test ./... -v $(TESTARGS) -timeout 120m + +# Run dockerized Netbox for acceptance testing +.PHONY: docker-up +docker-up: + @echo "⌛ Startup Netbox $(NETBOX_VERSION) and wait for service to become ready" + $(DOCKER_COMPOSE) up -d netbox --wait + @echo "🚀 Netbox is up and running!" diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..5ca39ce --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,47 @@ +--- +version: "3.7" +services: + postgres: + image: postgres:14-alpine + environment: + - POSTGRES_USER=netbox + - POSTGRES_PASSWORD=netbox + - POSTGRES_DB=netbox + redis: + image: redis:6-alpine + netbox: + build: + context: tools/integration + args: + NETBOX_VERSION: ${NETBOX_VERSION:-3.7.8} + NETBOX_BGP_VERSION: ${NETBOX_BGP_VERSION:-0.12.1} + depends_on: + - postgres + - redis + ports: + - 8001:8080 + environment: + - CORS_ORIGIN_ALLOW_ALL=True + - DB_NAME=netbox + - DB_USER=netbox + - DB_PASSWORD=netbox + - DB_HOST=postgres + - REDIS_HOST=redis + - REDIS_DATABASE=0 + - REDIS_SSL=false + - REDIS_CACHE_HOST=redis + - REDIS_CACHE_DATABASE=1 + - REDIS_CACHE_SSL=false + - SECRET_KEY=0123456789abcdefghij0123456789abcdefghij0123456789 + - SKIP_STARTUP_SCRIPTS=false + - SKIP_SUPERUSER=false + - SUPERUSER_NAME=admin + - SUPERUSER_EMAIL=admin@example.com + - SUPERUSER_PASSWORD=admin + - SUPERUSER_API_TOKEN=${NETBOX_API_TOKEN:-0123456789abcdef0123456789abcdef01234567} + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:8080/api/status/"] + interval: 10s + timeout: 10s + retries: 10 + start_period: 5s diff --git a/tools/integration/Dockerfile b/tools/integration/Dockerfile new file mode 100644 index 0000000..46c7364 --- /dev/null +++ b/tools/integration/Dockerfile @@ -0,0 +1,8 @@ +ARG NETBOX_VERSION +FROM netboxcommunity/netbox:v${NETBOX_VERSION} + +ARG NETBOX_BGP_VERSION +RUN /opt/netbox/venv/bin/pip install --no-warn-script-location netbox-bgp==${NETBOX_BGP_VERSION} + +COPY plugins.py /etc/netbox/config/plugins.py +RUN SECRET_KEY="dummydummydummydummydummydummydummydummydummydummy" /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py collectstatic --no-input diff --git a/tools/integration/plugins.py b/tools/integration/plugins.py new file mode 100644 index 0000000..ded5398 --- /dev/null +++ b/tools/integration/plugins.py @@ -0,0 +1,5 @@ +PLUGINS = ["netbox_bgp"] + +PLUGINS_CONFIG = { + 'netbox_bgp': {}, +}