Skip to content

Commit ad4b7a9

Browse files
committed
20211023 Blynk Server - experimental branch - PR 3 of 3
This PR began with a [Discord question](https://discord.com/channels/638610460567928832/638610461109256194/900627294798893056) and uncovered a small can of worms. 1. The [github.com/blynkkk/blynk-server](https://github.com/blynkkk/blynk-server) repository appears to have been deleted. The replacement fork is at [github.com/Peterkn2001/blynk-server](https://github.com/Peterkn2001/blynk-server). This requires a change to the Dockerfile. 2. There are several problems with the `directoryfix.sh` mechanism which are best shown by example: * By default, the script lacks execute permission: ``` $ cd ~/IOTstack $ ls -l ./.templates/blynk_server/directoryfix.sh -rw-r--r-- 1 pi pi 2524 Sep 6 11:39 ./.templates/blynk_server/directoryfix.sh ``` * Correcting, executing and examining the result: ``` $ chmod +x ./.templates/blynk_server/directoryfix.sh $ ./.templates/blynk_server/directoryfix.sh Sample properties files created in ~/IOTstack/volumes/blynk_server/data/config Make sure you edit the files with your details, and restart the container to take effect. $ tree ./volumes/blynk_server/ ./volumes/blynk_server/ └── data └── config ├── mail.properties └── server.properties ``` * That folder structure is incorrect. The service definition declares: ``` volumes: - ./volumes/blynk_server/data:/data - ./volumes/blynk_server/config:/config ``` and the Dockerfile expects `/config` in the `-serverConfig` and `-mailConfig` arguments: ``` ENTRYPOINT ["java", "-jar", "/blynk/server.jar", "-dataFolder", "/data", "-serverConfig", "/config/server.properties", "-mailConfig", "/config/mail.properties"] ``` * Thus, a manual fix is needed before the container initialises properly: ``` $ sudo mv ./volumes/blynk_server/data/config ./volumes/blynk_server/ $ tree ./volumes/blynk_server/ ./volumes/blynk_server/ ├── config │   ├── mail.properties │   └── server.properties └── data ``` * These problems could be corrected by altering `directoryfix.sh` but it still leaves the basic problem common to all "directoryFix" bandaids: the script only runs at menu time, or when the user "just knows" to run it by hand, and doesn't handle container self-repair automatically each time the container starts. 3. The existing Dockerfile references `adoptopenjdk/openjdk14` as its base image. At the time of writing (2021-10-23) the [DockerHub page](https://hub.docker.com/r/adoptopenjdk/openjdk14) claims to have been updated 6 months ago but the actual image that downloads on Raspbian is significantly older: ``` $ docker images | grep -e "^REPOSITORY" -e "^adoptopenjdk" REPOSITORY TAG IMAGE ID CREATED SIZE adoptopenjdk/openjdk14 latest 4b3c72387798 15 months ago 403MB ``` There is an example Dockerfile at [github.com/Peterkn2001/blynk-server](https://github.com/Peterkn2001/blynk-server/blob/master/server/Docker/Dockerfile) which uses `ubuntu` as its base image. This implies that the current Blynk Server fork is being tested on Ubuntu. It is also clear that Ubuntu is getting a lot more maintenance: ``` $ docker images | grep -e "^REPOSITORY" -e "ubuntu" REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu latest 897590a6c564 7 days ago 49.8MB ``` 4. The existing Dockerfile is tightly-coupled with the Blynk-Server version number. I have abstracted this using an `ARG` statement: ``` ARG BLYNK_SERVER_VERSION=0.41.16 ``` In the Dockerfile, this defaults to the current version but can be altered by the end user in the compose file: ``` blynk_server: build: context: ./.templates/blynk_server/. args: - BLYNK_SERVER_VERSION=0.41.16 ``` A user who wants to adopt a later version can alter the compose file and "build" the container. 5. The blynk server appears to listen to a large number of ports (at least 587, 7443, 8080, 8081, 8082, 8440, 8441, 8442, 8443 & 9443). Three ports seem to be directly relevant: - 8080 http.port - 8440 hardware.mqtt.port - 9443 https.port Those ports have been: - exposed in the Dockerfile, adding 8440 which *is* mentioned in `server.properties`; and - declared in the default service definition, removing 8441 which is *not* mentioned in `server.properties`. Note: - The Dockerfile at [github.com/Peterkn2001/blynk-server](https://github.com/Peterkn2001/blynk-server/blob/master/server/Docker/Dockerfile) attempts to expose: ``` EXPOSE ${HARDWARE_MQTT_PORT} ${HARDWARE_MQTT_PORT_SSL} ${HTTP_PORT} ${HTTPS_PORT} ``` `HARDWARE_MQTT_PORT_SSL` is *probably* intended to be port 8441 but it is not actually defined so it evaluates to a null. 6. Container self-repair is implemented in the now fairly well-established fashion: - An `iotstack_defaults` folder in the template is copied into the image. In this case, it contains the contents of the `config` directory. - A `docker-entrypoint.sh` in the template is copied into the image. When the container is brought up, this script executes first and performs self-repair, then "execs" the original command over the top. 7. Support for three environment variables: - `TZ=Etc/UTC` - the container already has timezone support so this just makes it clear that it can be activated. - `IOTSTACK_UID=1000` & `IOTSTACK_GID=1000` control the ownwership assigned to the "config" directory and its contents during self-repair. Defaults to "nobody" if omitted. 8. Documentation not changed.
1 parent d7acd7f commit ad4b7a9

File tree

6 files changed

+147
-108
lines changed

6 files changed

+147
-108
lines changed
Lines changed: 70 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,75 @@
1-
FROM adoptopenjdk/openjdk14
2-
MAINTAINER 877dev <[email protected]>
1+
# Acknowledgements:
2+
# Based on:
3+
# https://github.com/SensorsIot/IOTstack/blob/master/.templates/blynk_server/Dockerfile
4+
# (as at commit ID 4dff89c1bb6a5b1c01d3c087dcb662256a0c050f)
5+
# Borrows from:
6+
# https://github.com/Peterkn2001/blynk-server/blob/master/server/Docker/Dockerfile
7+
# (as at commit ID 889c7e55161832e21264d993d9fa5abd1c015e1c)
38

4-
#RUN apt-get update
5-
#RUN apt-get install -y apt-utils
6-
#RUN apt-get install -y default-jdk curl
9+
FROM ubuntu
710

8-
ENV BLYNK_SERVER_VERSION 0.41.16
9-
RUN mkdir /blynk
10-
RUN curl -L https://github.com/blynkkk/blynk-server/releases/download/v${BLYNK_SERVER_VERSION}/server-${BLYNK_SERVER_VERSION}.jar > /blynk/server.jar
11+
# declare the version to be built, defaulting to 0.41.16 (which is
12+
# current as of 2021-10-22)
13+
ARG BLYNK_SERVER_VERSION=0.41.16
1114

12-
# Create data folder. To persist data, map a volume to /data
13-
RUN mkdir /data
15+
# form the download URL
16+
ENV BLYNK_SERVER_URL=https://github.com/Peterkn2001/blynk-server/releases/download/v${BLYNK_SERVER_VERSION}/server-${BLYNK_SERVER_VERSION}.jar
1417

15-
# Create configuration folder. To persist data, map a file to /config/server.properties
16-
RUN mkdir /config && touch /config/server.properties
17-
VOLUME ["/config", "/data/backup"]
18+
# Add support packages to the base image
19+
RUN apt-get update \
20+
&& apt-get install -y \
21+
apt-utils \
22+
libreadline8 \
23+
libreadline-dev \
24+
&& apt-get install -y \
25+
curl \
26+
libxrender1 \
27+
maven \
28+
openjdk-11-jdk \
29+
rsync
1830

19-
WORKDIR /data
20-
ENTRYPOINT ["java", "-jar", "/blynk/server.jar", "-dataFolder", "/data", "-serverConfig", "/config/server.properties", "-mailConfig", "/config/mail.properties"]
31+
# Add IOTstack-specific support
32+
ENV IOTSTACK_DEFAULTS_DIR="iotstack_defaults"
33+
ENV IOTSTACK_ENTRY_POINT="docker-entrypoint.sh"
34+
COPY ${IOTSTACK_DEFAULTS_DIR} /${IOTSTACK_DEFAULTS_DIR}
35+
COPY ${IOTSTACK_ENTRY_POINT} /${IOTSTACK_ENTRY_POINT}
36+
RUN chmod 755 /${IOTSTACK_ENTRY_POINT}
37+
38+
# define well-known paths
39+
ENV IOTSTACK_DATA_DIR="/data"
40+
ENV IOTSTACK_CONF_DIR="/config"
41+
ENV IOTSTACK_JAVA_DIR="/blynk"
42+
43+
# Create and populate expected folders
44+
RUN mkdir -p ${IOTSTACK_DATA_DIR} ${IOTSTACK_JAVA_DIR} \
45+
&& curl -L ${BLYNK_SERVER_URL} >"${IOTSTACK_JAVA_DIR}/server.jar"
46+
47+
# declare expected mapped volumes
48+
VOLUME ["${IOTSTACK_CONF_DIR}", "${IOTSTACK_DATA_DIR}"]
49+
50+
# Expose assumed internal ports:
51+
# 8080 http.port
52+
# 8440 hardware.mqtt.port
53+
# 9443 https.port
54+
EXPOSE 8080 8440 9443
55+
56+
# set the working directory
57+
WORKDIR ${IOTSTACK_DATA_DIR}
58+
59+
# define launch procedure
60+
ENTRYPOINT ["/docker-entrypoint.sh"]
61+
CMD ["java", "-jar", "/blynk/server.jar", "-dataFolder", "/data", "-serverConfig", "/config/server.properties", "-mailConfig", "/config/mail.properties"]
62+
63+
# supplement image metadata
64+
LABEL blynk-server.version=${BLYNK_SERVER_VERSION}
65+
LABEL blynk-server.url=${BLYNK_SERVER_URL}
66+
LABEL com.github.SensorsIot.IOTstack.Dockerfile.maintainer="877dev <[email protected]>"
67+
LABEL com.github.Peterkn2001.blynk-server.Dockerfile.maintainer="Florian Mauduit <[email protected]>"
68+
69+
# unset variables that are not needed by docker-entrypoint.sh
70+
ENV IOTSTACK_ENTRY_POINT=
71+
ENV IOTSTACK_DATA_DIR=
72+
ENV IOTSTACK_JAVA_DIR=
73+
ENV BLYNK_SERVER_URL=
74+
75+
# EOF
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# were we launched as root with defaults available?
5+
if [ "$(id -u)" = "0" -a -d /"$IOTSTACK_DEFAULTS_DIR" ]; then
6+
7+
# yes! ensure that the IOTSTACK_CONF_DIR exists
8+
mkdir -p "$IOTSTACK_CONF_DIR"
9+
10+
# populate runtime directory from the defaults
11+
rsync -arp --ignore-existing "/${IOTSTACK_DEFAULTS_DIR}/" "${IOTSTACK_CONF_DIR}"
12+
13+
# enforce correct ownership
14+
chown -R "${IOTSTACK_UID:-nobody}":"${IOTSTACK_GID:-nobody}" "$IOTSTACK_CONF_DIR"
15+
16+
fi
17+
18+
# start the blynk server
19+
exec "$@"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
mail.smtp.auth=true
2+
mail.smtp.starttls.enable=true
3+
mail.smtp.host=smtp.gmail.com
4+
mail.smtp.port=587
5+
mail.smtp.username[email protected]
6+
mail.smtp.password=YOUR_GMAIL_APP_PASSWORD
7+
mail.smtp.connectiontimeout=30000
8+
mail.smtp.timeout=120000
9+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
hardware.mqtt.port=8440
2+
http.port=8080
3+
force.port.80.for.csv=false
4+
force.port.80.for.redirect=true
5+
https.port=9443
6+
data.folder=./data
7+
logs.folder=./logs
8+
log.level=info
9+
user.devices.limit=10
10+
user.tags.limit=100
11+
user.dashboard.max.limit=100
12+
user.widget.max.size.limit=20
13+
user.message.quota.limit=100
14+
notifications.queue.limit=2000
15+
blocking.processor.thread.pool.limit=6
16+
notifications.frequency.user.quota.limit=5
17+
webhooks.frequency.user.quota.limit=1000
18+
webhooks.response.size.limit=96
19+
user.profile.max.size=128
20+
terminal.strings.pool.size=25
21+
map.strings.pool.size=25
22+
lcd.strings.pool.size=6
23+
table.rows.pool.size=100
24+
profile.save.worker.period=60000
25+
stats.print.worker.period=60000
26+
web.request.max.size=524288
27+
csv.export.data.points.max=43200
28+
hard.socket.idle.timeout=10
29+
enable.db=false
30+
enable.raw.db.data.store=false
31+
async.logger.ring.buffer.size=2048
32+
allow.reading.widget.without.active.app=false
33+
allow.store.ip=true
34+
initial.energy=1000000
35+
admin.rootPath=/admin
36+
restore.host=blynk-cloud.com
37+
product.name=Blynk
38+
admin.email[email protected]
39+
admin.pass=admin
40+

.internal/templates/services/blynk_server/directoryfix.sh

Lines changed: 0 additions & 90 deletions
This file was deleted.

.internal/templates/services/blynk_server/template.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
blynk_server:
2-
build: ./services/blynk_server/.
2+
build:
3+
context: ./.templates/blynk_server/.
4+
args:
5+
- BLYNK_SERVER_VERSION=0.41.16
36
container_name: blynk_server
47
restart: unless-stopped
8+
environment:
9+
- TZ=Etc/UTC
10+
- IOTSTACK_UID=1000
11+
- IOTSTACK_GID=1000
512
ports:
613
- "8180:8080"
7-
- "8441:8441"
14+
- "8440:8440"
815
- "9443:9443"
916
volumes:
1017
- ./volumes/blynk_server/data:/data
1118
- ./volumes/blynk_server/config:/config
1219
networks:
1320
- iotstack_nw
14-

0 commit comments

Comments
 (0)