Skip to content

Commit

Permalink
Merge pull request #46 from emqx/0918-emqx-5.2
Browse files Browse the repository at this point in the history
feat: emqx 5.2
  • Loading branch information
id authored Sep 18, 2023
2 parents dfa1507 + 4ee94cd commit 6e4c675
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 22 deletions.
23 changes: 1 addition & 22 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ jobs:
strategy:
matrix:
version:
- '4.4'
- '5.0'
- '5.1'
- '5.2'

steps:
- uses: actions/checkout@v3
Expand All @@ -42,27 +42,6 @@ jobs:
file: ${{ matrix.version }}/Dockerfile
context: ${{ matrix.version }}
- name: Check image
if: matrix.version == '4.4'
timeout-minutes: 1
run: |
docker pull ghcr.io/${{ github.repository }}:${{ matrix.version }}
docker run -d -p 8081:8081 --name emqx ghcr.io/${{ github.repository }}:${{ matrix.version }}
while ! curl -fs 127.0.0.1:8081/status > /dev/null; do
echo "waiting for emqx"
sleep 1
done
if ! docker exec -i emqx emqx ping; then
echo "emqx command not working"
exit 1
fi
if ! docker exec -i emqx emqx_ctl status; then
echo "emqx_ctl command not working"
exit 1
fi
echo "================================================================"
echo "emqx is running"
- name: Check image
if: matrix.version != '4.4'
timeout-minutes: 1
run: |
docker pull ghcr.io/${{ github.repository }}:${{ matrix.version }}
Expand Down
56 changes: 56 additions & 0 deletions 5.2/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
FROM debian:11-slim

RUN set -eu; \
apt-get update; \
apt-get install -y --no-install-recommends curl ca-certificates procps; \
rm -rf /var/lib/apt/lists/*

RUN groupadd -r -g 1000 emqx; \
useradd -r -m -u 1000 -g emqx emqx;

ENV EMQX_VERSION=5.2.0-build.1
ENV AMD64_SHA256=4a67fa3e3b28629d9e4739182059e6f7700523309922534af0308f4801cdc2e8
ENV ARM64_SHA256=b4991f1f7d44963ad7ff0fd65234f9ae39298ea43d9fa8b009035d649e4c17d2
ENV LC_ALL=C.UTF-8 LANG=C.UTF-8

RUN set -eu; \
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 {} +; \
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

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)
# - 11883 port for internal MQTT/TCP
# - 18083 for dashboard and API
# - 4370 default Erlang distribution port
# - 5369 for backplain gen_rpc
EXPOSE 1883 8083 8084 8883 11883 18083 4370 5369

COPY docker-entrypoint.sh /usr/bin/

ENTRYPOINT ["/usr/bin/docker-entrypoint.sh"]

CMD ["/opt/emqx/bin/emqx", "foreground"]
50 changes: 50 additions & 0 deletions 5.2/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"

0 comments on commit 6e4c675

Please sign in to comment.