Skip to content

Commit e56d449

Browse files
Merge pull request #43 from paulgrainger85/master
Add Alpine docker environment and ARM64 instructions
2 parents 7985c95 + 2c4c15a commit e56d449

File tree

5 files changed

+106
-2
lines changed

5 files changed

+106
-2
lines changed

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,25 @@ MQTT is used commonly for constrained devices with low-bandwidth, high-latency o
132132
133133
#### Docker - Linux
134134
135+
There are two sample docker files provided in the `docker_linux` directory.
136+
137+
#### CentOS 7
138+
135139
A sample docker file is provided in the `docker_linux` directory to create a CentOS 7 environment (including downloading the `paho.mqtt.c` 64 bit Linux release) before building and installing the kdb+ `mqtt` interface.
136140
137-
The `MQTT_INSTALL_DIR` and `QHOME` directories are specified at the top of `mqtt_build.bat`, which sets up the environment specified in `Dockerfile.build` and invokes `mqtt_build.sh` to build the library.
141+
The `MQTT_INSTALL_DIR` and `QHOME` directories are specified at the top of `mqtt_build.bat`, which sets up the environment specified in `Dockerfile.centos7` and invokes `mqtt_build.sh` to build the library.
142+
143+
##### Alpine
144+
145+
A lightweight Alpine environment is also provided. The file `Dockerfile.alpine` specifies the environment and build steps. This image will have a smaller footprint than the above and may be more suited to smaller IOT devices.
146+
147+
Note if this is to be built for a ARM64 device (on a non-ARM device), be sure to have multi-platform builds available. See this blog post for more information:
148+
https://www.docker.com/blog/multi-platform-docker-builds/
149+
150+
e.g. Building on x86-64 for ARM:
151+
152+
`docker buildx build --platform linux/arm64 -t mqtt-kdb-arm64 --load --file docker_linux/Dockerfile.alpine .`
153+
138154
139155
## Quick Start
140156

docker_linux/Dockerfile.alpine

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
FROM alpine:3.14
2+
3+
RUN mkdir -p /q/l64
4+
RUN mkdir -p /source/paho.mqtt.c
5+
RUN mkdir -p /source/mqtt/examples
6+
RUN mkdir -p /source/mqtt/q
7+
RUN mkdir -p /source/mqtt/src
8+
RUN mkdir -p /source/mqtt/include
9+
10+
COPY docker_linux/mqtt_build.sh /source
11+
12+
COPY CMakeLists.txt /source/mqtt
13+
COPY docker_linux/build_libpaho.sh /source/mqtt
14+
COPY install.sh /source/mqtt
15+
COPY README.md /source/mqtt
16+
COPY LICENSE /source/mqtt
17+
18+
COPY examples/ /source/mqtt/examples
19+
COPY src/ /source/mqtt/src
20+
COPY include/ /source/mqtt/include
21+
COPY q/mqtt.q /q/
22+
23+
ENV QHOME /q
24+
ENV PATH /q/l64:$PATH
25+
ENV LD_LIBRARY_PATH /usr/local/lib:$LD_LIBRARY_PATH
26+
ENV MQTT_INSTALL_DIR /source/paho.mqtt.c
27+
ENV BUILD_HOME /source/paho.mqtt.c
28+
29+
RUN apk add --update && \
30+
apk add build-base && \
31+
apk add cmake && \
32+
apk add make && \
33+
apk add openssl-dev && \
34+
apk add wget && \
35+
apk add gcompat && \
36+
apk add libnsl && \
37+
cd /source && \
38+
39+
# MQTT Libs
40+
/bin/sh /source/mqtt/build_libpaho.sh && \
41+
42+
# Clean up
43+
apk del gcc && \
44+
apk del cmake && \
45+
apk del make && \
46+
apk del wget && \
47+
apk del build-base && \
48+
rm -rf /source/mqtt_build.sh /source/paho.mqtt.c /source/v1.3.9* /source/mqtt/CmakeLists.txt
49+
50+
## Update this section here to add kdb+
51+
#COPY q/k4.lic /q/
52+
#COPY q/q.k /q/
53+
#COPY q/l64/q /q/l64
54+
55+
## If running licensed version of kdb, you may also need taskset to start the process
56+
# apk add util-linux
57+
58+
WORKDIR /source
59+
60+
ENTRYPOINT ["/bin/sh"]
File renamed without changes.

docker_linux/build_libpaho.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/sh
2+
3+
cd /source
4+
5+
wget https://github.com/eclipse/paho.mqtt.c/archive/refs/tags/v1.3.9.tar.gz
6+
tar xvf v1.3.9.tar.gz -C ./paho.mqtt.c --strip-components=1
7+
8+
cd paho.mqtt.c
9+
10+
# This library is not present in the Alpine image, removing it from the compiler args
11+
sed -i 's/GAI_LIB = -lanl/#GAI_LIB = -lanl/g' Makefile
12+
ln -s /usr/lib/libnsl.so.2 /usr/lib/libnsl.so.1
13+
14+
make
15+
make install
16+
mkdir -p include/lib
17+
cd include/lib
18+
19+
ln -s /usr/local/lib/libpaho-mqtt3c.so libpaho-mqtt3c.a
20+
ln -s /usr/local/lib/libpaho-mqtt3cs.so libpaho-mqtt3cs.a
21+
ln -s /usr/local/lib/libpaho-mqtt3as.so libpaho-mqtt3as.a
22+
ln -s /usr/local/lib/libpaho-mqtt3a.so libpaho-mqtt3a.a
23+
24+
mkdir /source/mqtt/cmake
25+
cd /source/mqtt/cmake
26+
cmake ..
27+
make
28+
make install

docker_linux/mqtt_build.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ SETLOCAL
33
SET MQTT_SOURCE="C:\Users\guest\Development\mqtt"
44
SET QHOME_LINUX="C:\q"
55

6-
docker build -f Dockerfile.build -t mqtt-dev .
6+
docker build -f Dockerfile.centos7 -t mqtt-dev .
77
docker run --rm -it -v %MQTT_SOURCE%:/source/mqtt -v %QHOME_LINUX%:/q mqtt-dev /bin/bash -c /source/mqtt_build.sh
88

99
ENDLOCAL

0 commit comments

Comments
 (0)