Skip to content

Commit

Permalink
Add gRPC options to set timeout and skip dial errors (#193)
Browse files Browse the repository at this point in the history
* Don't bubble up grpc client error, just keep it nil and derive it again on checking.

Add option to check if we should faild on gRCP dial error or not.

Add timeout option.

* Instead of attempting on each check, remove with block when fail on dial error is not set to true so gRPC takes care of the connection itself.
Add tests to check that auth fails with dial errors, but works once the service is back up.

* Fix docker files missing libwebsockets8 by building from source, fix docker test run by starting maridb service instead of mysql one.

Co-authored-by: Ignacio Gómez <[email protected]>
  • Loading branch information
iegomez and Ignacio Gómez committed Sep 15, 2021
1 parent 5dc063f commit 290c1c5
Show file tree
Hide file tree
Showing 7 changed files with 225 additions and 92 deletions.
33 changes: 29 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ RUN if [ "$(echo $MOSQUITTO_VERSION | head -c 1)" != 2 ]; then \
make -j "$(nproc)" && \
rm -rf /root/.cmake ; \
fi

WORKDIR /app

RUN mkdir -p mosquitto/auth mosquitto/conf.d
Expand Down Expand Up @@ -60,7 +60,7 @@ ARG BUILDPLATFORM

# Install TARGETPLATFORM parser to translate its value to GOOS, GOARCH, and GOARM
COPY --from=tonistiigi/xx:golang / /
RUN go env
RUN go env

# Install needed libc and gcc for target platform.
RUN if [ ! -z "$TARGETPLATFORM" ]; then \
Expand Down Expand Up @@ -89,9 +89,34 @@ RUN go build -buildmode=c-archive go-auth.go && \
#Start from a new image.
FROM debian:stable-slim

RUN apt update && apt install -y libwebsockets8 libc-ares2 openssl uuid tini
RUN apt update && apt install -y libc-ares2 openssl uuid tini

# Get libwebsocket. Debian's libwebsockets is too old for Mosquitto version > 2.x so it gets built from source.
RUN if [ "$(echo $MOSQUITTO_VERSION | head -c 1)" != 2 ]; then \
apt install -y libwebsockets-dev ; \
else \
export LWS_VERSION=2.4.2 && \
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 ; \
fi

RUN mkdir -p /var/lib/mosquitto /var/log/mosquitto
RUN mkdir -p /var/lib/mosquitto /var/log/mosquitto
RUN groupadd mosquitto \
&& useradd -s /sbin/nologin mosquitto -g mosquitto -d /var/lib/mosquitto \
&& chown -R mosquitto:mosquitto /var/log/mosquitto/ \
Expand Down
29 changes: 27 additions & 2 deletions Dockerfile.runtest
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,36 @@ ENV GO_VERSION=1.13.8
WORKDIR /app

#Get mosquitto build dependencies.
RUN apt-get update && apt-get install -y libwebsockets8 libwebsockets-dev libc-ares2 libc-ares-dev openssl uuid uuid-dev wget build-essential git
RUN apt-get update && apt-get install -y libc-ares2 libc-ares-dev openssl uuid uuid-dev wget build-essential git

RUN if [ "$(echo $MOSQUITTO_VERSION | head -c 1)" != 2 ]; then \
apt install -y libwebsockets-dev ; \
else \
export LWS_VERSION=2.4.2 && \
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 ; \
fi

RUN mkdir -p mosquitto/auth mosquitto/conf.d

RUN wget http:https://mosquitto.org/files/source/mosquitto-${MOSQUITTO_VERSION}.tar.gz
RUN tar xzvf mosquitto-${MOSQUITTO_VERSION}.tar.gz && rm mosquitto-${MOSQUITTO_VERSION}.tar.gz
RUN tar xzvf mosquitto-${MOSQUITTO_VERSION}.tar.gz && rm mosquitto-${MOSQUITTO_VERSION}.tar.gz

#Build mosquitto.
RUN cd mosquitto-${MOSQUITTO_VERSION} && make WITH_WEBSOCKETS=yes && make install && cd ..
Expand Down

0 comments on commit 290c1c5

Please sign in to comment.