mirror of
https://github.com/eclipse/mosquitto.git
synced 2025-05-08 16:52:13 +08:00
Make target for building a docker image based on working dir files.
This commit is contained in:
parent
995f90dbaf
commit
9470cd8c68
2
.gitignore
vendored
2
.gitignore
vendored
@ -25,6 +25,8 @@ cov-int/
|
||||
|
||||
dist/
|
||||
|
||||
docker/local/mosq.tar.gz
|
||||
|
||||
examples/mysql_log/mosquitto_mysql_log
|
||||
examples/temperature_conversion/mqtt_temperature_conversion
|
||||
|
||||
|
55
Makefile
55
Makefile
@ -3,8 +3,41 @@ include config.mk
|
||||
DIRS=lib client src
|
||||
DOCDIRS=man
|
||||
DISTDIRS=man
|
||||
DISTFILES= \
|
||||
client/ \
|
||||
examples/ \
|
||||
installer/ \
|
||||
lib/ \
|
||||
logo/ \
|
||||
man/ \
|
||||
misc/ \
|
||||
security/ \
|
||||
service/ \
|
||||
src/ \
|
||||
test/ \
|
||||
\
|
||||
CMakeLists.txt \
|
||||
CONTRIBUTING.md \
|
||||
ChangeLog.txt \
|
||||
LICENSE.txt \
|
||||
Makefile \
|
||||
about.html \
|
||||
aclfile.example \
|
||||
compiling.txt \
|
||||
config.h \
|
||||
config.mk \
|
||||
edl-v10 \
|
||||
epl-v10 \
|
||||
libmosquitto.pc.in \
|
||||
libmosquittopp.pc.in \
|
||||
mosquitto.conf \
|
||||
notice.html \
|
||||
pskfile.example \
|
||||
pwfile.example \
|
||||
readme-windows.txt \
|
||||
readme.md
|
||||
|
||||
.PHONY : all mosquitto api docs binary check clean reallyclean test install uninstall dist sign copy
|
||||
.PHONY : all mosquitto api docs binary check clean reallyclean test install uninstall dist sign copy localdocker
|
||||
|
||||
all : $(MAKE_ALL)
|
||||
|
||||
@ -69,14 +102,8 @@ dist : reallyclean
|
||||
set -e; for d in ${DISTDIRS}; do $(MAKE) -C $${d} dist; done
|
||||
|
||||
mkdir -p dist/mosquitto-${VERSION}
|
||||
cp -r client examples installer lib logo man misc security service src test about.html aclfile.example ChangeLog.txt CMakeLists.txt compiling.txt config.h config.mk CONTRIBUTING.md edl-v10 epl-v10 libmosquitto.pc.in libmosquittopp.pc.in LICENSE.txt Makefile mosquitto.conf notice.html pskfile.example pwfile.example readme.md readme-windows.txt dist/mosquitto-${VERSION}/
|
||||
cp -r ${DISTFILES} dist/mosquitto-${VERSION}/
|
||||
cd dist; tar -zcf mosquitto-${VERSION}.tar.gz mosquitto-${VERSION}/
|
||||
set -e; for m in man/*.xml; \
|
||||
do \
|
||||
hfile=$$(echo $${m} | sed -e 's#man/\(.*\)\.xml#\1#' | sed -e 's/\./-/g'); \
|
||||
$(XSLTPROC) $(DB_HTML_XSL) $${m} > dist/$${hfile}.html; \
|
||||
done
|
||||
|
||||
|
||||
sign : dist
|
||||
cd dist; gpg --detach-sign -a mosquitto-${VERSION}.tar.gz
|
||||
@ -89,3 +116,15 @@ copy : sign
|
||||
coverage :
|
||||
lcov --capture --directory . --output-file coverage.info
|
||||
genhtml coverage.info --output-directory out
|
||||
|
||||
localdocker : reallyclean
|
||||
set -e; for d in ${DISTDIRS}; do $(MAKE) -C $${d} dist; done
|
||||
|
||||
rm -rf dockertmp/
|
||||
mkdir -p dockertmp/mosquitto-${VERSION}
|
||||
cp -r ${DISTFILES} dockertmp/mosquitto-${VERSION}/
|
||||
cd dockertmp/; tar -zcf mosq.tar.gz mosquitto-${VERSION}/
|
||||
cp dockertmp/mosq.tar.gz docker/local
|
||||
rm -rf dockertmp/
|
||||
cd docker/local && docker build .
|
||||
|
||||
|
@ -17,3 +17,5 @@ docker build -t eclipse-mosquitto:1.5.1 --build-arg VERSION="1.5.1" .
|
||||
docker run --rm -it eclipse-mosquitto:1.5.1
|
||||
```
|
||||
|
||||
The `local` directory can be used to build an image based on the files in the
|
||||
working directory by using `make localdocker` from the root of the repository.
|
||||
|
71
docker/local/Dockerfile
Normal file
71
docker/local/Dockerfile
Normal file
@ -0,0 +1,71 @@
|
||||
FROM alpine:3.8
|
||||
|
||||
LABEL maintainer="Roger Light <roger@atchoo.org>" \
|
||||
description="Eclipse Mosquitto MQTT Broker"
|
||||
|
||||
ENV LWS_VERSION=2.4.2
|
||||
|
||||
COPY mosq.tar.gz /tmp
|
||||
|
||||
RUN set -x && \
|
||||
apk --no-cache add --virtual build-deps \
|
||||
build-base \
|
||||
cmake \
|
||||
gnupg \
|
||||
libressl-dev \
|
||||
util-linux-dev && \
|
||||
wget https://github.com/warmcat/libwebsockets/archive/v${LWS_VERSION}.tar.gz -O /tmp/lws.tar.gz && \
|
||||
mkdir -p /build/lws && \
|
||||
tar --strip=1 -xf /tmp/lws.tar.gz -C /build/lws && \
|
||||
rm /tmp/lws.tar.gz && \
|
||||
cd /build/lws && \
|
||||
cmake . \
|
||||
-DCMAKE_BUILD_TYPE=MinSizeRel \
|
||||
-DCMAKE_INSTALL_PREFIX=/usr \
|
||||
-DLWS_IPV6=ON \
|
||||
-DLWS_WITHOUT_BUILTIN_GETIFADDRS=ON \
|
||||
-DLWS_WITHOUT_CLIENT=ON \
|
||||
-DLWS_WITHOUT_EXTENSIONS=ON \
|
||||
-DLWS_WITHOUT_TESTAPPS=ON \
|
||||
-DLWS_WITH_SHARED=OFF \
|
||||
-DLWS_WITH_ZIP_FOPS=OFF \
|
||||
-DLWS_WITH_ZLIB=OFF && \
|
||||
make -j "$(nproc)" && \
|
||||
rm -rf /root/.cmake && \
|
||||
mkdir -p /build/mosq && \
|
||||
tar --strip=1 -xf /tmp/mosq.tar.gz -C /build/mosq && \
|
||||
rm /tmp/mosq.tar.gz && \
|
||||
make -C /build/mosq -j "$(nproc)" \
|
||||
CFLAGS="-Wall -O2 -I/build/lws/include" \
|
||||
LDFLAGS="-L/build/lws/lib" \
|
||||
WITH_ADNS=no \
|
||||
WITH_DOCS=no \
|
||||
WITH_MEMORY_TRACKING=yes \
|
||||
WITH_SHARED_LIBRARIES=yes \
|
||||
WITH_SRV=no \
|
||||
WITH_STRIP=yes \
|
||||
WITH_TLS_PSK=no \
|
||||
WITH_WEBSOCKETS=yes \
|
||||
prefix=/usr \
|
||||
binary && \
|
||||
addgroup -S -g 1883 mosquitto 2>/dev/null && \
|
||||
adduser -S -u 1883 -D -H -h /var/empty -s /sbin/nologin -G mosquitto -g mosquitto mosquitto 2>/dev/null && \
|
||||
mkdir -p /mosquitto/config /mosquitto/data /mosquitto/log && \
|
||||
install -d /usr/sbin/ && \
|
||||
install -s -m755 /build/mosq/client/mosquitto_pub /usr/bin/mosquitto_pub && \
|
||||
install -s -m755 /build/mosq/client/mosquitto_rr /usr/bin/mosquitto_rr && \
|
||||
install -s -m755 /build/mosq/client/mosquitto_sub /usr/bin/mosquitto_sub && \
|
||||
install -s -m644 /build/mosq/lib/libmosquitto.so.1 /usr/lib/libmosquitto.so.1 && \
|
||||
install -s -m755 /build/mosq/src/mosquitto /usr/sbin/mosquitto && \
|
||||
install -s -m755 /build/mosq/src/mosquitto_passwd /usr/bin/mosquitto_passwd && \
|
||||
install -m644 /build/mosq/mosquitto.conf /mosquitto/config/mosquitto.conf && \
|
||||
chown -R mosquitto:mosquitto /mosquitto && \
|
||||
apk del build-deps && \
|
||||
rm -rf /build
|
||||
|
||||
VOLUME ["/mosquitto/data", "/mosquitto/log"]
|
||||
|
||||
# Set up the entry point script and default command
|
||||
COPY docker-entrypoint.sh /
|
||||
ENTRYPOINT ["/docker-entrypoint.sh"]
|
||||
CMD ["/usr/sbin/mosquitto", "-c", "/mosquitto/config/mosquitto.conf"]
|
51
docker/local/README.md
Normal file
51
docker/local/README.md
Normal file
@ -0,0 +1,51 @@
|
||||
# Eclipse Mosquitto Docker Image
|
||||
Containers built with this Dockerfile build from a source tarball "mosq.tar.gz"
|
||||
placed in the local directory. Running `make localdocker` from the root of the
|
||||
repository will generate the source tar and build the docker image.
|
||||
|
||||
## Mount Points
|
||||
A docker mount point has been created in the image to be used for configuration.
|
||||
```
|
||||
/mosquitto/config
|
||||
```
|
||||
|
||||
Two docker volumes have been created in the image to be used for persistent storage and logs.
|
||||
```
|
||||
/mosquitto/data
|
||||
/mosquitto/log
|
||||
```
|
||||
|
||||
## User/Group
|
||||
|
||||
The image runs mosqutto under the mosquitto user and group, which are created
|
||||
with a uid and gid of 1883.
|
||||
|
||||
## Configuration
|
||||
When creating a container from the image, the default configuration values are used.
|
||||
To use a custom configuration file, mount a **local** configuration file to `/mosquitto/config/mosquitto.conf`
|
||||
```
|
||||
docker run -it -p 1883:1883 -v <absolute-path-to-configuration-file>:/mosquitto/config/mosquitto.conf eclipse-mosquitto:<version>
|
||||
```
|
||||
|
||||
:boom: if the mosquitto configuration (mosquitto.conf) was modified
|
||||
to use non-default ports, the docker run command will need to be updated
|
||||
to expose the ports that have been configured, for example:
|
||||
|
||||
```
|
||||
docker run -it -p 1883:1883 -p 9001:9001 -v <absolute-path-to-configuration-file>:/mosquitto/config/mosquitto.conf eclipse-mosquitto:<version>
|
||||
```
|
||||
|
||||
Configuration can be changed to:
|
||||
|
||||
* persist data to `/mosquitto/data`
|
||||
* log to `/mosquitto/log/mosquitto.log`
|
||||
|
||||
i.e. add the following to `mosquitto.conf`:
|
||||
```
|
||||
persistence true
|
||||
persistence_location /mosquitto/data/
|
||||
|
||||
log_dest file /mosquitto/log/mosquitto.log
|
||||
```
|
||||
|
||||
**Note**: For any volume used, the data will be persistent between containers.
|
4
docker/local/docker-entrypoint.sh
Executable file
4
docker/local/docker-entrypoint.sh
Executable file
@ -0,0 +1,4 @@
|
||||
#!/bin/ash
|
||||
set -e
|
||||
|
||||
exec "$@"
|
Loading…
x
Reference in New Issue
Block a user