From 82538b087fdb50cbc6d70e033d9713ef865ab7cb Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Tue, 17 Nov 2026 16:44:58 -0500 Subject: [PATCH] feat(compose): run netbox as a host-network stack, AppJail included The AppJail CIT ran the image alone, without postgres or redis, and failed at 'database unreachable'. The compose now runs all three on host networking with 127.0.0.1 hosts and its paths and secrets in example.env, like kaneo, so the generated Director bundle carries postgres and redis and dbuild tests AppJail through it instead of the lone image. --- compose.yaml | 92 +++++++++++++++++++++++++++++++----------- example.env | 15 +++++++ postgres-template.conf | 14 +++++++ 3 files changed, 98 insertions(+), 23 deletions(-) create mode 100644 example.env create mode 100644 postgres-template.conf diff --git a/compose.yaml b/compose.yaml index b48ffd2..944b23d 100644 --- a/compose.yaml +++ b/compose.yaml @@ -10,15 +10,54 @@ x-daemonless: user: "bsd" upstream_binary: true notes: "Needs PostgreSQL 15+ and Redis. Migrations run automatically at start." + + networking: + netbox: default + "*": private + hostnames: + postgres: DB_HOST + redis: REDIS_HOST + + appjail: + director: + options: + - alias: + - ip4_inherit: + depends_on: + - name: postgres + image: ghcr.io/daemonless/postgres:18 + template: postgres-template.conf + env: + POSTGRES_DB: "!ENV '${DB_NAME}'" + POSTGRES_USER: "!ENV '${DB_USER}'" + POSTGRES_PASSWORD: "!ENV '${DB_PASSWORD}'" + volumes: + db_data: /var/lib/postgresql/data + - name: redis + image: ghcr.io/daemonless/redis:latest docs: env: ALLOWED_HOSTS: "Space-separated hostnames (default *)" CSRF_TRUSTED_ORIGINS: "Space-separated origins, e.g. https://netbox.example.com" - DB_HOST: "PostgreSQL host" - DB_NAME: "Database name" - DB_USER: "Database user" + NETBOX_CONFIG_PATH: "Path to store NetBox secrets, media and scripts" + DB_DATA_LOCATION: "Path to store PostgreSQL data files" + DB_HOST: + desc: "Where NetBox finds PostgreSQL (set automatically for the built-in database; 127.0.0.1 on host networking)" + level: advanced + optional: true + DB_NAME: + desc: "PostgreSQL database name" + level: advanced + optional: true + DB_USER: + desc: "PostgreSQL user" + level: advanced + optional: true DB_PASSWORD: "Database password (or DB_PASSWORD_FILE)" - REDIS_HOST: "Redis host" + REDIS_HOST: + desc: "Where NetBox finds Redis (set automatically for the built-in Redis; 127.0.0.1 on host networking)" + level: advanced + optional: true NETBOX_SECRET_KEY: "Optional; auto-generated into /config/secret_key" NETBOX_API_TOKEN_PEPPER: "Optional; auto-generated into /config/api_token_pepper" SUPERUSER_NAME: "Optional first-run admin user" @@ -34,36 +73,43 @@ services: netbox: image: ghcr.io/daemonless/netbox:latest container_name: netbox + network_mode: host + depends_on: [postgres, redis] + restart: unless-stopped environment: - PUID=1000 - PGID=1000 - - TZ=UTC - - DB_HOST=postgres - - DB_PASSWORD=changeme - - REDIS_HOST=redis - - SUPERUSER_NAME=admin - - SUPERUSER_PASSWORD=changeme - - GRANIAN_WORKERS=4 + - TZ=${TZ:-UTC} + - DB_HOST=${DB_HOST:-127.0.0.1} + - DB_NAME=${DB_NAME:-netbox} + - DB_USER=${DB_USER:-netbox} + - DB_PASSWORD=${DB_PASSWORD} + - REDIS_HOST=${REDIS_HOST:-127.0.0.1} + - SUPERUSER_NAME=${SUPERUSER_NAME:-admin} + - SUPERUSER_PASSWORD=${SUPERUSER_PASSWORD} + - GRANIAN_WORKERS=${GRANIAN_WORKERS:-4} # - GRANIAN_WORKERS_LIFETIME=12h volumes: - - /containers/netbox:/config + - ${NETBOX_CONFIG_PATH}:/config ports: - 8080:8080 - depends_on: [postgres, redis] - restart: always - postgres: # placeholder: any PostgreSQL 15+ FreeBSD image + postgres: image: ghcr.io/daemonless/postgres:18 - environment: - - POSTGRES_DB=netbox - - POSTGRES_USER=netbox - - POSTGRES_PASSWORD=changeme + container_name: netbox-postgres + network_mode: host + restart: unless-stopped annotations: org.freebsd.jail.allow.sysvipc: "true" + environment: + - POSTGRES_DB=${DB_NAME:-netbox} + - POSTGRES_USER=${DB_USER:-netbox} + - POSTGRES_PASSWORD=${DB_PASSWORD} volumes: - - /containers/netbox/postgres:/var/lib/postgresql/data - restart: always + - ${DB_DATA_LOCATION}:/var/lib/postgresql/data - redis: # placeholder: any Redis/Valkey FreeBSD image + redis: image: ghcr.io/daemonless/redis:latest - restart: always + container_name: netbox-redis + network_mode: host + restart: unless-stopped diff --git a/example.env b/example.env new file mode 100644 index 0000000..4d361ce --- /dev/null +++ b/example.env @@ -0,0 +1,15 @@ +# NetBox for FreeBSD (Daemonless) +# Copy to .env and edit. + +# Host paths for persistent storage +NETBOX_CONFIG_PATH=/containers/netbox/config +DB_DATA_LOCATION=/containers/netbox/postgres + +# Database password and first-run admin (change both before first start) +DB_NAME=netbox +DB_USER=netbox +DB_PASSWORD=changeme +SUPERUSER_NAME=admin +SUPERUSER_PASSWORD=changeme + +TZ=UTC diff --git a/postgres-template.conf b/postgres-template.conf new file mode 100644 index 0000000..101297e --- /dev/null +++ b/postgres-template.conf @@ -0,0 +1,14 @@ +# postgres-template.conf -- jail template for the PostgreSQL sidecar (AppJail) +# +# PostgreSQL needs System V shared memory. allow.sysvipc is a no-op on +# FreeBSD 15; the jail gets its own SysV IPC namespace instead. +exec.start: "/bin/sh /etc/rc" +exec.stop: "/bin/sh /etc/rc.shutdown jail" +mount.devfs +persist +# host networking (ip4_inherit is a no-op in AppJail 5.5.0; the parameters are not) +ip4: inherit +ip6: inherit +sysvmsg: new +sysvsem: new +sysvshm: new