Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/lint-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
strategy:
matrix:
python: [ "3.10" ]
netbox: [ "", "v4.2.3" ]
netbox: [ "v4.5.0", "v4.4.10" ]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dist/

# Docker
docker/coverage
!docker/netbox/env
!docker/common/netbox/env
!docker/*/netbox/env
docker/oauth2/secrets/*
!docker/oauth2/secrets/.gitkeep
33 changes: 18 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,51 @@ else
DOCKER_COMPOSE := docker-compose
endif

NETBOX_VERSION ?=
ifneq ($(NETBOX_VERSION),)
DOCKER_PATH := docker/$(NETBOX_VERSION)
TEST_SELECTOR := "/opt/netbox/netbox/netbox_diode_plugin/tests/$(NETBOX_VERSION)/tests/"
else
DOCKER_PATH := docker
TEST_SELECTOR = netbox_diode_plugin
endif
# Default to v4.5.x if NETBOX_VERSION is not set
NETBOX_VERSION ?= v4.5.0
# Extract minor version (e.g., v4.5.0 -> v4.5.x)
NETBOX_MINOR_VERSION := $(shell echo $(NETBOX_VERSION) | sed -E 's/^v?([0-9]+\.[0-9]+).*/v\1.x/')
DOCKER_PATH := docker/$(NETBOX_MINOR_VERSION)
DOCKER_COMMON_PATH := docker/common
TEST_SELECTOR := "/opt/netbox/netbox/netbox_diode_plugin/tests/$(NETBOX_MINOR_VERSION)/tests/"

# Export variables so they're available to docker-compose
export NETBOX_VERSION
export NETBOX_MINOR_VERSION

.PHONY: docker-compose-netbox-plugin-up
docker-compose-netbox-plugin-up:
@$(DOCKER_COMPOSE) -f $(DOCKER_PATH)/docker-compose.yaml up -d --build
@$(DOCKER_COMPOSE) -f $(DOCKER_COMMON_PATH)/docker-compose.yaml up -d --build

.PHONY: docker-compose-netbox-plugin-down
docker-compose-netbox-plugin-down:
@$(DOCKER_COMPOSE) -f $(DOCKER_PATH)/docker-compose.yaml down
@$(DOCKER_COMPOSE) -f $(DOCKER_COMMON_PATH)/docker-compose.yaml down

.PHONY: docker-compose-netbox-plugin-test
docker-compose-netbox-plugin-test:
@$(DOCKER_COMPOSE) -f $(DOCKER_PATH)/docker-compose.yaml -f $(DOCKER_PATH)/docker-compose.test.yaml run -u root --rm netbox ./manage.py test $(TEST_FLAGS) --keepdb $(TEST_SELECTOR); \
@$(DOCKER_COMPOSE) -f $(DOCKER_COMMON_PATH)/docker-compose.yaml -f $(DOCKER_COMMON_PATH)/docker-compose.test.yaml run -u root --rm netbox ./manage.py test $(TEST_FLAGS) --keepdb $(TEST_SELECTOR); \
EXIT_CODE=$$?; \
$(MAKE) docker-compose-netbox-plugin-down; \
exit $$EXIT_CODE

.PHONY: docker-compose-netbox-plugin-test-lint
docker-compose-netbox-plugin-test-lint:
@$(DOCKER_COMPOSE) -f $(DOCKER_PATH)/docker-compose.yaml -f $(DOCKER_PATH)/docker-compose.test.yaml run -u root --rm netbox ruff check --output-format=github netbox_diode_plugin; \
@$(DOCKER_COMPOSE) -f $(DOCKER_COMMON_PATH)/docker-compose.yaml -f $(DOCKER_COMMON_PATH)/docker-compose.test.yaml run -u root --rm netbox ruff check --output-format=github netbox_diode_plugin; \
EXIT_CODE=$$?; \
$(MAKE) docker-compose-netbox-plugin-down; \
exit $$EXIT_CODE

.PHONY: docker-compose-netbox-plugin-test-cover
docker-compose-netbox-plugin-test-cover:
@$(DOCKER_COMPOSE) -f $(DOCKER_PATH)/docker-compose.yaml -f $(DOCKER_PATH)/docker-compose.test.yaml run --rm -u root -e COVERAGE_FILE=/opt/netbox/netbox/coverage/.coverage netbox sh -c "coverage run --source=netbox_diode_plugin --omit=*/migrations/* ./manage.py test --keepdb $(TEST_SELECTOR) && coverage xml -o /opt/netbox/netbox/coverage/report.xml && coverage report -m | tee /opt/netbox/netbox/coverage/report.txt"; \
@$(DOCKER_COMPOSE) -f $(DOCKER_COMMON_PATH)/docker-compose.yaml -f $(DOCKER_COMMON_PATH)/docker-compose.test.yaml run --rm -u root -e COVERAGE_FILE=/opt/netbox/netbox/coverage/.coverage netbox sh -c "coverage run --source=netbox_diode_plugin --omit=*/migrations/* ./manage.py test --keepdb $(TEST_SELECTOR) && coverage xml -o /opt/netbox/netbox/coverage/report.xml && coverage report -m | tee /opt/netbox/netbox/coverage/report.txt"; \
EXIT_CODE=$$?; \
$(MAKE) docker-compose-netbox-plugin-down; \
exit $$EXIT_CODE

.PHONY: docker-compose-generate-matching-docs
docker-compose-generate-matching-docs:
@$(DOCKER_COMPOSE) -f $(DOCKER_PATH)/docker-compose.yaml -f $(DOCKER_PATH)/docker-compose.test.yaml run --rm netbox python manage.py generate_matching_docs | awk '/Generating markdown documentation.../{p=1;next} p' > ./docs/matching-criteria-documentation.md
@$(DOCKER_COMPOSE) -f $(DOCKER_COMMON_PATH)/docker-compose.yaml -f $(DOCKER_COMMON_PATH)/docker-compose.test.yaml run --rm netbox python manage.py generate_matching_docs | awk '/Generating markdown documentation.../{p=1;next} p' > ./docs/matching-criteria-documentation.md

.PHONY: docker-compose-migrate
docker-compose-migrate:
@$(DOCKER_COMPOSE) -f $(DOCKER_PATH)/docker-compose.yaml -f $(DOCKER_PATH)/docker-compose.test.yaml run --rm netbox python manage.py migrate
@$(DOCKER_COMPOSE) -f $(DOCKER_COMMON_PATH)/docker-compose.yaml -f $(DOCKER_COMMON_PATH)/docker-compose.test.yaml run --rm netbox python manage.py migrate
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ at [https://netboxlabs.com/blog/introducing-diode-streamlining-data-ingestion-in

## Compatibility

| NetBox Version | Plugin Version |
|:--------------:|:--------------:|
| >= 3.7.2 | 0.1.0 |
| >= 4.1.0 | 0.4.0 |
| >= 4.2.3 | 1.0.0 |
| >= 4.2.3 | 1.1.0 |
| >= 4.2.3 | 1.2.0 |
| >= 4.4.0 | 1.4.0 |
| >= 4.4.0 | 1.4.1 |
| NetBox Version | Plugin Version |
|:---------------:|:--------------:|
| >= 3.7.2 | 0.1.0 |
| >= 4.1.0 | 0.4.0 |
| >= 4.2.3 | 1.0.0 |
| >= 4.2.3 | 1.1.0 |
| >= 4.2.3 | 1.2.0 |
| >= 4.4.0 | 1.4.0 |
| >= 4.4.0 | 1.4.1 |
| >= 4.4.10 | 1.7.0 |
| >= 4.5.0 | 1.7.0 |

## Installation

Expand Down
5 changes: 5 additions & 0 deletions docker/common/docker-compose.test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: diode-netbox-plugin-${NETBOX_MINOR_VERSION:-v4.5.x}
services:
netbox:
volumes:
- ../common/netbox/plugins_test.py:/etc/netbox/config/plugins.py:z,ro
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
name: diode-netbox-plugin-4.2.3
name: diode-netbox-plugin-${NETBOX_MINOR_VERSION:-v4.5.x}
services:
netbox: &netbox
image: netboxcommunity/netbox:v4.2.3-3.1.1-diode-netbox-plugin
image: netboxcommunity/netbox:${NETBOX_VERSION:-v4.5.0-3.4.2}-diode-netbox-plugin
build:
context: .
dockerfile: Dockerfile-diode-netbox-plugin
context: ..
dockerfile: ${NETBOX_MINOR_VERSION:-v4.5.x}/Dockerfile
pull: true
args:
NETBOX_VERSION: ${NETBOX_VERSION:-v4.5.0-3.4.2}
depends_on:
- netbox-postgres
- netbox-redis
- netbox-redis-cache
env_file: netbox/env/netbox.env
user: 'unit:root'
env_file: ../common/netbox/env/netbox.env
user: "unit:root"
healthcheck:
start_period: 60s
start_period: 180s
timeout: 3s
interval: 15s
test: "curl -f http://localhost:8080/netbox/api/ || exit 1"
Expand All @@ -24,15 +26,15 @@ services:
- ../oauth2/secrets:/run/secrets:z,ro
- ./netbox/launch-netbox.sh:/opt/netbox/launch-netbox.sh:z,ro
- ./netbox/plugins_dev.py:/etc/netbox/config/plugins.py:z,ro
- ./coverage:/opt/netbox/netbox/coverage:z,rw
- ../coverage:/opt/netbox/netbox/coverage:z,rw
- netbox-media-files:/opt/netbox/netbox/media:rw
- netbox-reports-files:/opt/netbox/netbox/reports:rw
- netbox-scripts-files:/opt/netbox/netbox/scripts:rw
extra_hosts:
- "host.docker.internal:host-gateway"
ports:
- "8000:8080"

netbox-worker:
<<: *netbox
depends_on:
Expand All @@ -48,11 +50,11 @@ services:
timeout: 3s
interval: 15s
ports: []

# postgres
netbox-postgres:
image: docker.io/postgres:16-alpine
env_file: netbox/env/postgres.env
env_file: ../common/netbox/env/postgres.env
volumes:
- netbox-postgres-data:/var/lib/postgresql/data

Expand All @@ -63,7 +65,7 @@ services:
- sh
- -c # this is to evaluate the $REDIS_PASSWORD from the env
- redis-server --appendonly yes --requirepass $$REDIS_PASSWORD ## $$ because of docker-compose
env_file: netbox/env/redis.env
env_file: ../common/netbox/env/redis.env
volumes:
- netbox-redis-data:/data

Expand All @@ -73,7 +75,7 @@ services:
- sh
- -c # this is to evaluate the $REDIS_PASSWORD from the env
- redis-server --requirepass $$REDIS_PASSWORD ## $$ because of docker-compose
env_file: netbox/env/redis-cache.env
env_file: ../common/netbox/env/redis-cache.env
volumes:
- netbox-redis-cache-data:/data

Expand All @@ -89,4 +91,4 @@ volumes:
netbox-reports-files:
driver: local
netbox-scripts-files:
driver: local
driver: local
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ def _read_secret(secret_name: str, default: str | None = None) -> str | None:
# is passed to it as a parameter. The value returned from `map_fn` is then the return value of this function.
# The `map_fn` is not invoked, if the value (that was read from the environment or the default value if not found) is None.
def _environ_get_and_map(
variable_name: str,
default: str | None = None,
map_fn: Callable[[str], Any | None] = None,
variable_name: str,
default: str | None = None,
map_fn: Callable[[str], Any | None] = None,
) -> Any | None:
env_value = environ.get(variable_name, default)

Expand Down Expand Up @@ -133,6 +133,12 @@ def _environ_get_and_map(
# https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-SECRET_KEY
SECRET_KEY = _read_secret("secret_key", environ.get("SECRET_KEY", ""))


API_TOKEN_PEPPERS = {}
if api_token_pepper := _read_secret('api_token_pepper_1', environ.get('API_TOKEN_PEPPER_1', '')):
API_TOKEN_PEPPERS.update({1: api_token_pepper})


#########################
# #
# Optional settings #
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ SUPERUSER_PASSWORD=admin
WEBHOOKS_ENABLED=true
RELOAD_NETBOX_ON_DIODE_PLUGIN_CHANGE=true
BASE_PATH=netbox/
DEBUG=False
DEBUG=False
API_TOKEN_PEPPER_1=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 0 additions & 5 deletions docker/docker-compose.test.yaml

This file was deleted.

92 changes: 0 additions & 92 deletions docker/docker-compose.yaml

This file was deleted.

12 changes: 0 additions & 12 deletions docker/v4.2.3/Dockerfile-diode-netbox-plugin

This file was deleted.

5 changes: 0 additions & 5 deletions docker/v4.2.3/docker-compose.test.yaml

This file was deleted.

Loading