zaki work log

作業ログやら生活ログやらなんやら

[NetBox] 最新のfeatureブランチでDockerビルドしてコンテナとしてデプロイする

NetBoxの機能でまだリリースはされていないけどfeatureブランチには実装済みの新しい機能を試してみたい場合、feature版のコンテナイメージは用意されてないためOS上に素で構築する必要があるが、それよりはfeature版コンテナイメージを手元でビルドした方が楽なのでは?と思って試してみた。

なお、試してみるとコンテナ版のビルドスクリプトはfeature版には対応していないため、実装の差異がある場合は手直しが必要*1

以下は時期バージョンの2.11のリリースノート。

github.com

環境

[zaki@cloud-dev netbox-docker (release)]$ docker-compose --version
docker-compose version 1.28.6, build 5db8d86f
[zaki@cloud-dev netbox-docker (release)]$ docker --version
Docker version 20.10.5, build 55c4c88

準備

Docker Compose版のリポジトリcloneする。

github.com

$ git clone https://github.com/netbox-community/netbox-docker.git
$ cd netbox-docker/

NetBoxコンテナイメージをビルドするには、付属のbuild.shを使うと簡単にビルドできる。

イメージのbuild

ビルドスクリプトの使い方は--helpを指定して確認できる。

$ ./build.sh --help
▶️ ./build.sh --help
Usage: ./build.sh <branch> [--push|--push-only]

ブランチ名を引数に実行すれば、そのブランチのソースを使ってコンテナイメージがビルドされる。
デフォルトはビルドのみで、(試してないけど)--pushも付与すれば、おそらくDocker Hubへpushされる(未確認。デフォルトではnetboxcommunityリポジトリになるので個人環境では変更が必要かも)。

というわけで、NetBoxのfeatureブランチをビルドするには以下の通り。

$ ./build.sh feature

実行すると .netboxディレクトリにNetBox本体のリポジトリcloneされビルド処理が始まる。
ビルド中はステージごとの処理時間がログの右側に表示されるのでtimeは付けなくていいかも。手元の環境(i7のESXiの上の4vCPUs RAM8GBのVM)では約10分必要だった。
あとは、実行ユーザー権限でDockerが使用可能であること。

ビルドログはこんな感じ。

▶️ ./build.sh feature
🌐 Checking out 'feature' of NetBox from the url 'https://github.com/netbox-community/netbox.git' into '.netbox'
✅ Checked out NetBox
🏭 Building the following targets: main ldap
🏗 Building the target 'main'
🐳 Building the Docker image 'docker.io/netboxcommunity/netbox:feature'.
    Build reason set to: interactive
[+] Building 641.3s (22/22) FINISHED                                                                                                                          
 => [internal] load build definition from Dockerfile                                                                                                     0.0s
 => => transferring dockerfile: 4.03kB                                                                                                                   0.0s
 => [internal] load .dockerignore                                                                                                                        0.0s
 => => transferring context: 159B                                                                                                                        0.0s
 => [internal] load metadata for docker.io/library/alpine:3.13                                                                                           2.6s
 => [internal] load build context                                                                                                                        0.3s
 => => transferring context: 18.63MB                                                                                                                     0.3s
 => [builder 1/4] FROM docker.io/library/alpine:3.13@sha256:ec14c7992a97fc11425907e908340c6c3d6ff602f5f13d899e6b7027c9b4133a                             0.8s
 => => resolve docker.io/library/alpine:3.13@sha256:ec14c7992a97fc11425907e908340c6c3d6ff602f5f13d899e6b7027c9b4133a                                     0.0s
 => => sha256:49f356fa4513676c5e22e3a8404aad6c7262cc7aaed15341458265320786c58c 1.47kB / 1.47kB                                                           0.0s
 => => sha256:ca3cd42a7c9525f6ce3d64c1a70982613a8235f0cc057ec9244052921853ef15 2.81MB / 2.81MB                                                           0.7s
 => => sha256:ec14c7992a97fc11425907e908340c6c3d6ff602f5f13d899e6b7027c9b4133a 1.64kB / 1.64kB                                                           0.0s 
 => => sha256:e103c1b4bf019dc290bcc7aca538dc2bf7a9d0fc836e186f5fa34945c5168310 528B / 528B                                                               0.0s 
 => => extracting sha256:ca3cd42a7c9525f6ce3d64c1a70982613a8235f0cc057ec9244052921853ef15                                                                0.1s 
 => [builder 2/4] RUN apk add --no-cache       bash       build-base       cargo       ca-certificates       cyrus-sasl-dev       graphviz       jpeg-  46.7s
 => [main  2/14] RUN apk add --no-cache       bash       ca-certificates       curl       graphviz       libevent       libffi       libjpeg-turbo      11.0s
 => [main  3/14] WORKDIR /opt                                                                                                                            0.6s
 => [builder 3/4] COPY .netbox/requirements.txt requirements-container.txt /                                                                             0.0s
 => [builder 4/4] RUN /opt/netbox/venv/bin/pip install       -r /requirements.txt       -r /requirements-container.txt                                 569.6s
 => [main  4/14] COPY --from=builder /opt/netbox/venv /opt/netbox/venv                                                                                   4.4s
 => [main  5/14] COPY .netbox /opt/netbox                                                                                                                0.4s
 => [main  6/14] COPY docker/configuration.docker.py /opt/netbox/netbox/netbox/configuration.py                                                          0.0s
 => [main  7/14] COPY docker/docker-entrypoint.sh /opt/netbox/docker-entrypoint.sh                                                                       0.0s
 => [main  8/14] COPY docker/launch-netbox.sh /opt/netbox/launch-netbox.sh                                                                               0.0s
 => [main  9/14] COPY startup_scripts/ /opt/netbox/startup_scripts/                                                                                      0.0s
 => [main 10/14] COPY initializers/ /opt/netbox/initializers/                                                                                            0.0s
 => [main 11/14] COPY configuration/ /etc/netbox/config/                                                                                                 0.0s
 => [main 12/14] COPY docker/nginx-unit.json /etc/unit/                                                                                                  0.0s
 => [main 13/14] WORKDIR /opt/netbox/netbox                                                                                                              0.1s
 => [main 14/14] RUN mkdir -p static /opt/unit/state/ /opt/unit/tmp/       && chmod -R g+w media /opt/unit/       && SECRET_KEY="dummy" /opt/netbox/ven  2.8s
 => exporting to image                                                                                                                                  11.5s
 => => exporting layers                                                                                                                                 11.5s
 => => writing image sha256:71d6db96e4e172dfae2d1b0c68aad0283212936e17f0bc22aef00004f7f2e756                                                             0.0s
 => => naming to docker.io/netboxcommunity/netbox:feature                                                                                                0.0s
✅ Finished building the Docker images 'docker.io/netboxcommunity/netbox:feature'
🔎 Inspecting labels on 'docker.io/netboxcommunity/netbox:feature'
{"BUILD_REASON":"interactive","NETBOX_GIT_BRANCH":"HEAD","NETBOX_GIT_REF":"4883bc3dd445a8353ae1f204d0a1fe3dcc83cb73","NETBOX_GIT_URL":"https://github.com/netbox-community/netbox.git","ORIGINAL_TAG":"docker.io/netboxcommunity/netbox:feature","org.label-schema.build-date":"2021-04-03T02:05+00:00","org.label-schema.description":"A container based distribution of NetBox, the free and open IPAM and DCIM solution.","org.label-schema.name":"NetBox Docker","org.label-schema.schema-version":"1.0","org.label-schema.url":"https://github.com/netbox-community/netbox-docker","org.label-schema.usage":"https://github.com/netbox-community/netbox-docker/wiki","org.label-schema.vcs-ref":"cb5ffa0354016d7187395c591d17b2f0f5f0699a","org.label-schema.vcs-url":"https://github.com/netbox-community/netbox-docker.git","org.label-schema.vendor":"The netbox-docker contributors.","org.label-schema.version":"1.1.0","org.opencontainers.image.authors":"The netbox-docker contributors.","org.opencontainers.image.created":"2021-04-03T02:05+00:00","org.opencontainers.image.description":"A container based distribution of NetBox, the free and open IPAM and DCIM solution.","org.opencontainers.image.documentation":"https://github.com/netbox-community/netbox-docker/wiki","org.opencontainers.image.licenses":"Apache-2.0","org.opencontainers.image.revision":"cb5ffa0354016d7187395c591d17b2f0f5f0699a","org.opencontainers.image.source":"https://github.com/netbox-community/netbox-docker.git","org.opencontainers.image.title":"NetBox Docker","org.opencontainers.image.url":"https://github.com/netbox-community/netbox-docker","org.opencontainers.image.vendor":"The netbox-docker contributors.","org.opencontainers.image.version":"1.1.0"}
🏗 Building the target 'ldap'
🐳 Building the Docker image 'docker.io/netboxcommunity/netbox:feature-ldap'.
    Build reason set to: interactive
[+] Building 5.1s (24/24) FINISHED                                                                                                                            
 => [internal] load build definition from Dockerfile                                                                                                     0.1s
 => => transferring dockerfile: 38B                                                                                                                      0.0s
 => [internal] load .dockerignore                                                                                                                        0.0s
 => => transferring context: 34B                                                                                                                         0.0s
 => [internal] load metadata for docker.io/library/alpine:3.13                                                                                           1.7s
 => [internal] load build context                                                                                                                        0.1s
 => => transferring context: 176.93kB                                                                                                                    0.1s
 => [builder 1/4] FROM docker.io/library/alpine:3.13@sha256:ec14c7992a97fc11425907e908340c6c3d6ff602f5f13d899e6b7027c9b4133a                             0.0s
 => CACHED [main  2/14] RUN apk add --no-cache       bash       ca-certificates       curl       graphviz       libevent       libffi       libjpeg-tur  0.0s
 => CACHED [main  3/14] WORKDIR /opt                                                                                                                     0.0s
 => CACHED [builder 2/4] RUN apk add --no-cache       bash       build-base       cargo       ca-certificates       cyrus-sasl-dev       graphviz        0.0s
 => CACHED [builder 3/4] COPY .netbox/requirements.txt requirements-container.txt /                                                                      0.0s
 => CACHED [builder 4/4] RUN /opt/netbox/venv/bin/pip install       -r /requirements.txt       -r /requirements-container.txt                            0.0s
 => CACHED [main  4/14] COPY --from=builder /opt/netbox/venv /opt/netbox/venv                                                                            0.0s
 => CACHED [main  5/14] COPY .netbox /opt/netbox                                                                                                         0.0s
 => CACHED [main  6/14] COPY docker/configuration.docker.py /opt/netbox/netbox/netbox/configuration.py                                                   0.0s
 => CACHED [main  7/14] COPY docker/docker-entrypoint.sh /opt/netbox/docker-entrypoint.sh                                                                0.0s
 => CACHED [main  8/14] COPY docker/launch-netbox.sh /opt/netbox/launch-netbox.sh                                                                        0.0s
 => CACHED [main  9/14] COPY startup_scripts/ /opt/netbox/startup_scripts/                                                                               0.0s
 => CACHED [main 10/14] COPY initializers/ /opt/netbox/initializers/                                                                                     0.0s
 => CACHED [main 11/14] COPY configuration/ /etc/netbox/config/                                                                                          0.0s
 => CACHED [main 12/14] COPY docker/nginx-unit.json /etc/unit/                                                                                           0.0s
 => CACHED [main 13/14] WORKDIR /opt/netbox/netbox                                                                                                       0.0s
 => CACHED [main 14/14] RUN mkdir -p static /opt/unit/state/ /opt/unit/tmp/       && chmod -R g+w media /opt/unit/       && SECRET_KEY="dummy" /opt/net  0.0s
 => [ldap 1/2] RUN apk add --no-cache       libsasl       libldap       util-linux                                                                       1.6s
 => [ldap 2/2] COPY docker/ldap_config.docker.py /opt/netbox/netbox/netbox/ldap_config.py                                                                0.0s
 => exporting to image                                                                                                                                   1.7s
 => => exporting layers                                                                                                                                  1.7s
 => => writing image sha256:b6c008b1e41d1f122c051ebba982ed7de5c3f47f14ab9ddef154f1b693cc3e7e                                                             0.0s
 => => naming to docker.io/netboxcommunity/netbox:feature-ldap                                                                                           0.0s
✅ Finished building the Docker images 'docker.io/netboxcommunity/netbox:feature-ldap'
🔎 Inspecting labels on 'docker.io/netboxcommunity/netbox:feature-ldap'
{"BUILD_REASON":"interactive","NETBOX_GIT_BRANCH":"HEAD","NETBOX_GIT_REF":"4883bc3dd445a8353ae1f204d0a1fe3dcc83cb73","NETBOX_GIT_URL":"https://github.com/netbox-community/netbox.git","ORIGINAL_TAG":"docker.io/netboxcommunity/netbox:feature-ldap","org.label-schema.build-date":"2021-04-03T02:05+00:00","org.label-schema.description":"A container based distribution of NetBox, the free and open IPAM and DCIM solution.","org.label-schema.name":"NetBox Docker","org.label-schema.schema-version":"1.0","org.label-schema.url":"https://github.com/netbox-community/netbox-docker","org.label-schema.usage":"https://github.com/netbox-community/netbox-docker/wiki","org.label-schema.vcs-ref":"cb5ffa0354016d7187395c591d17b2f0f5f0699a","org.label-schema.vcs-url":"https://github.com/netbox-community/netbox-docker.git","org.label-schema.vendor":"The netbox-docker contributors.","org.label-schema.version":"1.1.0","org.opencontainers.image.authors":"The netbox-docker contributors.","org.opencontainers.image.created":"2021-04-03T02:05+00:00","org.opencontainers.image.description":"A container based distribution of NetBox, the free and open IPAM and DCIM solution.","org.opencontainers.image.documentation":"https://github.com/netbox-community/netbox-docker/wiki","org.opencontainers.image.licenses":"Apache-2.0","org.opencontainers.image.revision":"cb5ffa0354016d7187395c591d17b2f0f5f0699a","org.opencontainers.image.source":"https://github.com/netbox-community/netbox-docker.git","org.opencontainers.image.title":"NetBox Docker","org.opencontainers.image.url":"https://github.com/netbox-community/netbox-docker","org.opencontainers.image.vendor":"The netbox-docker contributors.","org.opencontainers.image.version":"1.1.0"}

この2イメージがビルドされた。

[zaki@cloud-dev netbox-docker (release)]$ docker images
REPOSITORY               TAG            IMAGE ID       CREATED         SIZE
netboxcommunity/netbox   feature-ldap   1e775790d163   2 minutes ago   404MB
netboxcommunity/netbox   feature        ef2733470d41   2 minutes ago   399MB

デプロイ

デプロイは通常通り、必要に応じて docker-compose.override.yml を作成する。
このとき、指定コンテナイメージのtagにfeatureを指定し、今ビルドしたイメージを使うように指定する。
(※これはdocker-compose.override.ymlで指定しなくても、環境変数VERSIONfeatureを指定しても良いようにdocker-compose.ymlが作成されている。)

version: '3.4'
services:
  netbox:
    ports:
      - 9900:8080
    image: netboxcommunity/netbox:feature

デプロイ開始。

[zaki@cloud-dev netbox-docker (release)]$ docker-compose up -d
Creating network "netbox-docker_default" with the default driver
Creating volume "netbox-docker_netbox-media-files" with local driver
Creating volume "netbox-docker_netbox-postgres-data" with local driver
Creating volume "netbox-docker_netbox-redis-data" with local driver
Pulling postgres (postgres:12-alpine)...
12-alpine: Pulling from library/postgres
ca3cd42a7c95: Already exists
a0d003399a5b: Pull complete
0a08de1ad3ba: Pull complete
36fedf58ee26: Pull complete
733693f76814: Pull complete
14068c3cc9f8: Pull complete
0e1916273d9a: Pull complete
163f3880181d: Pull complete
Digest: sha256:56ccea5941111d7cfd22894c6ab7eb7dd9c0fff1ffa489194e87d4f5372160ec
Status: Downloaded newer image for postgres:12-alpine
Pulling redis (redis:6-alpine)...
6-alpine: Pulling from library/redis
ca3cd42a7c95: Already exists
8ea57f684bcd: Pull complete
c99865ad8d20: Pull complete
e2b874e1c121: Pull complete
4419ed1bbecc: Pull complete
662c8cef3675: Pull complete
Digest: sha256:142f857eb675a6a817dff1ae4d2138fc0228db596db2849ad1c38023a9dea7a4
Status: Downloaded newer image for redis:6-alpine
Creating netbox-docker_redis-cache_1 ... done
Creating netbox-docker_redis_1       ... done
Creating netbox-docker_postgres_1    ... done
Creating netbox-docker_netbox-worker_1 ... done
Creating netbox-docker_netbox_1        ... done

実行状態。

[zaki@cloud-dev netbox-docker (release)]$ docker-compose ps
            Name                           Command               State     Ports  
----------------------------------------------------------------------------------
netbox-docker_netbox-worker_1   /opt/netbox/venv/bin/pytho ...   Up               
netbox-docker_netbox_1          /opt/netbox/docker-entrypo ...   Exit 1           
netbox-docker_postgres_1        docker-entrypoint.sh postgres    Up       5432/tcp
netbox-docker_redis-cache_1     docker-entrypoint.sh sh -c ...   Up       6379/tcp
netbox-docker_redis_1           docker-entrypoint.sh sh -c ...   Up       6379/tcp

おや、、、

実行エラー

ログを確認してみると以下の通り。

[zaki@cloud-dev netbox-docker (release)]$ docker-compose logs 

:
:

netbox_1         | 🧬 loaded config '/etc/netbox/config/configuration.py'
netbox_1         | 🧬 loaded config '/etc/netbox/config/extra.py'
netbox_1         | 💡 Superuser Username: admin, E-Mail: admin@example.com
netbox_1         | 🧬 loaded config '/etc/netbox/config/configuration.py'
netbox_1         | 🧬 loaded config '/etc/netbox/config/extra.py'
netbox_1         | ▶️  Running the startup script /opt/netbox/startup_scripts/000_users.py
netbox_1         | ▶️  Running the startup script /opt/netbox/startup_scripts/010_groups.py
netbox_1         | ▶️  Running the startup script /opt/netbox/startup_scripts/020_custom_fields.py
netbox_1         | ▶️  Running the startup script /opt/netbox/startup_scripts/020_tags.py
netbox_1         | ▶️  Running the startup script /opt/netbox/startup_scripts/030_regions.py
netbox_1         | ▶️  Running the startup script /opt/netbox/startup_scripts/040_sites.py
netbox_1         | ▶️  Running the startup script /opt/netbox/startup_scripts/050_manufacturers.py
netbox_1         | ▶️  Running the startup script /opt/netbox/startup_scripts/060_device_types.py
netbox_1         | ▶️  Running the startup script /opt/netbox/startup_scripts/070_rack_roles.py
netbox_1         | ▶️  Running the startup script /opt/netbox/startup_scripts/075_rack_groups.py
netbox_1         | Traceback (most recent call last):
netbox_1         |   File "./manage.py", line 10, in <module>
netbox_1         |     execute_from_command_line(sys.argv)
netbox_1         |   File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
netbox_1         |     utility.execute()
netbox_1         |   File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
netbox_1         |     self.fetch_command(subcommand).run_from_argv(self.argv)
netbox_1         |   File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
netbox_1         |     self.execute(*args, **cmd_options)
netbox_1         |   File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
netbox_1         |     output = self.handle(*args, **options)
netbox_1         |   File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/management/commands/shell.py", line 93, in handle
netbox_1         |     exec(sys.stdin.read(), globals())
netbox_1         |   File "<string>", line 1, in <module>
netbox_1         |   File "/usr/lib/python3.8/runpy.py", line 282, in run_path
netbox_1         |     return _run_code(code, mod_globals, init_globals,
netbox_1         |   File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
netbox_1         |     exec(code, run_globals)
netbox_1         |   File "../startup_scripts/__main__.py", line 27, in <module>
netbox_1         |     runpy.run_path(f.path)
netbox_1         |   File "/usr/lib/python3.8/runpy.py", line 265, in run_path
netbox_1         |     return _run_module_code(code, init_globals, run_name,
netbox_1         |   File "/usr/lib/python3.8/runpy.py", line 97, in _run_module_code
netbox_1         |     _run_code(code, mod_globals, init_globals,
netbox_1         |   File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
netbox_1         |     exec(code, run_globals)
netbox_1         |   File "/opt/netbox/startup_scripts/075_rack_groups.py", line 3, in <module>
netbox_1         |     from dcim.models import RackGroup, Site
netbox_1         | ImportError: cannot import name 'RackGroup' from 'dcim.models' (/opt/netbox/netbox/dcim/models/__init__.py)
netbox-docker_netbox_1 exited with code 1

エラーになっている。

先に答えを書くと、NetBox本体はfeatureブランチを今回対象としているけど、イメージビルドに使っているNetBox Dockerはfeatureブランチは存在しないのでデフォルトのreleaseブランチを使っているので、実装の差異があるとそこでエラーが発生する。

NetBox Dockerのコードを本体のfeatureブランチの内容に合わせる

以下は2021.04.03 11時(JST)時点での修正ポイント。

最初はfeatureブランチの内容が実装されてないから実装されるまで待とうかなーと思ったけど、あきらめきれずにソースを追ってみる。
(最近こんなのばっかだな)

最初に見るエラーの内容は以下。

Running the startup script /opt/netbox/startup_scripts/075_rack_groups.py
:
:
ImportError: cannot import name 'RackGroup' from 'dcim.models' (/opt/netbox/netbox/dcim/models/__init__.py)

エラー発生個所のコードを確認すると、featureブランチはLocationになってる

masterやdevelopだとRackGroupになっている

そして、実行中スクリプト075_rack_groups.pyのあるnetbox-dockerのリリースブランチでは、RackGroupを参照してる、と。

ということで、startup_scripts以下で RackGroup を参照しているところを Location に変更すれば一歩進める(少なくともimportはうまくいく)と予測が立つ。
ただ、パッケージ名変更だけで動くのかというとそれはあやしいのでもうblameをチェックすると、以下のissueで「名前の変更」が行われたことが確認できる。

github.com

変更点は以下。

github.com

grepと脳内インタプリタでざっと見た感じでは、netbox-docker側のスクリプトもリネームでとりあえず大丈夫そうなので、startup_scripts内で参照しているRackGroupLocationに変更してやる。
以下の通り。

diff --git a/startup_scripts/075_rack_groups.py b/startup_scripts/075_rack_groups.py
index 3974b56..d2bf249 100644
--- a/startup_scripts/075_rack_groups.py
+++ b/startup_scripts/075_rack_groups.py
@@ -1,6 +1,6 @@
 import sys
 
-from dcim.models import RackGroup, Site
+from dcim.models import Location, Site
 from startup_script_utils import load_yaml
 
 rack_groups = load_yaml("/opt/netbox/initializers/rack_groups.yml")
@@ -17,7 +17,7 @@ for params in rack_groups:
         query = {field: params.pop(assoc)}
         params[assoc] = model.objects.get(**query)
 
-    rack_group, created = RackGroup.objects.get_or_create(**params)
+    rack_group, created = Location.objects.get_or_create(**params)
 
     if created:
         print("🎨 Created rack group", rack_group.name)
diff --git a/startup_scripts/080_racks.py b/startup_scripts/080_racks.py
index 087b3f9..e27b268 100644
--- a/startup_scripts/080_racks.py
+++ b/startup_scripts/080_racks.py
@@ -1,6 +1,6 @@
 import sys
 
-from dcim.models import Rack, RackGroup, RackRole, Site
+from dcim.models import Rack, Location, RackRole, Site
 from startup_script_utils import load_yaml, pop_custom_fields, set_custom_fields_values
 from tenancy.models import Tenant
 
@@ -14,7 +14,7 @@ required_assocs = {"site": (Site, "name")}
 optional_assocs = {
     "role": (RackRole, "name"),
     "tenant": (Tenant, "name"),
-    "group": (RackGroup, "name"),
+    "group": (Location, "name"),
 }
 
 for params in racks:
diff --git a/startup_scripts/330_power_panels.py b/startup_scripts/330_power_panels.py
index bfde18f..db11a4d 100644
--- a/startup_scripts/330_power_panels.py
+++ b/startup_scripts/330_power_panels.py
@@ -1,6 +1,6 @@
 import sys
 
-from dcim.models import PowerPanel, RackGroup, Site
+from dcim.models import PowerPanel, Location, Site
 from startup_script_utils import load_yaml, pop_custom_fields, set_custom_fields_values
 
 power_panels = load_yaml("/opt/netbox/initializers/power_panels.yml")
@@ -10,7 +10,7 @@ if power_panels is None:
 
 required_assocs = {"site": (Site, "name")}
 
-optional_assocs = {"rack_group": (RackGroup, "name")}
+optional_assocs = {"rack_group": (Location, "name")}
 
 for params in power_panels:
     custom_field_data = pop_custom_fields(params)

再デプロイ

変更が済んだら一度down --volumeでボリューム含めて全て削除(これはトラブル防止のために環境をクリアにするという趣旨)し、再度デプロイする。

[zaki@cloud-dev netbox-docker (release)]$ docker-compose down --volume 
Stopping netbox-docker_netbox-worker_1 ... done
Stopping netbox-docker_postgres_1      ... done
Stopping netbox-docker_redis-cache_1   ... done
Stopping netbox-docker_redis_1         ... done
Removing netbox-docker_netbox_1        ... done
Removing netbox-docker_netbox-worker_1 ... done
Removing netbox-docker_postgres_1      ... done
Removing netbox-docker_redis-cache_1   ... done
Removing netbox-docker_redis_1         ... done
Removing network netbox-docker_default
Removing volume netbox-docker_netbox-media-files
Removing volume netbox-docker_netbox-postgres-data
Removing volume netbox-docker_netbox-redis-data
[zaki@cloud-dev netbox-docker (release)]$ docker-compose up -d
Creating network "netbox-docker_default" with the default driver
Creating volume "netbox-docker_netbox-media-files" with local driver
Creating volume "netbox-docker_netbox-postgres-data" with local driver
Creating volume "netbox-docker_netbox-redis-data" with local driver
Creating netbox-docker_redis-cache_1   ... done
Creating netbox-docker_postgres_1      ... done
Creating netbox-docker_redis_1       ... done
Creating netbox-docker_netbox-worker_1 ... done
Creating netbox-docker_netbox_1        ... done
[zaki@cloud-dev netbox-docker (release)]$ docker-compose ps
            Name                           Command               State                       Ports                     
-----------------------------------------------------------------------------------------------------------------------
netbox-docker_netbox-worker_1   /opt/netbox/venv/bin/pytho ...   Up                                                    
netbox-docker_netbox_1          /opt/netbox/docker-entrypo ...   Up      0.0.0.0:9900->8080/tcp,0.0.0.0:49164->8080/tcp
netbox-docker_postgres_1        docker-entrypoint.sh postgres    Up      5432/tcp                                      
netbox-docker_redis-cache_1     docker-entrypoint.sh sh -c ...   Up      6379/tcp                                      
netbox-docker_redis_1           docker-entrypoint.sh sh -c ...   Up      6379/tcp           

ログを見た感じでも正常に起動した模様。

webアクセス

この通り、featureブランチで開発されている2.11の表示になっている。(リリース版は現在2.10)

f:id:zaki-hmkc:20210403114740p:plain

2.11のリリースノートはこちら

github.com

#5451 - Add support for multiple-selection custom fields

たとえばカスタムフィールドの「multi-select」とかがサポートされるようになっている。 画面右上Adminメニューの「Custom fields」で、以下のように項目が追加されているのを確認できる。

v2.11 f:id:zaki-hmkc:20210403115250p:plain

以下はv2.10の場合 f:id:zaki-hmkc:20210403115401p:plain

まとめ

featureブランチの内容でも手元でイメージビルドすればDocker Composeを使ってNetBoxをデプロイできることを確認できた。
ただし実装の内容(次期バージョンと現バージョンの実装の差異)によっては修正が必要。
なので、「構築は楽だけどこれでまぁ大丈夫かな?」くらいだろうか。。

今回は露見してないけど「全くの新しいパッケージimportが必要」なパターンであればデプロイのタイミングではエラーにならずに画面から参照しようとするとランタイムエラーになる、というパターンもあるかもしれないので注意。

用途としては「壊して作り直す」が容易なコンテナのメリットを活かせるので、新機能を確認するための環境の用意の手段の一つとして、やりかたをチェックしておくと良いと思う。

*1:あくまで2021.04.03時点の2.11バージョンの場合