generated from home-assistant/addons-example
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathDockerfile
143 lines (131 loc) · 4.31 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
ARG BUILD_FROM
FROM $BUILD_FROM
# Build arguments
ARG BUILD_ARCH
# Versions
ENV HIVEMQ='b2043e7fcbd5897a3799869d42c6202122221fbc' \
LIBWEBSOCKETS='3.1.0' \
MOSQUITTO='2.0.10' \
MOSQUITTO_GO_AUTH='1.5.0' \
MOSQUTTO_DISCONNECT='0.0.1' \
GOVERSION=1.16.4
# Set shell
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
# Set workdir
WORKDIR /usr/src
# Install base dependencies
# hadolint ignore=DL3003
RUN apt-get update
RUN apt-get install --no-install-recommends -y gnupg gpg-agent \
&& apt-get --no-install-recommends install -y \
build-essential \
git \
cmake \
libssl-dev \
libffi-dev \
python3-dev \
dbus \
bash \
sqlite \
curl \
socat \
openssl \
python3 \
python3-setuptools \
python3-pip \
nginx \
software-properties-common \
xsltproc \
logrotate \
libglib2.0-0 \
libglib2.0-dev \
libdbus-1-dev \
&& pip3 install wheel
# Setup GO source # export GOARM=7 ;
RUN mkdir -p /tmp/go \
&& export GOOS=linux \
&& if [ "${BUILD_ARCH}" = "armhf" ]; then \
export GOBIN_GOARCH=armv6l ; \
export GOARCH=arm ; \
export GOARM=6 ; \
ln -s /lib/ld-linux.so.3 /lib/ld-linux-armhf.so.3 ; \
elif [ "${BUILD_ARCH}" = "armv7" ]; then \
export GOBIN_GOARCH=armv6l ; \
export GOARCH=arm ; \
export GOARM=7 ; \
elif [ "${BUILD_ARCH}" = "aarch64" ]; then \
export GOBIN_GOARCH=arm64 ; \
export GOARCH=arm64 ; \
elif [ "${BUILD_ARCH}" = "i386" ]; then \
export GOBIN_GOARCH=386 ; \
export GOARCH=386 ; \
elif [ "${BUILD_ARCH}" = "amd64" ]; then \
export GOBIN_GOARCH=amd64 ; \
export GOARCH=amd64 ; \
else \
echo 'NOT VALID BUILD'; exit 1; \
fi \
&& curl https://dl.google.com/go/go${GOVERSION}.${GOOS}-${GOBIN_GOARCH}.tar.gz --output /tmp/go/go.tar.gz \
&& tar -C /usr/local -xzf /tmp/go/go.tar.gz \
&& export PATH=$PATH:/usr/local/go/bin \
&& git clone --branch "v${LIBWEBSOCKETS}" --depth=1 https://github.com/warmcat/libwebsockets.git /tmp/libwebsockets \
&& mkdir -p /tmp/libwebsockets/build \
&& cd /tmp/libwebsockets/build \
&& cmake .. \
-DCMAKE_BUILD_TYPE=MinSizeRel \
-DCMAKE_INSTALL_PREFIX=/usr \
-DLWS_IPV6=OFF \
-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 \
&& make install \
&& git clone --branch "v${MOSQUITTO}" --depth=1 https://github.com/eclipse/mosquitto.git /tmp/mosquitto \
&& git clone --branch "v${MOSQUTTO_DISCONNECT}" --depth=1 https://github.com/albertogeniola/mosquitto-disconnections-plugin.git /tmp/mosquitto-disconnections-plugin \
&& mkdir -p /tmp/mosquitto/plugins/disconnections \
&& cp -R /tmp/mosquitto-disconnections-plugin/src/* /tmp/mosquitto/plugins/disconnections \
&& echo "add_subdirectory(disconnections)" >> /tmp/mosquitto/plugins/CMakeLists.txt \
&& cd /tmp/mosquitto \
&& cmake . \
-D WITH_ADNS=OFF \
-D WITH_DOCS=OFF \
-D WITH_MEMORY_TRACKING=OFF \
-D WITH_TLS_PSK=OFF \
-D WITH_WEBSOCKETS=ON \
-D WITH_CJSON=OFF \
-D WITH_CLIENTS=OFF \
-D WITH_BROKER=ON \
-D WITH_PLUGINS=ON \
-D DOCUMENTATION=OFF \
&& make install \
&& mkdir -p /usr/share/mosquitto \
&& cp /usr/local/lib/mosquitto_disconnections.so /usr/share/mosquitto/mosquitto_disconnections.so \
&& cd /tmp \
&& git clone --depth 1 --branch "${MOSQUITTO_GO_AUTH}" \
https://github.com/iegomez/mosquitto-go-auth.git \
&& export GOPROXY='direct' \
&& cd mosquitto-go-auth \
&& make CFLAGS="-I/usr/local/include -fPIC" LDFLAGS="-shared -Wl,-unresolved-symbols=ignore-all" \
&& cp /tmp/mosquitto-go-auth/pw /usr/share/mosquitto/pw \
&& cp /tmp/mosquitto-go-auth/go-auth.so /usr/share/mosquitto/go-auth.so \
&& chmod +x /usr/share/mosquitto/pw \
&& addgroup --system mosquitto \
&& adduser --system --no-create-home --disabled-login --group mosquitto \
&& apt-get clean \
&& rm -fr \
/etc/nginx \
/opt/mosquitto.conf \
/opt/acl \
/tmp/*
# Copy the requirements.txt file and install the listed packages
COPY rootfs/opt/custom_broker/requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
WORKDIR /
COPY rootfs /
COPY --chown=mosquitto:mosquitto --chmod=0755 rootfs/etc/mosquitto/certs /etc/mosquitto/
RUN mkdir -p /var/run/mdns/meross-mqtt && mkdir -p /var/run/mdns/meross-http-api
RUN chmod +x /usr/local/bin/*.sh