From fb1bd160e30d835e10514ec65943b46ec93ca503 Mon Sep 17 00:00:00 2001 From: sturman <4456572+sturman@users.noreply.github.com> Date: Sat, 24 Feb 2024 20:19:53 +0200 Subject: [PATCH 1/8] Use `envsubst` to replace placeholders in system.properties --- root/defaults/system.properties | 6 ++-- .../init-unifi-network-application-config/run | 34 ++----------------- 2 files changed, 6 insertions(+), 34 deletions(-) diff --git a/root/defaults/system.properties b/root/defaults/system.properties index 709e574..ab0084b 100644 --- a/root/defaults/system.properties +++ b/root/defaults/system.properties @@ -41,6 +41,6 @@ # unifi.throughput.port=6789 # db.mongo.local=false -db.mongo.uri=mongodb://~MONGO_USER~:~MONGO_PASS~@~MONGO_HOST~:~MONGO_PORT~/~MONGO_DBNAME~?tls=~MONGO_TLS~~MONGO_AUTHSOURCE~ -statdb.mongo.uri=mongodb://~MONGO_USER~:~MONGO_PASS~@~MONGO_HOST~:~MONGO_PORT~/~MONGO_DBNAME~_stat?tls=~MONGO_TLS~~MONGO_AUTHSOURCE~ -unifi.db.name=~MONGO_DBNAME~ +db.mongo.uri=$MONGO_URI +statdb.mongo.uri=$STAT_MONGO_URI +unifi.db.name=$MONGO_DBNAME diff --git a/root/etc/s6-overlay/s6-rc.d/init-unifi-network-application-config/run b/root/etc/s6-overlay/s6-rc.d/init-unifi-network-application-config/run index fd28c3c..d9c5427 100755 --- a/root/etc/s6-overlay/s6-rc.d/init-unifi-network-application-config/run +++ b/root/etc/s6-overlay/s6-rc.d/init-unifi-network-application-config/run @@ -28,39 +28,11 @@ if [[ ! -L "/usr/lib/unifi/run" ]]; then fi if [[ ! -e /config/data/system.properties ]]; then - if [[ -z "${MONGO_HOST}" ]]; then - echo "*** No MONGO_HOST set, cannot configure database settings. ***" + if [[ -z "${MONGO_URI}" || -z "${STAT_MONGO_URI}" || -z "${MONGO_DBNAME}" ]]; then + echo "*** Required environments are not set, cannot configure database settings. ***" sleep infinity else - echo "*** Waiting for MONGO_HOST ${MONGO_HOST} to be reachable. ***" - DBCOUNT=0 - while true; do - if nc -w1 "${MONGO_HOST}" "${MONGO_PORT}" >/dev/null 2>&1; then - break - fi - DBCOUNT=$((DBCOUNT+1)) - if [[ ${DBCOUNT} -gt 6 ]]; then - echo "*** Defined MONGO_HOST ${MONGO_HOST} is not reachable, cannot proceed. ***" - sleep infinity - fi - sleep 5 - done - sed -i "s/~MONGO_USER~/${MONGO_USER}/" /defaults/system.properties - sed -i "s/~MONGO_HOST~/${MONGO_HOST}/" /defaults/system.properties - sed -i "s/~MONGO_PORT~/${MONGO_PORT}/" /defaults/system.properties - sed -i "s/~MONGO_DBNAME~/${MONGO_DBNAME}/" /defaults/system.properties - sed -i "s/~MONGO_PASS~/${MONGO_PASS}/" /defaults/system.properties - if [[ "${MONGO_TLS,,}" = "true" ]]; then - sed -i "s/~MONGO_TLS~/true/" /defaults/system.properties - else - sed -i "s/~MONGO_TLS~/false/" /defaults/system.properties - fi - if [[ -z "${MONGO_AUTHSOURCE}" ]]; then - sed -i "s/~MONGO_AUTHSOURCE~//" /defaults/system.properties - else - sed -i "s/~MONGO_AUTHSOURCE~/\&authSource=${MONGO_AUTHSOURCE}/" /defaults/system.properties - fi - cp /defaults/system.properties /config/data + envsubst < /defaults/system.properties > /config/data/system.properties fi fi From 1146ec48fdb3c40e297da88ec03da2b8d5fd7b7d Mon Sep 17 00:00:00 2001 From: sturman <4456572+sturman@users.noreply.github.com> Date: Sat, 24 Feb 2024 20:20:02 +0200 Subject: [PATCH 2/8] Install `envsubst` --- Dockerfile | 3 ++- Dockerfile.aarch64 | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3e8e069..a499e44 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,7 +20,8 @@ RUN \ jsvc \ logrotate \ openjdk-17-jre-headless \ - unzip && \ + unzip \ + gettext && \ echo "**** install unifi ****" && \ if [ -z ${UNIFI_VERSION+x} ]; then \ UNIFI_VERSION=$(curl -sX GET http://dl.ui.com/unifi/debian/dists/${UNIFI_BRANCH}/ubiquiti/binary-amd64/Packages \ diff --git a/Dockerfile.aarch64 b/Dockerfile.aarch64 index 93d023b..8356967 100644 --- a/Dockerfile.aarch64 +++ b/Dockerfile.aarch64 @@ -20,7 +20,8 @@ RUN \ jsvc \ logrotate \ openjdk-17-jre-headless \ - unzip && \ + unzip \ + gettext && \ echo "**** install unifi ****" && \ if [ -z ${UNIFI_VERSION+x} ]; then \ UNIFI_VERSION=$(curl -sX GET http://dl.ui.com/unifi/debian/dists/${UNIFI_BRANCH}/ubiquiti/binary-amd64/Packages \ From 62dab7b4c20c8a0b3cbac848978efd3c5afeab54 Mon Sep 17 00:00:00 2001 From: sturman <4456572+sturman@users.noreply.github.com> Date: Sat, 24 Feb 2024 20:35:15 +0200 Subject: [PATCH 3/8] Install `envsubst` alternative (Go version) --- Dockerfile | 11 +++++++---- Dockerfile.aarch64 | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index a499e44..c6d46fc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,8 +10,9 @@ LABEL build_version="Linuxserver.io version:- ${VERSION} Build-date:- ${BUILD_DA LABEL maintainer="thespad" # environment settings -ARG UNIFI_BRANCH="stable" \ -DEBIAN_FRONTEND="noninteractive" +ARG UNIFI_BRANCH="stable" +ARG DEBIAN_FRONTEND="noninteractive" +ARG ENVSUBST_VERSION=v1.4.2 RUN \ echo "**** install packages ****" && \ @@ -20,8 +21,10 @@ RUN \ jsvc \ logrotate \ openjdk-17-jre-headless \ - unzip \ - gettext && \ + unzip && \ + curl -L https://github.com/a8m/envsubst/releases/download/${ENVSUBST_VERSION}/envsubst-`uname -s`-`uname -m` -o envsubst && \ + chmod +x envsubst && \ + mv envsubst /usr/local/bin && \ echo "**** install unifi ****" && \ if [ -z ${UNIFI_VERSION+x} ]; then \ UNIFI_VERSION=$(curl -sX GET http://dl.ui.com/unifi/debian/dists/${UNIFI_BRANCH}/ubiquiti/binary-amd64/Packages \ diff --git a/Dockerfile.aarch64 b/Dockerfile.aarch64 index 8356967..2c5e235 100644 --- a/Dockerfile.aarch64 +++ b/Dockerfile.aarch64 @@ -10,8 +10,9 @@ LABEL build_version="Linuxserver.io version:- ${VERSION} Build-date:- ${BUILD_DA LABEL maintainer="thespad" # environment settings -ARG UNIFI_BRANCH="stable" \ -DEBIAN_FRONTEND="noninteractive" +ARG UNIFI_BRANCH="stable" +ARG DEBIAN_FRONTEND="noninteractive" +ARG ENVSUBST_VERSION=v1.4.2 RUN \ echo "**** install packages ****" && \ @@ -20,8 +21,10 @@ RUN \ jsvc \ logrotate \ openjdk-17-jre-headless \ - unzip \ - gettext && \ + unzip && \ + curl -L https://github.com/a8m/envsubst/releases/download/${ENVSUBST_VERSION}/envsubst-`uname -s`-`uname -m` -o envsubst && \ + chmod +x envsubst && \ + mv envsubst /usr/local/bin && \ echo "**** install unifi ****" && \ if [ -z ${UNIFI_VERSION+x} ]; then \ UNIFI_VERSION=$(curl -sX GET http://dl.ui.com/unifi/debian/dists/${UNIFI_BRANCH}/ubiquiti/binary-amd64/Packages \ From a1b59c28ec2fe7f8dd6dfa57558dbd6d131aaaf7 Mon Sep 17 00:00:00 2001 From: sturman <4456572+sturman@users.noreply.github.com> Date: Sat, 24 Feb 2024 20:38:41 +0200 Subject: [PATCH 4/8] Set `DEBIAN_FRONTEND` environment variable --- Dockerfile | 2 +- Dockerfile.aarch64 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index c6d46fc..e1d2645 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ LABEL maintainer="thespad" # environment settings ARG UNIFI_BRANCH="stable" -ARG DEBIAN_FRONTEND="noninteractive" +ENV DEBIAN_FRONTEND="noninteractive" ARG ENVSUBST_VERSION=v1.4.2 RUN \ diff --git a/Dockerfile.aarch64 b/Dockerfile.aarch64 index 2c5e235..a26073f 100644 --- a/Dockerfile.aarch64 +++ b/Dockerfile.aarch64 @@ -11,7 +11,7 @@ LABEL maintainer="thespad" # environment settings ARG UNIFI_BRANCH="stable" -ARG DEBIAN_FRONTEND="noninteractive" +ENV DEBIAN_FRONTEND="noninteractive" ARG ENVSUBST_VERSION=v1.4.2 RUN \ From 3be04fb26202945d1944776df234367dadb9843e Mon Sep 17 00:00:00 2001 From: sturman <4456572+sturman@users.noreply.github.com> Date: Sat, 24 Feb 2024 20:55:31 +0200 Subject: [PATCH 5/8] Fix log message --- .../s6-rc.d/init-unifi-network-application-config/run | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/root/etc/s6-overlay/s6-rc.d/init-unifi-network-application-config/run b/root/etc/s6-overlay/s6-rc.d/init-unifi-network-application-config/run index d9c5427..2d14000 100755 --- a/root/etc/s6-overlay/s6-rc.d/init-unifi-network-application-config/run +++ b/root/etc/s6-overlay/s6-rc.d/init-unifi-network-application-config/run @@ -29,7 +29,7 @@ fi if [[ ! -e /config/data/system.properties ]]; then if [[ -z "${MONGO_URI}" || -z "${STAT_MONGO_URI}" || -z "${MONGO_DBNAME}" ]]; then - echo "*** Required environments are not set, cannot configure database settings. ***" + echo "*** Required environment variables are not set, cannot configure database settings. ***" sleep infinity else envsubst < /defaults/system.properties > /config/data/system.properties From 36abd4e7626e9073ce32b612b3b851db1bea4fc7 Mon Sep 17 00:00:00 2001 From: sturman <4456572+sturman@users.noreply.github.com> Date: Sat, 24 Feb 2024 21:50:33 +0200 Subject: [PATCH 6/8] Revert "Install `envsubst` alternative (Go version)" This reverts commit 62dab7b4 --- Dockerfile | 7 ++----- Dockerfile.aarch64 | 7 ++----- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index e1d2645..323a50b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,6 @@ LABEL maintainer="thespad" # environment settings ARG UNIFI_BRANCH="stable" ENV DEBIAN_FRONTEND="noninteractive" -ARG ENVSUBST_VERSION=v1.4.2 RUN \ echo "**** install packages ****" && \ @@ -21,10 +20,8 @@ RUN \ jsvc \ logrotate \ openjdk-17-jre-headless \ - unzip && \ - curl -L https://github.com/a8m/envsubst/releases/download/${ENVSUBST_VERSION}/envsubst-`uname -s`-`uname -m` -o envsubst && \ - chmod +x envsubst && \ - mv envsubst /usr/local/bin && \ + unzip \ + gettext && \ echo "**** install unifi ****" && \ if [ -z ${UNIFI_VERSION+x} ]; then \ UNIFI_VERSION=$(curl -sX GET http://dl.ui.com/unifi/debian/dists/${UNIFI_BRANCH}/ubiquiti/binary-amd64/Packages \ diff --git a/Dockerfile.aarch64 b/Dockerfile.aarch64 index a26073f..e705ccc 100644 --- a/Dockerfile.aarch64 +++ b/Dockerfile.aarch64 @@ -12,7 +12,6 @@ LABEL maintainer="thespad" # environment settings ARG UNIFI_BRANCH="stable" ENV DEBIAN_FRONTEND="noninteractive" -ARG ENVSUBST_VERSION=v1.4.2 RUN \ echo "**** install packages ****" && \ @@ -21,10 +20,8 @@ RUN \ jsvc \ logrotate \ openjdk-17-jre-headless \ - unzip && \ - curl -L https://github.com/a8m/envsubst/releases/download/${ENVSUBST_VERSION}/envsubst-`uname -s`-`uname -m` -o envsubst && \ - chmod +x envsubst && \ - mv envsubst /usr/local/bin && \ + unzip \ + gettext && \ echo "**** install unifi ****" && \ if [ -z ${UNIFI_VERSION+x} ]; then \ UNIFI_VERSION=$(curl -sX GET http://dl.ui.com/unifi/debian/dists/${UNIFI_BRANCH}/ubiquiti/binary-amd64/Packages \ From 27594b95a8141a912c1b3832c6262cf273f2b0e4 Mon Sep 17 00:00:00 2001 From: sturman <4456572+sturman@users.noreply.github.com> Date: Sat, 24 Feb 2024 21:51:16 +0200 Subject: [PATCH 7/8] Sort dependencies --- Dockerfile | 4 ++-- Dockerfile.aarch64 | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 323a50b..75c09b0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,11 +17,11 @@ RUN \ echo "**** install packages ****" && \ apt-get update && \ apt-get install --no-install-recommends -y \ + gettext \ jsvc \ logrotate \ openjdk-17-jre-headless \ - unzip \ - gettext && \ + unzip && \ echo "**** install unifi ****" && \ if [ -z ${UNIFI_VERSION+x} ]; then \ UNIFI_VERSION=$(curl -sX GET http://dl.ui.com/unifi/debian/dists/${UNIFI_BRANCH}/ubiquiti/binary-amd64/Packages \ diff --git a/Dockerfile.aarch64 b/Dockerfile.aarch64 index e705ccc..1191812 100644 --- a/Dockerfile.aarch64 +++ b/Dockerfile.aarch64 @@ -17,11 +17,11 @@ RUN \ echo "**** install packages ****" && \ apt-get update && \ apt-get install --no-install-recommends -y \ + gettext \ jsvc \ logrotate \ openjdk-17-jre-headless \ - unzip \ - gettext && \ + unzip && \ echo "**** install unifi ****" && \ if [ -z ${UNIFI_VERSION+x} ]; then \ UNIFI_VERSION=$(curl -sX GET http://dl.ui.com/unifi/debian/dists/${UNIFI_BRANCH}/ubiquiti/binary-amd64/Packages \ From 1a538030bef5f675b12fffe175c4e2e51f9b1275 Mon Sep 17 00:00:00 2001 From: sturman <4456572+sturman@users.noreply.github.com> Date: Wed, 20 Mar 2024 12:25:09 +0200 Subject: [PATCH 8/8] Add new environment variables to README.md --- README.md | 16 ++++------------ readme-vars.yml | 23 ++++++++++------------- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 0f5425a..4041032 100644 --- a/README.md +++ b/README.md @@ -145,15 +145,11 @@ services: - PUID=1000 - PGID=1000 - TZ=Etc/UTC - - MONGO_USER=unifi - - MONGO_PASS= - - MONGO_HOST=unifi-db - - MONGO_PORT=27017 + - MONGO_URI=mongodb+srv://unifi:password@unifi.mongodb.net/unifi?retryWrites=true&w=majority&appName=unifi + - STAT_MONGO_URI=mongodb+srv://unifi:password@unifi.mongodb.net/unifi_stats?retryWrites=true&w=majority&appName=unifi - MONGO_DBNAME=unifi - MEM_LIMIT=1024 #optional - MEM_STARTUP=1024 #optional - - MONGO_TLS= #optional - - MONGO_AUTHSOURCE= #optional volumes: - /path/to/unifi-network-application/data:/config ports: @@ -177,15 +173,11 @@ docker run -d \ -e PUID=1000 \ -e PGID=1000 \ -e TZ=Etc/UTC \ - -e MONGO_USER=unifi \ - -e MONGO_PASS= \ - -e MONGO_HOST=unifi-db \ - -e MONGO_PORT=27017 \ + -e MONGO_URI=mongodb+srv://unifi:password@unifi.mongodb.net/?retryWrites=true&w=majority&appName=unifi \ + -e STAT_MONGO_URI=mongodb+srv://unifi:password@unifi.mongodb.net/?retryWrites=true&w=majority&appName=unifi \ -e MONGO_DBNAME=unifi \ -e MEM_LIMIT=1024 `#optional` \ -e MEM_STARTUP=1024 `#optional` \ - -e MONGO_TLS= `#optional` \ - -e MONGO_AUTHSOURCE= `#optional` \ -p 8443:8443 \ -p 3478:3478/udp \ -p 10001:10001/udp \ diff --git a/readme-vars.yml b/readme-vars.yml index a297ca9..52fec8c 100644 --- a/readme-vars.yml +++ b/readme-vars.yml @@ -30,19 +30,15 @@ param_ports: param_usage_include_env: true param_env_vars: - - { env_var: "MONGO_USER", env_value: "unifi", desc: "Mongodb Username. Only evaluated on first run. **Special characters must be [url encoded](https://en.wikipedia.org/wiki/Percent-encoding)**." } - - { env_var: "MONGO_PASS", env_value: "", desc: "Mongodb Password. Only evaluated on first run. **Special characters must be [url encoded](https://en.wikipedia.org/wiki/Percent-encoding)**." } - - { env_var: "MONGO_HOST", env_value: "unifi-db", desc: "Mongodb Hostname. Only evaluated on first run." } - - { env_var: "MONGO_PORT", env_value: "27017", desc: "Mongodb Port. Only evaluated on first run." } - - { env_var: "MONGO_DBNAME", env_value: "unifi", desc: "Mongodb Database Name (stats DB is automatically suffixed with `_stat`). Only evaluated on first run." } + - { env_var: "MONGO_URI", env_value: "unifi", desc: "MongoDB URI. Only evaluated on first run." } + - { env_var: "STAT_MONGO_URI", env_value: "", desc: "MongoDB stat URI. Only evaluated on first run." } + - { env_var: "MONGO_DBNAME", env_value: "unifi", desc: "MongoDB Database Name (stats DB is automatically suffixed with `_stat`). Only evaluated on first run." } # optional container parameters opt_param_usage_include_env: true opt_param_env_vars: - { env_var: "MEM_LIMIT", env_value: "1024", desc: "Optionally change the Java memory limit (in Megabytes). Set to `default` to reset to default" } - { env_var: "MEM_STARTUP", env_value: "1024", desc: "Optionally change the Java initial/minimum memory (in Megabytes). Set to `default` to reset to default" } - - { env_var: "MONGO_TLS", env_value: "", desc: "Mongodb enable [TLS](https://www.mongodb.com/docs/manual/reference/connection-string/#mongodb-urioption-urioption.tls). Only evaluated on first run." } - - { env_var: "MONGO_AUTHSOURCE", env_value: "", desc: "Mongodb [authSource](https://www.mongodb.com/docs/manual/reference/connection-string/#mongodb-urioption-urioption.authSource). For Atlas set to `admin`.Defaults to `MONGO_DBNAME`.Only evaluated on first run." } opt_param_usage_include_ports: true opt_param_ports: @@ -57,15 +53,15 @@ app_setup_block_enabled: true app_setup_block: | After setup, the web UI is available at https://ip:8443. The application can be configured, or a backup restored, using the first run wizard. - **This container requires an external mongodb database instance.** + **This container requires an external MongoDB database instance.** ### Setting Up Your External Database - Starting with version 8.1 of Unifi Network Application, mongodb 3.6 through 7.0 are supported. + Starting with version 8.1 of Unifi Network Application, MongoDB 3.6 through 7.0 are supported. - **Make sure you pin your database image version and do not use `latest`, as mongodb does not support automatic upgrades between major versions.** + **Make sure you pin your database image version and do not use `latest`, as MongoDB does not support automatic upgrades between major versions.** - If you are using the [official mongodb container](https://hub.docker.com/_/mongo/), you can create your user using an `init-mongo.js` file with the following contents: + If you are using the [official MongoDB container](https://hub.docker.com/_/mongo/), you can create your user using an `init-mongo.js` file with the following contents: ```js db.getSiblingDB("MONGO_DBNAME").createUser({user: "MONGO_USER", pwd: "MONGO_PASS", roles: [{role: "dbOwner", db: "MONGO_DBNAME"}]}); @@ -86,7 +82,7 @@ app_setup_block: | restart: unless-stopped ``` - *Note that the init script method will only work on first run. If you start the mongodb container without an init script it will generate test data automatically and you will have to manually create your databases, or restart with a clean `/data/db` volume and an init script mounted.* + *Note that the init script method will only work on first run. If you start the MongoDB container without an init script it will generate test data automatically and you will have to manually create your databases, or restart with a clean `/data/db` volume and an init script mounted.* *If you are using the init script method do not also set `MONGO_INITDB_ROOT_USERNAME`, `MONGO_INITDB_ROOT_PASSWORD`, or any other "INITDB" values as they will cause conflicts.* @@ -123,6 +119,7 @@ app_setup_block: | # changelog changelogs: - - { date: "04.03.24:", desc: "Install from zip package instead of deb." } + - { date: "20.03.24:", desc: "Change environment variables" } + - { date: "04.02.24:", desc: "Install from zip package instead of deb." } - { date: "17.10.23:", desc: "Add environment variables for TLS and authSource to support Atlas and new MongoDB versions." } - { date: "05.09.23:", desc: "Initial release." }