diff --git a/Dockerfile b/Dockerfile index 9080f1d..1aafc48 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,6 +12,7 @@ LABEL maintainer="thespad" # environment settings ARG UNIFI_BRANCH="stable" ENV DEBIAN_FRONTEND="noninteractive" +ENV ENVSUBST_VERSION=v1.4.3 RUN \ echo "**** install packages ****" && \ @@ -20,7 +21,11 @@ RUN \ jsvc \ logrotate \ openjdk-17-jre-headless \ - unzip && \ + unzip \ + gettext && \ + 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 https://dl.ui.com/unifi/debian/dists/${UNIFI_BRANCH}/ubiquiti/binary-amd64/Packages.gz \ diff --git a/Dockerfile.aarch64 b/Dockerfile.aarch64 index 2909319..91a1645 100644 --- a/Dockerfile.aarch64 +++ b/Dockerfile.aarch64 @@ -12,6 +12,7 @@ LABEL maintainer="thespad" # environment settings ARG UNIFI_BRANCH="stable" ENV DEBIAN_FRONTEND="noninteractive" +ENV ENVSUBST_VERSION=v1.4.3 RUN \ echo "**** install packages ****" && \ @@ -20,7 +21,11 @@ RUN \ jsvc \ logrotate \ openjdk-17-jre-headless \ - unzip && \ + unzip \ + gettext && \ + 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 https://dl.ui.com/unifi/debian/dists/${UNIFI_BRANCH}/ubiquiti/binary-amd64/Packages.gz \ diff --git a/README.md b/README.md index 0feafa8..d491dd8 100644 --- a/README.md +++ b/README.md @@ -173,10 +173,8 @@ 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 - MONGO_AUTHSOURCE=admin - MEM_LIMIT=1024 #optional @@ -205,10 +203,8 @@ 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 MONGO_AUTHSOURCE=admin \ -e MEM_LIMIT=1024 `#optional` \ diff --git a/readme-vars.yml b/readme-vars.yml index 5fb807b..3ca875f 100644 --- a/readme-vars.yml +++ b/readme-vars.yml @@ -24,18 +24,15 @@ param_ports: - {external_port: "8080", internal_port: "8080", port_desc: "Required for device communication"} 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_AUTHSOURCE", env_value: "admin", desc: "Mongodb [authSource](https://www.mongodb.com/docs/manual/reference/connection-string/#mongodb-urioption-urioption.authSource). For Atlas set to `admin`. 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."} + opt_param_usage_include_ports: true opt_param_ports: - {external_port: "1900", internal_port: "1900/udp", port_desc: "Required for `Make controller discoverable on L2 network` option"} @@ -181,6 +178,7 @@ init_diagram: | "unifi-network-application:latest" <- Base Images # changelog changelogs: + - {date: "07.06.25:", desc: "Change environment variables"} - {date: "08.05.25:", desc: "Update sample `init-mongo.sh` for compatibility with 9.1.120 (only affects new installs)."} - {date: "13.02.25:", desc: "Revert JRE to 17."} - {date: "12.02.25:", desc: "Bump JRE to 21."} 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..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 @@ -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 environment variables 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