diff --git a/docker-compose.yml b/docker-compose.yml index 958561f..844a4d2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,6 +14,7 @@ services: test: "curl -f http://localhost:8080/login/ || exit 1" volumes: - ./configuration:/etc/netbox/config:z,ro + - init-files:/opt/init:ro - netbox-media-files:/opt/netbox/netbox/media:rw - netbox-reports-files:/opt/netbox/netbox/reports:rw - netbox-scripts-files:/opt/netbox/netbox/scripts:rw @@ -72,6 +73,8 @@ services: - netbox-redis-cache-data:/data volumes: + init-files: + driver: local netbox-media-files: driver: local netbox-postgres-data: diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index fa5930d..33da74f 100755 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -1,12 +1,19 @@ #!/bin/bash # Runs on every start of the NetBox Docker container -# Stop when an error occures +# Stop when an error occurs set -e # Allows NetBox to be run as non-root users umask 002 +if [ -d /opt/init/pre ]; then + find /opt/init/pre -type f -name \*.sh | sort -u | while read -r FILE; do + echo "⚙️ Running pre-init script '${FILE}'..." + /bin/bash -e "${FILE}" "$@" + done +fi + # Load correct Python3 env # shellcheck disable=SC1091 source /opt/netbox/venv/bin/activate @@ -91,8 +98,15 @@ except Token.DoesNotExist: pass END +if [ -d /opt/init/post ]; then + find /opt/init/post -type f -name \*.sh | sort -u | while read -r FILE; do + echo "⚙️ Running post-init script '${FILE}'..." + /bin/bash -e "${FILE}" "$@" + done +fi + echo "✅ Initialisation is done." # Launch whatever is passed by docker -# (i.e. the RUN instruction in the Dockerfile) +# (i.e. the CMD instruction in the Dockerfile) exec "$@"