diff --git a/Dockerfile.ubuntu20.04.runner b/Dockerfile.ubuntu20.04.runner new file mode 100644 index 000000000..124021c89 --- /dev/null +++ b/Dockerfile.ubuntu20.04.runner @@ -0,0 +1,42 @@ +## This is a fast-build Dockerfile only for testing +FROM ubuntu:20.04 +ARG PROFILE=emqx + +RUN apt-get update; \ + apt-get install -y --no-install-recommends ca-certificates procps; \ + rm -rf /var/lib/apt/lists/* + +RUN mkdir /opt/emqx +RUN date > /opt/emqx/BUILD_TIME +COPY _build/${PROFILE}/rel/emqx /opt/emqx +RUN ln -s /opt/emqx/bin/* /usr/local/bin/ +COPY deploy/docker/docker-entrypoint.sh /usr/bin/ + +WORKDIR /opt/emqx + + +RUN 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 + +USER emqx + +VOLUME ["/opt/emqx/log", "/opt/emqx/data"] + +# emqx will occupy these port: +# - 1883 port for MQTT +# - 8081 for mgmt API +# - 8083 for WebSocket/HTTP +# - 8084 for WSS/HTTPS +# - 8883 port for MQTT(SSL) +# - 11883 port for internal MQTT/TCP +# - 18083 for dashboard +# - 4370 default Erlang distrbution port +# - 5369 for backplain gen_rpc +EXPOSE 1883 8081 8083 8084 8883 11883 18083 4370 5369 + +ENTRYPOINT ["/usr/bin/docker-entrypoint.sh"] + +CMD ["/opt/emqx/bin/emqx", "foreground"] diff --git a/Dockerfile.ubuntu20.04.runner.dockerignore b/Dockerfile.ubuntu20.04.runner.dockerignore new file mode 100644 index 000000000..bf291d51e --- /dev/null +++ b/Dockerfile.ubuntu20.04.runner.dockerignore @@ -0,0 +1,4 @@ +* +!_build/emqx +!_build/emqx-enterprise +!deploy diff --git a/scripts/make-docker-image-from-host-build.sh b/scripts/make-docker-image-from-host-build.sh new file mode 100755 index 000000000..8911ed251 --- /dev/null +++ b/scripts/make-docker-image-from-host-build.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +set -euo pipefail +set -x + +PROFILE="$1" +COMPILE="${2:-no}" +DISTRO="$(./scripts/get-distro.sh)" +PKG_VSN="${PKG_VSN:-$(./pkg-vsn.sh "$PROFILE")}" + +case "$DISTRO" in + ubuntu20*) + EMQX_DOCKERFILE="Dockerfile.ubuntu20.04.runner" + ;; + *) + echo "sorry, no support for $DISTRO yet" + exit 1 +esac + +if [ "$COMPILE" = '--compile' ]; then + make "$PROFILE" + sync +fi + +export DOCKER_BUILDKIT=1 +docker build --build-arg PROFILE="${PROFILE}" \ + -t "emqx/emqx:${PKG_VSN}-${DISTRO}" \ + -f "$EMQX_DOCKERFILE" . diff --git a/scripts/start-two-nodes-in-docker.sh b/scripts/start-two-nodes-in-docker.sh index ec3989934..64a6647ce 100755 --- a/scripts/start-two-nodes-in-docker.sh +++ b/scripts/start-two-nodes-in-docker.sh @@ -2,14 +2,6 @@ set -euo pipefail -## This script takes the first argument as docker image name, -## starts two containers running with the built code mount -## into docker containers. -## -## NOTE: containers are not instructed to rebuild emqx, -## Please use a docker image which is compatible with -## the docker host. -## ## EMQX can only start with longname (https://erlang.org/doc/reference_manual/distributed.html) ## The host name part of EMQX's node name has to be static, this means we should either ## pre-assign static IP for containers, or ensure containers can communiate with each other by name @@ -19,7 +11,6 @@ set -euo pipefail cd -P -- "$(dirname -- "$0")/.." IMAGE="${1}" -PROJ_DIR="$(pwd)" NET='emqx.io' NODE1="node1.$NET" @@ -35,23 +26,23 @@ docker network create "$NET" docker run -d -t --restart=always --name "$NODE1" \ --net "$NET" \ + -e EMQX_LOG__CONSOLE_HANDLER__LEVEL=debug \ -e EMQX_NODE_NAME="emqx@$NODE1" \ -e EMQX_NODE_COOKIE="$COOKIE" \ -p 18083:18083 \ - -v "$PROJ_DIR"/_build/emqx/rel/emqx:/built \ - "$IMAGE" sh -c 'cp -r /built /emqx && /emqx/bin/emqx console' + "$IMAGE" docker run -d -t --restart=always --name "$NODE2" \ --net "$NET" \ + -e EMQX_LOG__CONSOLE_HANDLER__LEVEL=debug \ -e EMQX_NODE_NAME="emqx@$NODE2" \ -e EMQX_NODE_COOKIE="$COOKIE" \ -p 18084:18083 \ - -v "$PROJ_DIR"/_build/emqx/rel/emqx:/built \ - "$IMAGE" sh -c 'cp -r /built /emqx && /emqx/bin/emqx console' + "$IMAGE" wait (){ container="$1" - while ! docker exec "$container" /emqx/bin/emqx_ctl status >/dev/null 2>&1; do + while ! docker exec "$container" emqx_ctl status >/dev/null 2>&1; do echo -n '.' sleep 1 done @@ -61,4 +52,4 @@ wait $NODE1 wait $NODE2 echo -docker exec $NODE1 /emqx/bin/emqx_ctl cluster join "emqx@$NODE2" +docker exec $NODE1 emqx_ctl cluster join "emqx@$NODE2"