|
| 1 | +# Alpine Linux is not officially supported by the RabbitMQ team -- use at your own risk! |
1 | 2 | FROM alpine:3.8
|
2 | 3 |
|
3 |
| -# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added |
4 |
| -RUN addgroup -S rabbitmq && adduser -S -h /var/lib/rabbitmq -G rabbitmq rabbitmq |
5 |
| - |
6 | 4 | # grab su-exec for easy step-down from root
|
7 |
| -RUN apk add --no-cache 'su-exec>=0.2' |
| 5 | +# bash for docker-entrypoint.sh |
| 6 | +RUN apk add --no-cache 'su-exec>=0.2' bash |
| 7 | + |
| 8 | +# Default to a PGP keyserver that pgp-happy-eyeballs recognizes, but allow for substitutions locally |
| 9 | +ARG PGP_KEYSERVER=ha.pool.sks-keyservers.net |
| 10 | +# If you are building this image locally and are getting `gpg: keyserver receive failed: No data` errors, |
| 11 | +# run the build with a different PGP_KEYSERVER, e.g. docker build --tag rabbitmq:3.7 --build-arg PGP_KEYSERVER=pgpkeys.eu 3.7/ubuntu |
| 12 | +# For context, see https://github.com/docker-library/official-images/issues/4252 |
8 | 13 |
|
9 |
| -RUN apk add --no-cache \ |
10 |
| -# Bash for docker-entrypoint |
11 |
| - bash \ |
12 |
| -# Procps for rabbitmqctl |
13 |
| - procps \ |
14 |
| -# Erlang for RabbitMQ |
15 |
| - erlang-asn1 \ |
16 |
| - erlang-hipe \ |
17 |
| - erlang-crypto \ |
18 |
| - erlang-eldap \ |
19 |
| - erlang-inets \ |
20 |
| - erlang-mnesia \ |
21 |
| - erlang \ |
22 |
| - erlang-os-mon \ |
23 |
| - erlang-public-key \ |
24 |
| - erlang-sasl \ |
25 |
| - erlang-ssl \ |
26 |
| - erlang-syntax-tools \ |
27 |
| - erlang-xmerl |
| 14 | +# Using the latest OpenSSL LTS release, with support until September 2023 - https://www.openssl.org/source/ |
| 15 | +ENV OPENSSL_VERSION="1.1.1a" |
| 16 | +ENV OPENSSL_SOURCE_SHA256="fc20130f8b7cbd2fb918b2f14e2f429e109c31ddd0fb38fc5d71d9ffed3f9f41" |
| 17 | +# https://www.openssl.org/community/omc.html |
| 18 | +ENV OPENSSL_PGP_KEY_ID="0x8657ABB260F056B1E5190839D9C4D26D0E604491" |
28 | 19 |
|
29 |
| -# get logs to stdout (thanks @dumbbell for pushing this upstream! :D) |
30 |
| -ENV RABBITMQ_LOGS=- RABBITMQ_SASL_LOGS=- |
31 |
| -# https://github.com/rabbitmq/rabbitmq-server/commit/53af45bf9a162dec849407d114041aad3d84feaf |
| 20 | +# Use the latest stable Erlang/OTP release (https://github.com/erlang/otp/tags) |
| 21 | +ENV OTP_VERSION="21.2.3" |
| 22 | +# TODO add PGP checking when the feature will be added to Erlang/OTP's build system |
| 23 | +# http://erlang.org/pipermail/erlang-questions/2019-January/097067.html |
| 24 | +ENV OTP_SOURCE_SHA256="109a5722e398bdcd3aeb4f4833cde90bf441a9c014006439643aab550a770923" |
| 25 | + |
| 26 | +# Install dependencies required to build Erlang/OTP from source |
| 27 | +# http://erlang.org/doc/installation_guide/INSTALL.html |
| 28 | +# autoconf: Required to configure Erlang/OTP before compiling |
| 29 | +# dpkg-dev: Required to set up host & build type when compiling Erlang/OTP |
| 30 | +# gnupg: Required to verify OpenSSL artefacts |
| 31 | +# libncurses5-dev: Required for Erlang/OTP new shell & observer_cli - https://github.com/zhongwencool/observer_cli |
| 32 | +# m4: Required for Erlang/OTP HiPE support |
| 33 | +RUN set -eux; \ |
| 34 | + \ |
| 35 | + apk add --no-cache --virtual .build-deps \ |
| 36 | + autoconf \ |
| 37 | + ca-certificates \ |
| 38 | + dpkg-dev dpkg \ |
| 39 | + gcc \ |
| 40 | + gnupg \ |
| 41 | + libc-dev \ |
| 42 | + linux-headers \ |
| 43 | + m4 \ |
| 44 | + make \ |
| 45 | + ncurses-dev \ |
| 46 | + wget \ |
| 47 | + ; \ |
| 48 | + \ |
| 49 | + OPENSSL_SOURCE_URL="https://www.openssl.org/source/openssl-$OPENSSL_VERSION.tar.gz"; \ |
| 50 | + OPENSSL_PATH="/usr/local/src/openssl-$OPENSSL_VERSION"; \ |
| 51 | + OPENSSL_CONFIG_DIR=/usr/local/etc/ssl; \ |
| 52 | + \ |
| 53 | +# /usr/local/src doesn't exist in Alpine by default |
| 54 | + mkdir /usr/local/src; \ |
| 55 | + \ |
| 56 | +# Required by the crypto & ssl Erlang/OTP applications |
| 57 | + wget --progress dot:giga --output-document "$OPENSSL_PATH.tar.gz.asc" "$OPENSSL_SOURCE_URL.asc"; \ |
| 58 | + wget --progress dot:giga --output-document "$OPENSSL_PATH.tar.gz" "$OPENSSL_SOURCE_URL"; \ |
| 59 | + export GNUPGHOME="$(mktemp -d)"; \ |
| 60 | + gpg --batch --keyserver "$PGP_KEYSERVER" --recv-keys "$OPENSSL_PGP_KEY_ID"; \ |
| 61 | + gpg --batch --verify "$OPENSSL_PATH.tar.gz.asc" "$OPENSSL_PATH.tar.gz"; \ |
| 62 | + gpgconf --kill all; \ |
| 63 | + rm -rf "$GNUPGHOME"; \ |
| 64 | + echo "$OPENSSL_SOURCE_SHA256 *$OPENSSL_PATH.tar.gz" | sha256sum -c -; \ |
| 65 | + mkdir -p "$OPENSSL_PATH"; \ |
| 66 | + tar --extract --file "$OPENSSL_PATH.tar.gz" --directory "$OPENSSL_PATH" --strip-components 1; \ |
| 67 | + \ |
| 68 | +# Configure OpenSSL for compilation |
| 69 | + cd "$OPENSSL_PATH"; \ |
| 70 | + ./config --openssldir="$OPENSSL_CONFIG_DIR"; \ |
| 71 | +# Compile, install OpenSSL, verify that the command-line works & development headers are present |
| 72 | + make -j "$(getconf _NPROCESSORS_ONLN)"; \ |
| 73 | + make install_sw install_ssldirs; \ |
| 74 | + cd ..; \ |
| 75 | + rm -rf "$OPENSSL_PATH"*; \ |
| 76 | +# use Alpine's CA certificates |
| 77 | + rmdir "$OPENSSL_CONFIG_DIR/certs" "$OPENSSL_CONFIG_DIR/private"; \ |
| 78 | + ln -sf /etc/ssl/certs /etc/ssl/private "$OPENSSL_CONFIG_DIR"; \ |
| 79 | +# smoke test |
| 80 | + openssl version; \ |
| 81 | + \ |
| 82 | + OTP_SOURCE_URL="https://github.com/erlang/otp/archive/OTP-$OTP_VERSION.tar.gz"; \ |
| 83 | + OTP_PATH="/usr/local/src/otp-$OTP_VERSION"; \ |
| 84 | + \ |
| 85 | +# Download, verify & extract OTP_SOURCE |
| 86 | + mkdir -p "$OTP_PATH"; \ |
| 87 | + wget --progress dot:giga --output-document "$OTP_PATH.tar.gz" "$OTP_SOURCE_URL"; \ |
| 88 | + echo "$OTP_SOURCE_SHA256 *$OTP_PATH.tar.gz" | sha256sum -c -; \ |
| 89 | + tar --extract --file "$OTP_PATH.tar.gz" --directory "$OTP_PATH" --strip-components 1; \ |
| 90 | + \ |
| 91 | +# Configure Erlang/OTP for compilation, disable unused features & applications |
| 92 | +# http://erlang.org/doc/applications.html |
| 93 | +# ERL_TOP is required for Erlang/OTP makefiles to find the absolute path for the installation |
| 94 | + cd "$OTP_PATH"; \ |
| 95 | + export ERL_TOP="$OTP_PATH"; \ |
| 96 | + ./otp_build autoconf; \ |
| 97 | + CFLAGS="$(dpkg-buildflags --get CFLAGS)"; export CFLAGS; \ |
| 98 | + hostArch="$(dpkg-architecture --query DEB_HOST_GNU_TYPE)"; \ |
| 99 | + buildArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \ |
| 100 | + ./configure \ |
| 101 | + --host="$hostArch" \ |
| 102 | + --build="$buildArch" \ |
| 103 | + --disable-dynamic-ssl-lib \ |
| 104 | + --disable-sctp \ |
| 105 | + --disable-silent-rules \ |
| 106 | + --enable-clock-gettime \ |
| 107 | + --enable-hipe \ |
| 108 | + --enable-hybrid-heap \ |
| 109 | + --enable-kernel-poll \ |
| 110 | + --enable-shared-zlib \ |
| 111 | + --enable-smp-support \ |
| 112 | + --enable-threads \ |
| 113 | + --with-microstate-accounting=extra \ |
| 114 | + --without-common_test \ |
| 115 | + --without-debugger \ |
| 116 | + --without-dialyzer \ |
| 117 | + --without-diameter \ |
| 118 | + --without-edoc \ |
| 119 | + --without-erl_docgen \ |
| 120 | + --without-erl_interface \ |
| 121 | + --without-et \ |
| 122 | + --without-eunit \ |
| 123 | + --without-ftp \ |
| 124 | + --without-jinterface \ |
| 125 | + --without-megaco \ |
| 126 | + --without-observer \ |
| 127 | + --without-odbc \ |
| 128 | + --without-reltool \ |
| 129 | + --without-ssh \ |
| 130 | + --without-tftp \ |
| 131 | + --without-wx \ |
| 132 | + ; \ |
| 133 | +# Compile & install Erlang/OTP |
| 134 | + make -j "$(getconf _NPROCESSORS_ONLN)" GEN_OPT_FLGS="-O2 -fno-strict-aliasing"; \ |
| 135 | + make install; \ |
| 136 | + cd ..; \ |
| 137 | + rm -rf "$OTP_PATH"* /usr/local/lib/erlang/lib/*/src; \ |
| 138 | + \ |
| 139 | + runDeps="$( \ |
| 140 | + scanelf --needed --nobanner --format '%n#p' --recursive /usr/local \ |
| 141 | + | tr ',' '\n' \ |
| 142 | + | sort -u \ |
| 143 | + | awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \ |
| 144 | + )"; \ |
| 145 | + apk add --no-cache --virtual .otp-run-deps $runDeps; \ |
| 146 | + apk del --no-network .build-deps; \ |
| 147 | + \ |
| 148 | +# Check that OpenSSL still works after purging build dependencies |
| 149 | + openssl version; \ |
| 150 | +# Check that Erlang/OTP crypto & ssl were compiled against OpenSSL correctly |
| 151 | + erl -noshell -eval 'io:format("~p~n~n~p~n~n", [crypto:supports(), ssl:versions()]), init:stop().' |
32 | 152 |
|
33 |
| -ENV RABBITMQ_HOME /opt/rabbitmq |
34 |
| -ENV PATH $RABBITMQ_HOME/sbin:$PATH |
| 153 | +ENV RABBITMQ_DATA_DIR=/var/lib/rabbitmq |
| 154 | +# Create rabbitmq system user & group, fix permissions & allow root user to connect to the RabbitMQ Erlang VM |
| 155 | +RUN set -eux; \ |
| 156 | + addgroup -g 101 -S rabbitmq; \ |
| 157 | + adduser -u 100 -S -h "$RABBITMQ_DATA_DIR" -G rabbitmq rabbitmq; \ |
| 158 | + mkdir -p "$RABBITMQ_DATA_DIR" /etc/rabbitmq /tmp/rabbitmq-ssl /var/log/rabbitmq; \ |
| 159 | + chown -fR rabbitmq:rabbitmq "$RABBITMQ_DATA_DIR" /etc/rabbitmq /tmp/rabbitmq-ssl /var/log/rabbitmq; \ |
| 160 | + chmod 777 "$RABBITMQ_DATA_DIR" /etc/rabbitmq /tmp/rabbitmq-ssl /var/log/rabbitmq; \ |
| 161 | + ln -sf "$RABBITMQ_DATA_DIR/.erlang.cookie" /root/.erlang.cookie |
35 | 162 |
|
36 |
| -# gpg: key 6026DFCA: public key "RabbitMQ Release Signing Key <[email protected]>" imported |
37 |
| -ENV RABBITMQ_GPG_KEY 0A9AF2115F4687BD29803A206B73A36E6026DFCA |
| 163 | +# Use the latest stable RabbitMQ release (https://www.rabbitmq.com/download.html) |
| 164 | +ENV RABBITMQ_VERSION="3.7.11-rc.1" |
| 165 | +# https://www.rabbitmq.com/signatures.html#importing-gpg |
| 166 | +ENV RABBITMQ_PGP_KEY_ID="0x0A9AF2115F4687BD29803A206B73A36E6026DFCA" |
| 167 | +ENV RABBITMQ_HOME=/opt/rabbitmq |
38 | 168 |
|
39 |
| -ENV RABBITMQ_VERSION 3.7.8-rc.4 |
40 |
| -ENV RABBITMQ_GITHUB_TAG v3.7.8-rc.4 |
| 169 | +# Add RabbitMQ to PATH, send all logs to TTY |
| 170 | +ENV PATH=$RABBITMQ_HOME/sbin:$PATH \ |
| 171 | + RABBITMQ_LOGS=- RABBITMQ_SASL_LOGS=- |
41 | 172 |
|
42 |
| -RUN set -ex; \ |
| 173 | +# Install RabbitMQ |
| 174 | +RUN set -eux; \ |
43 | 175 | \
|
44 | 176 | apk add --no-cache --virtual .build-deps \
|
45 | 177 | ca-certificates \
|
46 | 178 | gnupg \
|
47 |
| - libressl \ |
48 | 179 | wget \
|
49 | 180 | xz \
|
50 | 181 | ; \
|
51 | 182 | \
|
52 |
| - wget -O rabbitmq-server.tar.xz.asc "https://github.com/rabbitmq/rabbitmq-server/releases/download/$RABBITMQ_GITHUB_TAG/rabbitmq-server-generic-unix-${RABBITMQ_VERSION}.tar.xz.asc"; \ |
53 |
| - wget -O rabbitmq-server.tar.xz "https://github.com/rabbitmq/rabbitmq-server/releases/download/$RABBITMQ_GITHUB_TAG/rabbitmq-server-generic-unix-${RABBITMQ_VERSION}.tar.xz"; \ |
| 183 | + RABBITMQ_SOURCE_URL="https://github.com/rabbitmq/rabbitmq-server/releases/download/v$RABBITMQ_VERSION/rabbitmq-server-generic-unix-$RABBITMQ_VERSION.tar.xz"; \ |
| 184 | + RABBITMQ_PATH="/usr/local/src/rabbitmq-$RABBITMQ_VERSION"; \ |
| 185 | + \ |
| 186 | + wget --progress dot:giga --output-document "$RABBITMQ_PATH.tar.xz.asc" "$RABBITMQ_SOURCE_URL.asc"; \ |
| 187 | + wget --progress dot:giga --output-document "$RABBITMQ_PATH.tar.xz" "$RABBITMQ_SOURCE_URL"; \ |
54 | 188 | \
|
55 | 189 | export GNUPGHOME="$(mktemp -d)"; \
|
56 |
| - gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys "$RABBITMQ_GPG_KEY"; \ |
57 |
| - gpg --batch --verify rabbitmq-server.tar.xz.asc rabbitmq-server.tar.xz; \ |
58 |
| - command -v gpgconf && gpgconf --kill all || :; \ |
| 190 | + gpg --batch --keyserver "$PGP_KEYSERVER" --recv-keys "$RABBITMQ_PGP_KEY_ID"; \ |
| 191 | + gpg --batch --verify "$RABBITMQ_PATH.tar.xz.asc" "$RABBITMQ_PATH.tar.xz"; \ |
| 192 | + gpgconf --kill all; \ |
59 | 193 | rm -rf "$GNUPGHOME"; \
|
60 | 194 | \
|
61 | 195 | mkdir -p "$RABBITMQ_HOME"; \
|
62 |
| - tar \ |
63 |
| - --extract \ |
64 |
| - --verbose \ |
65 |
| - --file rabbitmq-server.tar.xz \ |
66 |
| - --directory "$RABBITMQ_HOME" \ |
67 |
| - --strip-components 1 \ |
68 |
| - ; \ |
69 |
| - rm -f rabbitmq-server.tar.xz*; \ |
70 |
| - \ |
71 |
| -# update SYS_PREFIX (first making sure it's set to what we expect it to be) |
| 196 | + tar --extract --file "$RABBITMQ_PATH.tar.xz" --directory "$RABBITMQ_HOME" --strip-components 1; \ |
| 197 | + rm -rf "$RABBITMQ_PATH"*; \ |
| 198 | +# Do not default SYS_PREFIX to RABBITMQ_HOME, leave it empty |
72 | 199 | grep -qE '^SYS_PREFIX=\$\{RABBITMQ_HOME\}$' "$RABBITMQ_HOME/sbin/rabbitmq-defaults"; \
|
73 |
| - sed -ri 's!^(SYS_PREFIX=).*$!\1!g' "$RABBITMQ_HOME/sbin/rabbitmq-defaults"; \ |
| 200 | + sed -i 's/^SYS_PREFIX=.*$/SYS_PREFIX=/' "$RABBITMQ_HOME/sbin/rabbitmq-defaults"; \ |
74 | 201 | grep -qE '^SYS_PREFIX=$' "$RABBITMQ_HOME/sbin/rabbitmq-defaults"; \
|
| 202 | + chown -R rabbitmq:rabbitmq "$RABBITMQ_HOME"; \ |
75 | 203 | \
|
76 |
| - apk del .build-deps |
77 |
| - |
78 |
| -# set home so that any `--user` knows where to put the erlang cookie |
79 |
| -ENV HOME /var/lib/rabbitmq |
| 204 | + apk del .build-deps; \ |
| 205 | + \ |
| 206 | +# verify assumption of no stale cookies |
| 207 | + [ ! -e "$RABBITMQ_DATA_DIR/.erlang.cookie" ]; \ |
| 208 | +# Ensure RabbitMQ was installed correctly by running a few commands that do not depend on a running server, as the rabbitmq user |
| 209 | +# If they all succeed, it's safe to assume that things have been set up correctly |
| 210 | + su-exec rabbitmq rabbitmqctl help; \ |
| 211 | + su-exec rabbitmq rabbitmqctl list_ciphers; \ |
| 212 | + su-exec rabbitmq rabbitmq-plugins list; \ |
| 213 | +# no stale cookies |
| 214 | + rm "$RABBITMQ_DATA_DIR/.erlang.cookie" |
80 | 215 |
|
81 |
| -RUN mkdir -p /var/lib/rabbitmq /etc/rabbitmq /var/log/rabbitmq /tmp/rabbitmq-ssl \ |
82 |
| - && chown -R rabbitmq:rabbitmq /var/lib/rabbitmq /etc/rabbitmq /var/log/rabbitmq /tmp/rabbitmq-ssl \ |
83 |
| - && chmod -R 777 /var/lib/rabbitmq /etc/rabbitmq /var/log/rabbitmq /tmp/rabbitmq-ssl |
84 |
| -VOLUME /var/lib/rabbitmq |
| 216 | +# Added for backwards compatibility - users can simply COPY custom plugins to /plugins |
| 217 | +RUN ln -sf /opt/rabbitmq/plugins /plugins |
85 | 218 |
|
86 |
| -# add a symlink to the .erlang.cookie in /root so we can "docker exec rabbitmqctl ..." without gosu |
87 |
| -RUN ln -sf /var/lib/rabbitmq/.erlang.cookie /root/ |
| 219 | +# set home so that any `--user` knows where to put the erlang cookie |
| 220 | +ENV HOME $RABBITMQ_DATA_DIR |
| 221 | +# Hint that the data (a.k.a. home dir) dir should be separate volume |
| 222 | +VOLUME $RABBITMQ_DATA_DIR |
88 | 223 |
|
89 |
| -RUN ln -sf "$RABBITMQ_HOME/plugins" /plugins |
| 224 | +# warning: the VM is running with native name encoding of latin1 which may cause Elixir to malfunction as it expects utf8. Please ensure your locale is set to UTF-8 (which can be verified by running "locale" in your shell) |
| 225 | +# Setting all environment variables that control language preferences, behaviour differs - https://www.gnu.org/software/gettext/manual/html_node/The-LANGUAGE-variable.html#The-LANGUAGE-variable |
| 226 | +# https://docs.docker.com/samples/library/ubuntu/#locales |
| 227 | +ENV LANG=C.UTF-8 LANGUAGE=C.UTF-8 LC_ALL=C.UTF-8 |
90 | 228 |
|
91 | 229 | COPY docker-entrypoint.sh /usr/local/bin/
|
92 | 230 | ENTRYPOINT ["docker-entrypoint.sh"]
|
|
0 commit comments