Skip to content

Commit

Permalink
Start netbox in docker for acceptance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mraerino committed Jul 13, 2024
1 parent b12bff0 commit 19937b0
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 1 deletion.
14 changes: 13 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
@@ -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!"
47 changes: 47 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions tools/integration/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions tools/integration/plugins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PLUGINS = ["netbox_bgp"]

PLUGINS_CONFIG = {
'netbox_bgp': {},
}

0 comments on commit 19937b0

Please sign in to comment.