Skip to content

Commit 63b058e

Browse files
committed
feat: change MongoDB environment variables
1 parent de35bdb commit 63b058e

File tree

5 files changed

+22
-43
lines changed

5 files changed

+22
-43
lines changed

Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ LABEL maintainer="thespad"
1212
# environment settings
1313
ARG UNIFI_BRANCH="stable"
1414
ENV DEBIAN_FRONTEND="noninteractive"
15+
ENV ENVSUBST_VERSION=v1.4.3
1516

1617
RUN \
1718
echo "**** install packages ****" && \
@@ -20,7 +21,11 @@ RUN \
2021
jsvc \
2122
logrotate \
2223
openjdk-17-jre-headless \
23-
unzip && \
24+
unzip \
25+
gettext && \
26+
curl -L https://github.com/a8m/envsubst/releases/download/${ENVSUBST_VERSION}/envsubst-`uname -s`-`uname -m` -o envsubst && \
27+
chmod +x envsubst && \
28+
mv envsubst /usr/local/bin && \
2429
echo "**** install unifi ****" && \
2530
if [ -z ${UNIFI_VERSION+x} ]; then \
2631
UNIFI_VERSION=$(curl -sX GET https://dl.ui.com/unifi/debian/dists/${UNIFI_BRANCH}/ubiquiti/binary-amd64/Packages.gz \

Dockerfile.aarch64

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ LABEL maintainer="thespad"
1212
# environment settings
1313
ARG UNIFI_BRANCH="stable"
1414
ENV DEBIAN_FRONTEND="noninteractive"
15+
ENV ENVSUBST_VERSION=v1.4.3
1516

1617
RUN \
1718
echo "**** install packages ****" && \
@@ -20,7 +21,11 @@ RUN \
2021
jsvc \
2122
logrotate \
2223
openjdk-17-jre-headless \
23-
unzip && \
24+
unzip \
25+
gettext && \
26+
curl -L https://github.com/a8m/envsubst/releases/download/${ENVSUBST_VERSION}/envsubst-`uname -s`-`uname -m` -o envsubst && \
27+
chmod +x envsubst && \
28+
mv envsubst /usr/local/bin && \
2429
echo "**** install unifi ****" && \
2530
if [ -z ${UNIFI_VERSION+x} ]; then \
2631
UNIFI_VERSION=$(curl -sX GET https://dl.ui.com/unifi/debian/dists/${UNIFI_BRANCH}/ubiquiti/binary-amd64/Packages.gz \

readme-vars.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,14 @@ param_ports:
2424
- {external_port: "8080", internal_port: "8080", port_desc: "Required for device communication"}
2525
param_usage_include_env: true
2626
param_env_vars:
27-
- {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)**."}
28-
- {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)**."}
29-
- {env_var: "MONGO_HOST", env_value: "unifi-db", desc: "Mongodb Hostname. Only evaluated on first run."}
30-
- {env_var: "MONGO_PORT", env_value: "27017", desc: "Mongodb Port. Only evaluated on first run."}
31-
- {env_var: "MONGO_DBNAME", env_value: "unifi", desc: "Mongodb Database Name (stats DB is automatically suffixed with `_stat`). Only evaluated on first run."}
32-
- {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."}
27+
- {env_var: "MONGO_URI", env_value: "unifi", desc: "MongoDB URI. Only evaluated on first run."}
28+
- {env_var: "STAT_MONGO_URI", env_value: "", desc: "MongoDB stat URI. Only evaluated on first run."}
29+
- {env_var: "MONGO_DBNAME", env_value: "unifi", desc: "MongoDB Database Name (stats DB is automatically suffixed with `_stat`). Only evaluated on first run."}
3330
# optional container parameters
3431
opt_param_usage_include_env: true
3532
opt_param_env_vars:
3633
- {env_var: "MEM_LIMIT", env_value: "1024", desc: "Optionally change the Java memory limit (in Megabytes). Set to `default` to reset to default"}
3734
- {env_var: "MEM_STARTUP", env_value: "1024", desc: "Optionally change the Java initial/minimum memory (in Megabytes). Set to `default` to reset to default"}
38-
- {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."}
3935
opt_param_usage_include_ports: true
4036
opt_param_ports:
4137
- {external_port: "1900", internal_port: "1900/udp", port_desc: "Required for `Make controller discoverable on L2 network` option"}
@@ -181,6 +177,7 @@ init_diagram: |
181177
"unifi-network-application:latest" <- Base Images
182178
# changelog
183179
changelogs:
180+
- {date: "17.07.25:", desc: "Change environment variables"}
184181
- {date: "08.05.25:", desc: "Update sample `init-mongo.sh` for compatibility with 9.1.120 (only affects new installs)."}
185182
- {date: "13.02.25:", desc: "Revert JRE to 17."}
186183
- {date: "12.02.25:", desc: "Bump JRE to 21."}

root/defaults/system.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@
4141
# unifi.throughput.port=6789
4242
#
4343
db.mongo.local=false
44-
db.mongo.uri=mongodb://~MONGO_USER~:~MONGO_PASS~@~MONGO_HOST~:~MONGO_PORT~/~MONGO_DBNAME~?tls=~MONGO_TLS~~MONGO_AUTHSOURCE~
45-
statdb.mongo.uri=mongodb://~MONGO_USER~:~MONGO_PASS~@~MONGO_HOST~:~MONGO_PORT~/~MONGO_DBNAME~_stat?tls=~MONGO_TLS~~MONGO_AUTHSOURCE~
46-
unifi.db.name=~MONGO_DBNAME~
44+
db.mongo.uri=$MONGO_URI
45+
statdb.mongo.uri=$STAT_MONGO_URI
46+
unifi.db.name=$MONGO_DBNAME

root/etc/s6-overlay/s6-rc.d/init-unifi-network-application-config/run

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,39 +28,11 @@ if [[ ! -L "/usr/lib/unifi/run" ]]; then
2828
fi
2929

3030
if [[ ! -e /config/data/system.properties ]]; then
31-
if [[ -z "${MONGO_HOST}" ]]; then
32-
echo "*** No MONGO_HOST set, cannot configure database settings. ***"
31+
if [[ -z "${MONGO_URI}" || -z "${STAT_MONGO_URI}" || -z "${MONGO_DBNAME}" ]]; then
32+
echo "*** Required environment variables are not set, cannot configure database settings. ***"
3333
sleep infinity
3434
else
35-
echo "*** Waiting for MONGO_HOST ${MONGO_HOST} to be reachable. ***"
36-
DBCOUNT=0
37-
while true; do
38-
if nc -w1 "${MONGO_HOST}" "${MONGO_PORT}" >/dev/null 2>&1; then
39-
break
40-
fi
41-
DBCOUNT=$((DBCOUNT+1))
42-
if [[ ${DBCOUNT} -gt 6 ]]; then
43-
echo "*** Defined MONGO_HOST ${MONGO_HOST} is not reachable, cannot proceed. ***"
44-
sleep infinity
45-
fi
46-
sleep 5
47-
done
48-
sed -i "s/~MONGO_USER~/${MONGO_USER}/" /defaults/system.properties
49-
sed -i "s/~MONGO_HOST~/${MONGO_HOST}/" /defaults/system.properties
50-
sed -i "s/~MONGO_PORT~/${MONGO_PORT}/" /defaults/system.properties
51-
sed -i "s/~MONGO_DBNAME~/${MONGO_DBNAME}/" /defaults/system.properties
52-
sed -i "s/~MONGO_PASS~/${MONGO_PASS}/" /defaults/system.properties
53-
if [[ "${MONGO_TLS,,}" = "true" ]]; then
54-
sed -i "s/~MONGO_TLS~/true/" /defaults/system.properties
55-
else
56-
sed -i "s/~MONGO_TLS~/false/" /defaults/system.properties
57-
fi
58-
if [[ -z "${MONGO_AUTHSOURCE}" ]]; then
59-
sed -i "s/~MONGO_AUTHSOURCE~//" /defaults/system.properties
60-
else
61-
sed -i "s/~MONGO_AUTHSOURCE~/\&authSource=${MONGO_AUTHSOURCE}/" /defaults/system.properties
62-
fi
63-
cp /defaults/system.properties /config/data
35+
envsubst < /defaults/system.properties > /config/data/system.properties
6436
fi
6537
fi
6638

0 commit comments

Comments
 (0)