netbox-community / netbox-docker

🐳 Docker Image of NetBox
https://github.com/netbox-community/netbox-docker/wiki
Apache License 2.0
1.81k stars 829 forks source link

Ability to set FIELD_CHOICES in docker-compose.override.yml #1111

Closed Fredouye closed 9 months ago

Fredouye commented 11 months ago

Desired Behavior

Hi

Netbox 3.6.4 installed using the Quickstart.

Using the docker-compose.override.yml is a useful way to set LDAP authentication and various settings :

services:
  netbox:
    environment:
      [...]
      LOGIN_REQUIRED: "True"

But some settings need to be added into configuration/extra.py, which is fetched from the Git repo.

FIELD_CHOICES = {
    'ipam.IPAddress.status': (
        ('active', 'Active', 'cyan'),
        ('reserved', 'Reserved', 'orange'),
        ('deprecated', 'Deprecated', 'gray'),
        ('dhcp', 'DHCP', 'yellow'),
    )
}

Contrast to Current Behavior

As stated in the extra.py headers :

This file contains extra configuration options that can't be configured directly through environment variables.

Required Changes

No response

Discussion: Benefits and Drawbacks

If possible, read various settings as FIELD_CHOICES from docker-compose.override.yml, to avoid changes being lost when fetching from Git.

Thanks in advance !

kkthxbye-code commented 11 months ago

https://github.com/netbox-community/netbox-docker/wiki/Configuration#custom-configuration-files

You can create you own configuration files if you need to configure something that can't be configured via the environment variables. See the configuration/extra.py file as an example. This works for regular configuration as well as for ldap configuration files, with the little (obvious?) difference that ldap configuration files are placed in configuration/ldap/.

The files are read in the order in which they are received from the system, which usually is alphabetical order. Later files take precedence over previous files. All custom files take precedence over the default configuration files configuration.py and ldap_config.py.

Just call your custom configuration file something else like mysuperspecialconfigurationfile.py.

If possible, read various settings as FIELD_CHOICES from docker-compose.override.yml, to avoid changes being lost when fetching from Git.

How would this work? FIELD_CHOICES is a python data structure with the rough format of dict[string, tuple[tuple]]. How would you cleanly specify this in yaml and convert to the needed python data structure?

Fredouye commented 11 months ago

Sorry, I've missed this part of the documentation.

I've added this to docker-compose.override.yml :

services:
  netbox:
    volumes:
      - ./my-extra-config.py:/etc/netbox/config/extra.py:z,ro

I guess this issue can be closed.