|
| 1 | +FROM debian:bullseye-slim |
| 2 | + |
| 3 | +# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added |
| 4 | +RUN groupadd -r -g 999 redis && useradd -r -g redis -u 999 redis |
| 5 | + |
| 6 | +# grab gosu for easy step-down from root |
| 7 | +# https://github.com/tianon/gosu/releases |
| 8 | +ENV GOSU_VERSION 1.16 |
| 9 | +RUN set -eux; \ |
| 10 | + savedAptMark="$(apt-mark showmanual)"; \ |
| 11 | + apt-get update; \ |
| 12 | + apt-get install -y --no-install-recommends ca-certificates dirmngr gnupg wget; \ |
| 13 | + rm -rf /var/lib/apt/lists/*; \ |
| 14 | + dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \ |
| 15 | + wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \ |
| 16 | + wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \ |
| 17 | + export GNUPGHOME="$(mktemp -d)"; \ |
| 18 | + gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \ |
| 19 | + gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \ |
| 20 | + gpgconf --kill all; \ |
| 21 | + rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \ |
| 22 | + apt-mark auto '.*' > /dev/null; \ |
| 23 | + [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; \ |
| 24 | + apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ |
| 25 | + chmod +x /usr/local/bin/gosu; \ |
| 26 | + gosu --version; \ |
| 27 | + gosu nobody true |
| 28 | + |
| 29 | +ENV REDIS_VERSION 7.2-rc1 |
| 30 | +ENV REDIS_DOWNLOAD_URL https://github.com/redis/redis/archive/7.2-rc1.tar.gz |
| 31 | +ENV REDIS_DOWNLOAD_SHA d94d95c448eeb3dca8b4fd4801f9d2f8bdae0f5f84b2d9f5cfbd48cd6d8d5b43 |
| 32 | + |
| 33 | +RUN set -eux; \ |
| 34 | + \ |
| 35 | + savedAptMark="$(apt-mark showmanual)"; \ |
| 36 | + apt-get update; \ |
| 37 | + apt-get install -y --no-install-recommends \ |
| 38 | + ca-certificates \ |
| 39 | + wget \ |
| 40 | + \ |
| 41 | + dpkg-dev \ |
| 42 | + gcc \ |
| 43 | + libc6-dev \ |
| 44 | + libssl-dev \ |
| 45 | + make \ |
| 46 | + ; \ |
| 47 | + rm -rf /var/lib/apt/lists/*; \ |
| 48 | + \ |
| 49 | + wget -O redis.tar.gz "$REDIS_DOWNLOAD_URL"; \ |
| 50 | + echo "$REDIS_DOWNLOAD_SHA *redis.tar.gz" | sha256sum -c -; \ |
| 51 | + mkdir -p /usr/src/redis; \ |
| 52 | + tar -xzf redis.tar.gz -C /usr/src/redis --strip-components=1; \ |
| 53 | + rm redis.tar.gz; \ |
| 54 | + \ |
| 55 | +# disable Redis protected mode [1] as it is unnecessary in context of Docker |
| 56 | +# (ports are not automatically exposed when running inside Docker, but rather explicitly by specifying -p / -P) |
| 57 | +# [1]: https://github.com/redis/redis/commit/edd4d555df57dc84265fdfb4ef59a4678832f6da |
| 58 | + grep -E '^ *createBoolConfig[(]"protected-mode",.*, *1 *,.*[)],$' /usr/src/redis/src/config.c; \ |
| 59 | + sed -ri 's!^( *createBoolConfig[(]"protected-mode",.*, *)1( *,.*[)],)$!\10\2!' /usr/src/redis/src/config.c; \ |
| 60 | + grep -E '^ *createBoolConfig[(]"protected-mode",.*, *0 *,.*[)],$' /usr/src/redis/src/config.c; \ |
| 61 | +# for future reference, we modify this directly in the source instead of just supplying a default configuration flag because apparently "if you specify any argument to redis-server, [it assumes] you are going to specify everything" |
| 62 | +# see also https://github.com/docker-library/redis/issues/4#issuecomment-50780840 |
| 63 | +# (more exactly, this makes sure the default behavior of "save on SIGTERM" stays functional by default) |
| 64 | + \ |
| 65 | +# https://github.com/jemalloc/jemalloc/issues/467 -- we need to patch the "./configure" for the bundled jemalloc to match how Debian compiles, for compatibility |
| 66 | +# (also, we do cross-builds, so we need to embed the appropriate "--build=xxx" values to that "./configure" invocation) |
| 67 | + gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \ |
| 68 | + extraJemallocConfigureFlags="--build=$gnuArch"; \ |
| 69 | +# https://salsa.debian.org/debian/jemalloc/-/blob/c0a88c37a551be7d12e4863435365c9a6a51525f/debian/rules#L8-23 |
| 70 | + dpkgArch="$(dpkg --print-architecture)"; \ |
| 71 | + case "${dpkgArch##*-}" in \ |
| 72 | + amd64 | i386 | x32) extraJemallocConfigureFlags="$extraJemallocConfigureFlags --with-lg-page=12" ;; \ |
| 73 | + *) extraJemallocConfigureFlags="$extraJemallocConfigureFlags --with-lg-page=16" ;; \ |
| 74 | + esac; \ |
| 75 | + extraJemallocConfigureFlags="$extraJemallocConfigureFlags --with-lg-hugepage=21"; \ |
| 76 | + grep -F 'cd jemalloc && ./configure ' /usr/src/redis/deps/Makefile; \ |
| 77 | + sed -ri 's!cd jemalloc && ./configure !&'"$extraJemallocConfigureFlags"' !' /usr/src/redis/deps/Makefile; \ |
| 78 | + grep -F "cd jemalloc && ./configure $extraJemallocConfigureFlags " /usr/src/redis/deps/Makefile; \ |
| 79 | + \ |
| 80 | + export BUILD_TLS=yes; \ |
| 81 | + make -C /usr/src/redis -j "$(nproc)" all; \ |
| 82 | + make -C /usr/src/redis install; \ |
| 83 | + \ |
| 84 | +# TODO https://github.com/redis/redis/pull/3494 (deduplicate "redis-server" copies) |
| 85 | + serverMd5="$(md5sum /usr/local/bin/redis-server | cut -d' ' -f1)"; export serverMd5; \ |
| 86 | + find /usr/local/bin/redis* -maxdepth 0 \ |
| 87 | + -type f -not -name redis-server \ |
| 88 | + -exec sh -eux -c ' \ |
| 89 | + md5="$(md5sum "$1" | cut -d" " -f1)"; \ |
| 90 | + test "$md5" = "$serverMd5"; \ |
| 91 | + ' -- '{}' ';' \ |
| 92 | + -exec ln -svfT 'redis-server' '{}' ';' \ |
| 93 | + ; \ |
| 94 | + \ |
| 95 | + rm -r /usr/src/redis; \ |
| 96 | + \ |
| 97 | + apt-mark auto '.*' > /dev/null; \ |
| 98 | + [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; \ |
| 99 | + find /usr/local -type f -executable -exec ldd '{}' ';' \ |
| 100 | + | awk '/=>/ { print $(NF-1) }' \ |
| 101 | + | sort -u \ |
| 102 | + | xargs -r dpkg-query --search \ |
| 103 | + | cut -d: -f1 \ |
| 104 | + | sort -u \ |
| 105 | + | xargs -r apt-mark manual \ |
| 106 | + ; \ |
| 107 | + apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ |
| 108 | + \ |
| 109 | + redis-cli --version; \ |
| 110 | + redis-server --version |
| 111 | + |
| 112 | +RUN mkdir /data && chown redis:redis /data |
| 113 | +VOLUME /data |
| 114 | +WORKDIR /data |
| 115 | + |
| 116 | +COPY docker-entrypoint.sh /usr/local/bin/ |
| 117 | +ENTRYPOINT ["docker-entrypoint.sh"] |
| 118 | + |
| 119 | +EXPOSE 6379 |
| 120 | +CMD ["redis-server"] |
0 commit comments