Skip to content

Commit 758f312

Browse files
committed
20211023 Blynk Server - master branch - PR 1 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 updated to describe IOTstack build process.
1 parent 5ba4bb9 commit 758f312

File tree

8 files changed

+416
-507
lines changed

8 files changed

+416
-507
lines changed

.templates/blynk_server/Dockerfile

Lines changed: 69 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +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-
# IP port listing:
20-
# 8080: Hardware without ssl/tls support
21-
# 9443: Blynk app, https, web sockets, admin port
22-
EXPOSE 8080 9443
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}
2337

24-
WORKDIR /data
25-
ENTRYPOINT ["java", "-jar", "/blynk/server.jar", "-dataFolder", "/data", "-serverConfig", "/config/server.properties", "-mailConfig", "/config/mail.properties"]
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

0 commit comments

Comments
 (0)