From d175a8dea405a7e861789420e59f4e35a05e5531 Mon Sep 17 00:00:00 2001 From: aptalca <541623+aptalca@users.noreply.github.com> Date: Mon, 26 Aug 2024 20:55:43 -0400 Subject: [PATCH 1/2] restructure init to allow for plugins as mods --- README.md | 1 + readme-vars.yml | 1 + .../s6-overlay/s6-rc.d/init-netbox-config/run | 18 --------------- .../dependencies.d/init-services | 0 .../s6-overlay/s6-rc.d/svc-netbox-prepare/run | 22 +++++++++++++++++++ .../s6-rc.d/svc-netbox-prepare/type | 1 + .../s6-overlay/s6-rc.d/svc-netbox-prepare/up | 1 + .../dependencies.d/svc-netbox-prepare | 0 .../user/contents.d/svc-netbox-prepare | 0 9 files changed, 26 insertions(+), 18 deletions(-) rename root/etc/s6-overlay/s6-rc.d/{svc-netbox => svc-netbox-prepare}/dependencies.d/init-services (100%) create mode 100755 root/etc/s6-overlay/s6-rc.d/svc-netbox-prepare/run create mode 100644 root/etc/s6-overlay/s6-rc.d/svc-netbox-prepare/type create mode 100644 root/etc/s6-overlay/s6-rc.d/svc-netbox-prepare/up create mode 100644 root/etc/s6-overlay/s6-rc.d/svc-netbox/dependencies.d/svc-netbox-prepare create mode 100644 root/etc/s6-overlay/s6-rc.d/user/contents.d/svc-netbox-prepare diff --git a/README.md b/README.md index d4a3bfe..8889084 100644 --- a/README.md +++ b/README.md @@ -333,6 +333,7 @@ Once registered you can define the dockerfile to use with `-f Dockerfile.aarch64 ## Versions +* **26.08.24:** - Restructure init to allow for plugins as mods. * **16.07.24:** - Add required packages for LDAP support. * **01.06.24:** - Rebase to Alpine 3.20. * **23.12.23:** - Rebase to Alpine 3.19. diff --git a/readme-vars.yml b/readme-vars.yml index 90e1764..e610ede 100644 --- a/readme-vars.yml +++ b/readme-vars.yml @@ -57,6 +57,7 @@ app_setup_block: | # changelog changelogs: + - { date: "26.08.24:", desc: "Restructure init to allow for plugins as mods."} - { date: "16.07.24:", desc: "Add required packages for LDAP support."} - { date: "01.06.24:", desc: "Rebase to Alpine 3.20."} - { date: "23.12.23:", desc: "Rebase to Alpine 3.19."} diff --git a/root/etc/s6-overlay/s6-rc.d/init-netbox-config/run b/root/etc/s6-overlay/s6-rc.d/init-netbox-config/run index 152530a..c4c098c 100755 --- a/root/etc/s6-overlay/s6-rc.d/init-netbox-config/run +++ b/root/etc/s6-overlay/s6-rc.d/init-netbox-config/run @@ -64,21 +64,3 @@ fi lsiown -R abc:abc \ /app/netbox/netbox/static \ /config - -s6-setuidgid abc python3 ./manage.py migrate - -if [[ -n "$SUPERUSER_EMAIL" ]] && [[ -n "$SUPERUSER_PASSWORD" ]]; then -cat << EOF | s6-setuidgid abc python3 /app/netbox/netbox/manage.py shell -from users.models import Token, User; - -username = 'admin'; -password = '$SUPERUSER_PASSWORD'; -email = '$SUPERUSER_EMAIL'; - -if not User.objects.filter(username='admin'): - User.objects.create_superuser(username, email, password); - print('Superuser created.'); -else: - print('Superuser creation skipped. Already exists.'); -EOF -fi diff --git a/root/etc/s6-overlay/s6-rc.d/svc-netbox/dependencies.d/init-services b/root/etc/s6-overlay/s6-rc.d/svc-netbox-prepare/dependencies.d/init-services similarity index 100% rename from root/etc/s6-overlay/s6-rc.d/svc-netbox/dependencies.d/init-services rename to root/etc/s6-overlay/s6-rc.d/svc-netbox-prepare/dependencies.d/init-services diff --git a/root/etc/s6-overlay/s6-rc.d/svc-netbox-prepare/run b/root/etc/s6-overlay/s6-rc.d/svc-netbox-prepare/run new file mode 100755 index 0000000..57d43d3 --- /dev/null +++ b/root/etc/s6-overlay/s6-rc.d/svc-netbox-prepare/run @@ -0,0 +1,22 @@ +#!/usr/bin/with-contenv bash +# shellcheck shell=bash + +cd /app/netbox/netbox || exit 1 + +s6-setuidgid abc python3 ./manage.py migrate + +if [[ -n "$SUPERUSER_EMAIL" ]] && [[ -n "$SUPERUSER_PASSWORD" ]]; then +cat << EOF | s6-setuidgid abc python3 /app/netbox/netbox/manage.py shell +from users.models import Token, User; + +username = 'admin'; +password = '$SUPERUSER_PASSWORD'; +email = '$SUPERUSER_EMAIL'; + +if not User.objects.filter(username='admin'): + User.objects.create_superuser(username, email, password); + print('Superuser created.'); +else: + print('Superuser creation skipped. Already exists.'); +EOF +fi diff --git a/root/etc/s6-overlay/s6-rc.d/svc-netbox-prepare/type b/root/etc/s6-overlay/s6-rc.d/svc-netbox-prepare/type new file mode 100644 index 0000000..bdd22a1 --- /dev/null +++ b/root/etc/s6-overlay/s6-rc.d/svc-netbox-prepare/type @@ -0,0 +1 @@ +oneshot diff --git a/root/etc/s6-overlay/s6-rc.d/svc-netbox-prepare/up b/root/etc/s6-overlay/s6-rc.d/svc-netbox-prepare/up new file mode 100644 index 0000000..c716644 --- /dev/null +++ b/root/etc/s6-overlay/s6-rc.d/svc-netbox-prepare/up @@ -0,0 +1 @@ +/etc/s6-overlay/s6-rc.d/svc-netbox-prepare/run diff --git a/root/etc/s6-overlay/s6-rc.d/svc-netbox/dependencies.d/svc-netbox-prepare b/root/etc/s6-overlay/s6-rc.d/svc-netbox/dependencies.d/svc-netbox-prepare new file mode 100644 index 0000000..e69de29 diff --git a/root/etc/s6-overlay/s6-rc.d/user/contents.d/svc-netbox-prepare b/root/etc/s6-overlay/s6-rc.d/user/contents.d/svc-netbox-prepare new file mode 100644 index 0000000..e69de29 From b45c949faaaa8e1b8afc751bf8821971b1cd9bcf Mon Sep 17 00:00:00 2001 From: aptalca <541623+aptalca@users.noreply.github.com> Date: Tue, 27 Aug 2024 08:24:02 -0400 Subject: [PATCH 2/2] move docs to service as well --- root/etc/s6-overlay/s6-rc.d/init-netbox-config/run | 9 --------- root/etc/s6-overlay/s6-rc.d/svc-netbox-prepare/run | 12 ++++++++++++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/root/etc/s6-overlay/s6-rc.d/init-netbox-config/run b/root/etc/s6-overlay/s6-rc.d/init-netbox-config/run index c4c098c..a201cfe 100755 --- a/root/etc/s6-overlay/s6-rc.d/init-netbox-config/run +++ b/root/etc/s6-overlay/s6-rc.d/init-netbox-config/run @@ -52,15 +52,6 @@ ln -sf /config/ldap_config.py /app/netbox/netbox/netbox/ldap_config.py mv /defaults/uwsgi.ini /app/netbox/netbox/uwsgi.ini > /dev/null 2>&1 -# build docs -if [[ ! -e "/app/netbox/netbox/project-static/docs/index.html" ]]; then - cd /app/netbox || exit 1 - echo "Building local documentation" - mkdocs build -q - cd /app/netbox/netbox || exit 1 -fi - # permissions lsiown -R abc:abc \ - /app/netbox/netbox/static \ /config diff --git a/root/etc/s6-overlay/s6-rc.d/svc-netbox-prepare/run b/root/etc/s6-overlay/s6-rc.d/svc-netbox-prepare/run index 57d43d3..e3fe66f 100755 --- a/root/etc/s6-overlay/s6-rc.d/svc-netbox-prepare/run +++ b/root/etc/s6-overlay/s6-rc.d/svc-netbox-prepare/run @@ -20,3 +20,15 @@ else: print('Superuser creation skipped. Already exists.'); EOF fi + +# build docs +if [[ ! -e "/app/netbox/netbox/project-static/docs/index.html" ]]; then + cd /app/netbox || exit 1 + echo "Building local documentation" + mkdocs build -q + cd /app/netbox/netbox || exit 1 +fi + +# permissions +lsiown -R abc:abc \ + /app/netbox/netbox/static