#===============================================================================
# NGINX UI ENVIRONMENT CONFIGURATION - LOCAL
# Yet another WebUI for Nginx
# Web UI: http://<host>:9000 (first run: http://<host>:9000/install)
# Nginx HTTP: port 80, HTTPS: port 443
# Docs: https://nginxui.com/
#===============================================================================

#===============================================================================
# STACK CONFIGURATION
#===============================================================================
STACK_NAME=stk-nginxui-001
STACK_BINDMOUNTROOT=custom/docker/stacks
TZ=Etc/UTC
PUID=0
PGID=0

# Host folder holding the compiled binaries, relative to the stack directory:
#   /custom/docker/stacks/stk-nginxui-001/custom/bin/
# ./build.sh writes BOTH nginx and angie here; NginxUI mounts it READ-ONLY at
# NGINXUI_BINDIR (/opt/custom/bin inside the container).
STACK_CUSTOMBINPATH=custom/bin

#===============================================================================
# NGINX UI CONFIGURATION
#===============================================================================
NGINXUI_IMAGENAME=uozi/nginx-ui
NGINXUI_IMAGEVERSION=latest
NGINXUI_CONTAINERNAME=NGINXUI-APP-001
NGINXUI_ENABLEAUTOMATICUPDATES=false
NGINXUI_RESTARTPOLICY=unless-stopped
NGINXUI_STOPGRACEPERIOD=60s
NGINX_UI_IGNORE_DOCKER_SOCKET=true
NGINX_UI_PRESERVE_BUNDLED_CONF=true

# Nginx UI listening port (default: 9000)
# HTTP Challenge port (default: 9180) - configured in app.ini
NGINXUI_PORT=9000

NGINXUI_HEALTHCHECKSTARTPERIOD=30s
NGINXUI_HEALTHCHECKINTERVAL=30s
NGINXUI_HEALTHCHECKRETRIES=3
NGINXUI_HEALTHCHECKTIMEOUT=10s

#===============================================================================
# CUSTOM BINARY SELECTION
#
# ./build.sh compiles BOTH nginx and angie into the shared folder, so all
# three options below are available at once. Switching is one line + a
# redeploy - no rebuild.
#
# NGINXUI_SBINPATH -> NGINX_UI_NGINX_SBIN_PATH -> nginx.SbinPath (v2.1.10+)
# The single switch deciding which executable Nginx UI drives for -t,
# -s reload, and restart. Empty = Nginx UI falls back to a $PATH lookup.
#
# ---- PICK ONE ----
#
#  1. STOCK (default) - the binary bundled in the Nginx UI image.
NGINXUI_SBINPATH=/usr/sbin/nginx
#
#  2. CUSTOM NGINX - your compiled build with nginx-ntlm-module etc.
#NGINXUI_SBINPATH=/opt/custom/bin/nginx
#
#  3. ANGIE - the nginx fork, dropped in unchanged. builder/compile.sh compiles
#     it against the identical path layout, so it reads the same /etc/nginx
#     tree and speaks the same CLI. Nothing else needs to change.
#NGINXUI_SBINPATH=/opt/custom/bin/angie
#
#===============================================================================

# Where the binaries folder appears INSIDE the Nginx UI container. Mirrors the
# host path by default so the two are easy to reason about. Deliberately not
# /usr/sbin - overlaying that would hide every other binary there.
NGINXUI_BINDIR=/opt/custom/bin

#-------------------------------------------------------------------------------
# Remaining nginx.* settings. Empty = Nginx UI auto-detects, which is correct
# whenever the custom binary was compiled against the stock path layout.
# Override only if you changed those paths via NGINXBUILD_CONFIGUREARGS.
#
# Setting any *_CMD takes over completely and IGNORES SBINPATH, e.g.
#   NGINXUI_TESTCONFIGCMD=/opt/custom/bin/nginx -p /etc/nginx -t
#-------------------------------------------------------------------------------
NGINXUI_CONFIGDIR=
NGINXUI_PIDPATH=
NGINXUI_ACCESSLOGPATH=
NGINXUI_ERRORLOGPATH=
NGINXUI_TESTCONFIGCMD=
NGINXUI_RELOADCMD=
NGINXUI_RESTARTCMD=
NGINXUI_STUBSTATUSPORT=
NGINXUI_NGINXCONTAINERNAME=

#===============================================================================
# BUILDER CONFIGURATION
#
# Read by ./build.sh, NOT by docker-compose. The build runs entirely on its own
# - the stack is never started, stopped, or touched to produce a binary.
#
#   ./build.sh                    (picks up this .env automatically)
#   curl -fsSL https://prod.git.gracesolution.info/Grace-Solutions/NginX-Custom-Binary/raw/branch/main/build.sh | bash
#
# Command-line flags override everything here.
#===============================================================================

NGINXBUILD_IMAGENAME=local/nginx-custom-binary

# Case-insensitive regex matched against running container names to locate the
# Nginx UI container. build.sh then reads its nginx version AND its bind mounts,
# so the export directory comes from Docker rather than from the paths above.
#   ./build.sh --discover     shows what it found without building
#   ./build.sh --no-discover  ignores containers, uses the STACK_* paths
NGINXUI_MATCHPATTERN=.*nginx.*ui.*

# nginx | angie | both
# "both" builds each and puts them side by side in STACK_CUSTOMBINPATH.
NGINXBUILD_FLAVOR=both

# Fallback only. The nginx version is normally read off the discovered
# container, and MUST match it so the custom binary understands the bundled
# nginx.conf. Used when no container is found, or discovery is disabled.
#   docker exec NGINXUI-APP-001 nginx -V
NGINXBUILD_VERSION=1.31.3

# Angie has its own version series and is never auto-detected from the
# container. Current releases: https://download.angie.software/files/
NGINXBUILD_ANGIEVERSION=1.12.1

# Output filename in the shared folder. Empty = same as the flavor.
NGINXBUILD_ARTIFACTNAME=

# Compile-stage base. Must be ABI-compatible with the Nginx UI runtime (same
# glibc + libssl soname) - the artifact links against libraries provided by the
# NginxUI container, not this one.
#   debian:trixie         gcc 14.2 / glibc 2.41 / OpenSSL 3.5.x
#   uozi/nginx-ui:latest  guaranteed exact match; needs working apt in-image
NGINXBUILD_BUILDERBASE=debian:trixie
NGINXBUILD_EXPORTBASE=debian:trixie-slim

# Full override of ./configure. Empty = flavor preset in builder/compile.sh.
# --add-module flags and hardening cc/ld flags are appended either way.
NGINXBUILD_CONFIGUREARGS=

# 1 = strip debug symbols. 1 = keep a .prev copy of any replaced binary.
NGINXBUILD_STRIP=0
NGINXBUILD_KEEPPREVIOUS=1

#===============================================================================
# NOTES
#===============================================================================
# This container runs in host network mode, exposing:
#   - Port 80: Nginx HTTP
#   - Port 443: Nginx HTTPS
#   - Port 9000: Nginx UI Web Interface
#   - Port 9180: HTTP Challenge for Let's Encrypt (default)
#
# FIRST RUN:
#   1. Ensure the nginx volume mount is EMPTY on first deployment
#   2. Visit http://<host>:9000/install to complete setup
#   3. Create admin credentials and configure settings
#
# CUSTOM BINARY WORKFLOW:
#   1. ./build.sh                      (builds nginx + angie, stack untouched)
#   2. Set NGINXUI_SBINPATH to /opt/custom/bin/<artifact> (option 2 or 3 above)
#   3. docker compose up -d NginxUI
#   4. docker exec NGINXUI-APP-001 /opt/custom/bin/nginx -V   -> confirm modules
#
#   SBINPATH governs the commands Nginx UI issues. The container entrypoint
#   still boots /usr/sbin/nginx, so restart nginx from the UI (or uncomment the
#   overlay mount in docker-compose.yml) to make the custom binary the master.
#
# ADDING MODULES:
#   Edit builder/modules.txt, or pass them at build time:
#     ./build.sh -m https://github.com/openresty/headers-more-nginx-module@v0.38
#
# CONFIGURATION FILE:
#   After first run, edit /etc/nginx-ui/app.ini to change ports or settings
#   Default locations in container:
#     - Nginx config: /etc/nginx/
#     - Nginx UI config: /etc/nginx-ui/app.ini
#     - Web root: /var/www/
#     - Custom binaries: /opt/custom/bin/ (read-only, written by ./build.sh)
