From 2b64afcf4735010bc84a3ac6c1d5516472648896 Mon Sep 17 00:00:00 2001 From: Ivan Dyachkov Date: Tue, 2 Jan 2024 11:17:57 +0100 Subject: [PATCH 1/2] feat: add update.sh --- update.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100755 update.sh diff --git a/update.sh b/update.sh new file mode 100755 index 0000000..bf27281 --- /dev/null +++ b/update.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +set -eou pipefail + +VERSION="$1" +VERSION_DIR=$(echo "$VERSION" | cut -d '.' -f 1,2 -) + +AMD64_SHA256=$(curl -sSL https://github.com/emqx/emqx/releases/download/v${VERSION}/emqx-${VERSION}-debian11-amd64.tar.gz.sha256) +ARM64_SHA256=$(curl -sSL https://github.com/emqx/emqx/releases/download/v${VERSION}/emqx-${VERSION}-debian11-arm64.tar.gz.sha256) + +sed -i'' -e "s/EMQX_VERSION=.*/EMQX_VERSION=${VERSION}/" $VERSION_DIR/Dockerfile +sed -i'' -e "s/AMD64_SHA256=.*/AMD64_SHA256=${AMD64_SHA256}/" $VERSION_DIR/Dockerfile +sed -i'' -e "s/ARM64_SHA256=.*/ARM64_SHA256=${ARM64_SHA256}/" $VERSION_DIR/Dockerfile From 8faec45560a606f8192d733939ca7577d405fa5d Mon Sep 17 00:00:00 2001 From: Ivan Dyachkov Date: Tue, 2 Jan 2024 11:17:43 +0100 Subject: [PATCH 2/2] feat: emqx 5.4.0 --- .github/workflows/main.yaml | 1 + 5.4/Dockerfile | 52 +++++++++++++++++++++++++++++++++++++ 5.4/docker-entrypoint.sh | 50 +++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 5.4/Dockerfile create mode 100755 5.4/docker-entrypoint.sh diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index baac21c..dd8254c 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -22,6 +22,7 @@ jobs: - '5.1' - '5.2' - '5.3' + - '5.4' steps: - uses: actions/checkout@v3 diff --git a/5.4/Dockerfile b/5.4/Dockerfile new file mode 100644 index 0000000..ea72cc0 --- /dev/null +++ b/5.4/Dockerfile @@ -0,0 +1,52 @@ +FROM debian:11-slim + +ENV EMQX_VERSION=5.4.0 +ENV AMD64_SHA256=5572dccf3704dbd910f145fe19882fa30fdd9132113d0a28110444d4d5685a3f +ENV ARM64_SHA256=0dbe92966a93054a8dca89762c00b06a44659c7921177feb291a5ddd5340cefc +ENV LC_ALL=C.UTF-8 LANG=C.UTF-8 + +RUN set -eu; \ + apt-get update; \ + apt-get install -y --no-install-recommends ca-certificates procps curl; \ + arch=$(dpkg --print-architecture); \ + if [ ${arch} = "amd64" ]; then sha256="$AMD64_SHA256"; fi; \ + if [ ${arch} = "arm64" ]; then sha256="$ARM64_SHA256"; fi; \ + ID="$(sed -n '/^ID=/p' /etc/os-release | sed -r 's/ID=(.*)/\1/g' | sed 's/\"//g')"; \ + VERSION_ID="$(sed -n '/^VERSION_ID=/p' /etc/os-release | sed -r 's/VERSION_ID=(.*)/\1/g' | sed 's/\"//g')"; \ + pkg="emqx-${EMQX_VERSION}-${ID}${VERSION_ID}-${arch}.tar.gz"; \ + curl -f -O -L https://www.emqx.com/en/downloads/broker/v${EMQX_VERSION}/${pkg}; \ + echo "$sha256 *$pkg" | sha256sum -c; \ + mkdir /opt/emqx; \ + tar zxf $pkg -C /opt/emqx; \ + find /opt/emqx -name 'swagger*.js.map' -exec rm {} +; \ + groupadd -r -g 1000 emqx; \ + useradd -r -m -u 1000 -g emqx emqx; \ + chgrp -Rf emqx /opt/emqx; \ + chmod -Rf g+w /opt/emqx; \ + chown -Rf emqx /opt/emqx; \ + ln -s /opt/emqx/bin/* /usr/local/bin/; \ + rm -f $pkg; \ + apt-get purge -y --auto-remove curl; \ + rm -rf /var/lib/apt/lists/* + +WORKDIR /opt/emqx + +USER emqx + +VOLUME ["/opt/emqx/log", "/opt/emqx/data"] + +# emqx will occupy these port: +# - 1883 port for MQTT +# - 8083 for WebSocket/HTTP +# - 8084 for WSS/HTTPS +# - 8883 port for MQTT(SSL) +# - 18083 for dashboard and API +# - 4370 default Erlang distribution port +# - 5369 for backplain gen_rpc +EXPOSE 1883 8083 8084 8883 18083 4370 5369 + +COPY docker-entrypoint.sh /usr/bin/ + +ENTRYPOINT ["/usr/bin/docker-entrypoint.sh"] + +CMD ["/opt/emqx/bin/emqx", "foreground"] diff --git a/5.4/docker-entrypoint.sh b/5.4/docker-entrypoint.sh new file mode 100755 index 0000000..8e96a6b --- /dev/null +++ b/5.4/docker-entrypoint.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +## Shell setting +if [[ -n "$DEBUG" ]]; then + set -ex +else + set -e +fi + +shopt -s nullglob + +## Local IP address setting + +LOCAL_IP=$(hostname -i | grep -oE '((25[0-5]|(2[0-4]|1[0-9]|[1-9]|)[0-9])\.){3}(25[0-5]|(2[0-4]|1[0-9]|[1-9]|)[0-9])' | head -n 1) + +export EMQX_NAME="${EMQX_NAME:-emqx}" + +if [[ -z "$EMQX_HOST" ]]; then + if [[ "$EMQX_CLUSTER__DISCOVERY_STRATEGY" == "dns" ]] && \ + [[ "$EMQX_CLUSTER__DNS__RECORD_TYPE" == "srv" ]] && \ + grep -q "$(hostname).$EMQX_CLUSTER__DNS__NAME" /etc/hosts; then + EMQX_HOST="$(hostname).$EMQX_CLUSTER__DNS__NAME" + elif [[ "$EMQX_CLUSTER__DISCOVERY_STRATEGY" == "k8s" ]] && \ + [[ "$EMQX_CLUSTER__K8S__ADDRESS_TYPE" == "dns" ]] && \ + [[ -n "$EMQX_CLUSTER__K8S__NAMESPACE" ]]; then + EMQX_CLUSTER__K8S__SUFFIX=${EMQX_CLUSTER__K8S__SUFFIX:-"pod.cluster.local"} + EMQX_HOST="${LOCAL_IP//./-}.$EMQX_CLUSTER__K8S__NAMESPACE.$EMQX_CLUSTER__K8S__SUFFIX" + elif [[ "$EMQX_CLUSTER__DISCOVERY_STRATEGY" == "k8s" ]] && \ + [[ "$EMQX_CLUSTER__K8S__ADDRESS_TYPE" == 'hostname' ]] && \ + [[ -n "$EMQX_CLUSTER__K8S__NAMESPACE" ]]; then + EMQX_CLUSTER__K8S__SUFFIX=${EMQX_CLUSTER__K8S__SUFFIX:-'svc.cluster.local'} + EMQX_HOST=$(grep -h "^$LOCAL_IP" /etc/hosts | grep -o "$(hostname).*.$EMQX_CLUSTER__K8S__NAMESPACE.$EMQX_CLUSTER__K8S__SUFFIX") + else + EMQX_HOST="$LOCAL_IP" + fi + export EMQX_HOST +fi + +if [[ -z "$EMQX_NODE_NAME" ]]; then + export EMQX_NODE_NAME="$EMQX_NAME@$EMQX_HOST" +fi + +# The default rpc port discovery 'stateless' is mostly for clusters +# having static node names. So it's troulbe-free for multiple emqx nodes +# running on the same host. +# When start emqx in docker, it's mostly one emqx node in one container +# i.e. use port 5369 (or per tcp_server_port | ssl_server_port config) for gen_rpc +export EMQX_RPC__PORT_DISCOVERY="${EMQX_RPC__PORT_DISCOVERY:-manual}" + +exec "$@"