Skip to content

Commit

Permalink
Merge pull request #43 from paulgrainger85/master
Browse files Browse the repository at this point in the history
Add Alpine docker environment and ARM64 instructions
  • Loading branch information
nmcdonnell-kx authored Sep 16, 2021
2 parents 7985c95 + 2c4c15a commit e56d449
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 2 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,25 @@ MQTT is used commonly for constrained devices with low-bandwidth, high-latency o
#### Docker - Linux
There are two sample docker files provided in the `docker_linux` directory.
#### CentOS 7
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.
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.
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.
##### Alpine
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.
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:
https://www.docker.com/blog/multi-platform-docker-builds/
e.g. Building on x86-64 for ARM:
`docker buildx build --platform linux/arm64 -t mqtt-kdb-arm64 --load --file docker_linux/Dockerfile.alpine .`
## Quick Start
Expand Down
60 changes: 60 additions & 0 deletions docker_linux/Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
FROM alpine:3.14

RUN mkdir -p /q/l64
RUN mkdir -p /source/paho.mqtt.c
RUN mkdir -p /source/mqtt/examples
RUN mkdir -p /source/mqtt/q
RUN mkdir -p /source/mqtt/src
RUN mkdir -p /source/mqtt/include

COPY docker_linux/mqtt_build.sh /source

COPY CMakeLists.txt /source/mqtt
COPY docker_linux/build_libpaho.sh /source/mqtt
COPY install.sh /source/mqtt
COPY README.md /source/mqtt
COPY LICENSE /source/mqtt

COPY examples/ /source/mqtt/examples
COPY src/ /source/mqtt/src
COPY include/ /source/mqtt/include
COPY q/mqtt.q /q/

ENV QHOME /q
ENV PATH /q/l64:$PATH
ENV LD_LIBRARY_PATH /usr/local/lib:$LD_LIBRARY_PATH
ENV MQTT_INSTALL_DIR /source/paho.mqtt.c
ENV BUILD_HOME /source/paho.mqtt.c

RUN apk add --update && \
apk add build-base && \
apk add cmake && \
apk add make && \
apk add openssl-dev && \
apk add wget && \
apk add gcompat && \
apk add libnsl && \
cd /source && \

# MQTT Libs
/bin/sh /source/mqtt/build_libpaho.sh && \

# Clean up
apk del gcc && \
apk del cmake && \
apk del make && \
apk del wget && \
apk del build-base && \
rm -rf /source/mqtt_build.sh /source/paho.mqtt.c /source/v1.3.9* /source/mqtt/CmakeLists.txt

## Update this section here to add kdb+
#COPY q/k4.lic /q/
#COPY q/q.k /q/
#COPY q/l64/q /q/l64

## If running licensed version of kdb, you may also need taskset to start the process
# apk add util-linux

WORKDIR /source

ENTRYPOINT ["/bin/sh"]
File renamed without changes.
28 changes: 28 additions & 0 deletions docker_linux/build_libpaho.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh

cd /source

wget https://github.com/eclipse/paho.mqtt.c/archive/refs/tags/v1.3.9.tar.gz
tar xvf v1.3.9.tar.gz -C ./paho.mqtt.c --strip-components=1

cd paho.mqtt.c

# This library is not present in the Alpine image, removing it from the compiler args
sed -i 's/GAI_LIB = -lanl/#GAI_LIB = -lanl/g' Makefile
ln -s /usr/lib/libnsl.so.2 /usr/lib/libnsl.so.1

make
make install
mkdir -p include/lib
cd include/lib

ln -s /usr/local/lib/libpaho-mqtt3c.so libpaho-mqtt3c.a
ln -s /usr/local/lib/libpaho-mqtt3cs.so libpaho-mqtt3cs.a
ln -s /usr/local/lib/libpaho-mqtt3as.so libpaho-mqtt3as.a
ln -s /usr/local/lib/libpaho-mqtt3a.so libpaho-mqtt3a.a

mkdir /source/mqtt/cmake
cd /source/mqtt/cmake
cmake ..
make
make install
2 changes: 1 addition & 1 deletion docker_linux/mqtt_build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SETLOCAL
SET MQTT_SOURCE="C:\Users\guest\Development\mqtt"
SET QHOME_LINUX="C:\q"

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

ENDLOCAL

0 comments on commit e56d449

Please sign in to comment.