-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The only wrinkle was the protected-mode changes for 6.0+, but I handled them similar to what we do in PHP for multiple variants off the same template.
- Loading branch information
Showing
8 changed files
with
350 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
FROM debian:buster-slim | ||
|
||
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added | ||
RUN groupadd -r -g 999 redis && useradd -r -g redis -u 999 redis | ||
|
||
# grab gosu for easy step-down from root | ||
# https://github.com/tianon/gosu/releases | ||
ENV GOSU_VERSION 1.11 | ||
RUN set -eux; \ | ||
# save list of currently installed packages for later so we can clean up | ||
savedAptMark="$(apt-mark showmanual)"; \ | ||
apt-get update; \ | ||
apt-get install -y --no-install-recommends \ | ||
ca-certificates \ | ||
dirmngr \ | ||
gnupg \ | ||
wget \ | ||
; \ | ||
rm -rf /var/lib/apt/lists/*; \ | ||
\ | ||
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \ | ||
wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \ | ||
wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \ | ||
\ | ||
# verify the signature | ||
export GNUPGHOME="$(mktemp -d)"; \ | ||
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \ | ||
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \ | ||
gpgconf --kill all; \ | ||
rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \ | ||
\ | ||
# clean up fetch dependencies | ||
apt-mark auto '.*' > /dev/null; \ | ||
[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; \ | ||
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ | ||
\ | ||
chmod +x /usr/local/bin/gosu; \ | ||
# verify that the binary works | ||
gosu --version; \ | ||
gosu nobody true | ||
|
||
RUN set -eux; \ | ||
apt-get update; \ | ||
apt-get install -y --no-install-recommends libc6-i386; \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
ENV REDIS_VERSION placeholder | ||
ENV REDIS_DOWNLOAD_URL placeholder | ||
ENV REDIS_DOWNLOAD_SHA placeholder | ||
|
||
RUN set -eux; \ | ||
\ | ||
savedAptMark="$(apt-mark showmanual)"; \ | ||
apt-get update; \ | ||
apt-get install -y --no-install-recommends \ | ||
ca-certificates \ | ||
wget \ | ||
\ | ||
gcc \ | ||
gcc-multilib \ | ||
libc6-dev-i386 \ | ||
make \ | ||
; \ | ||
rm -rf /var/lib/apt/lists/*; \ | ||
\ | ||
wget -O redis.tar.gz "$REDIS_DOWNLOAD_URL"; \ | ||
echo "$REDIS_DOWNLOAD_SHA *redis.tar.gz" | sha256sum -c -; \ | ||
mkdir -p /usr/src/redis; \ | ||
tar -xzf redis.tar.gz -C /usr/src/redis --strip-components=1; \ | ||
rm redis.tar.gz; \ | ||
\ | ||
# disable Redis protected mode [1] as it is unnecessary in context of Docker | ||
# (ports are not automatically exposed when running inside Docker, but rather explicitly by specifying -p / -P) | ||
# [1]: https://github.com/antirez/redis/commit/edd4d555df57dc84265fdfb4ef59a4678832f6da | ||
##<protected-mode-sed>## | ||
grep -E '^ *createBoolConfig[(]"protected-mode",.*, *1 *,.*[)],$' /usr/src/redis/src/config.c; \ | ||
sed -ri 's!^( *createBoolConfig[(]"protected-mode",.*, *)1( *,.*[)],)$!\10\2!' /usr/src/redis/src/config.c; \ | ||
grep -E '^ *createBoolConfig[(]"protected-mode",.*, *0 *,.*[)],$' /usr/src/redis/src/config.c; \ | ||
##</protected-mode-sed>## | ||
# 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" | ||
# see also https://github.com/docker-library/redis/issues/4#issuecomment-50780840 | ||
# (more exactly, this makes sure the default behavior of "save on SIGTERM" stays functional by default) | ||
\ | ||
make -C /usr/src/redis -j "$(nproc)" 32bit; \ | ||
make -C /usr/src/redis install; \ | ||
\ | ||
# TODO https://github.com/antirez/redis/pull/3494 (deduplicate "redis-server" copies) | ||
serverMd5="$(md5sum /usr/local/bin/redis-server | cut -d' ' -f1)"; export serverMd5; \ | ||
find /usr/local/bin/redis* -maxdepth 0 \ | ||
-type f -not -name redis-server \ | ||
-exec sh -eux -c ' \ | ||
md5="$(md5sum "$1" | cut -d" " -f1)"; \ | ||
test "$md5" = "$serverMd5"; \ | ||
' -- '{}' ';' \ | ||
-exec ln -svfT 'redis-server' '{}' ';' \ | ||
; \ | ||
\ | ||
rm -r /usr/src/redis; \ | ||
\ | ||
apt-mark auto '.*' > /dev/null; \ | ||
[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; \ | ||
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ | ||
\ | ||
redis-cli --version; \ | ||
redis-server --version | ||
|
||
RUN mkdir /data && chown redis:redis /data | ||
VOLUME /data | ||
WORKDIR /data | ||
|
||
COPY docker-entrypoint.sh /usr/local/bin/ | ||
ENTRYPOINT ["docker-entrypoint.sh"] | ||
|
||
EXPOSE 6379 | ||
CMD ["redis-server"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
FROM alpine:3.11 | ||
|
||
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added | ||
RUN addgroup -S -g 1000 redis && adduser -S -G redis -u 999 redis | ||
# alpine already has a gid 999, so we'll use the next id | ||
|
||
RUN apk add --no-cache \ | ||
# grab su-exec for easy step-down from root | ||
'su-exec>=0.2' \ | ||
# add tzdata for https://github.com/docker-library/redis/issues/138 | ||
tzdata | ||
|
||
ENV REDIS_VERSION placeholder | ||
ENV REDIS_DOWNLOAD_URL placeholder | ||
ENV REDIS_DOWNLOAD_SHA placeholder | ||
|
||
RUN set -eux; \ | ||
\ | ||
apk add --no-cache --virtual .build-deps \ | ||
coreutils \ | ||
gcc \ | ||
linux-headers \ | ||
make \ | ||
musl-dev \ | ||
; \ | ||
\ | ||
wget -O redis.tar.gz "$REDIS_DOWNLOAD_URL"; \ | ||
echo "$REDIS_DOWNLOAD_SHA *redis.tar.gz" | sha256sum -c -; \ | ||
mkdir -p /usr/src/redis; \ | ||
tar -xzf redis.tar.gz -C /usr/src/redis --strip-components=1; \ | ||
rm redis.tar.gz; \ | ||
\ | ||
# disable Redis protected mode [1] as it is unnecessary in context of Docker | ||
# (ports are not automatically exposed when running inside Docker, but rather explicitly by specifying -p / -P) | ||
# [1]: https://github.com/antirez/redis/commit/edd4d555df57dc84265fdfb4ef59a4678832f6da | ||
##<protected-mode-sed>## | ||
grep -E '^ *createBoolConfig[(]"protected-mode",.*, *1 *,.*[)],$' /usr/src/redis/src/config.c; \ | ||
sed -ri 's!^( *createBoolConfig[(]"protected-mode",.*, *)1( *,.*[)],)$!\10\2!' /usr/src/redis/src/config.c; \ | ||
grep -E '^ *createBoolConfig[(]"protected-mode",.*, *0 *,.*[)],$' /usr/src/redis/src/config.c; \ | ||
##</protected-mode-sed>## | ||
# 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" | ||
# see also https://github.com/docker-library/redis/issues/4#issuecomment-50780840 | ||
# (more exactly, this makes sure the default behavior of "save on SIGTERM" stays functional by default) | ||
\ | ||
make -C /usr/src/redis -j "$(nproc)"; \ | ||
make -C /usr/src/redis install; \ | ||
\ | ||
# TODO https://github.com/antirez/redis/pull/3494 (deduplicate "redis-server" copies) | ||
serverMd5="$(md5sum /usr/local/bin/redis-server | cut -d' ' -f1)"; export serverMd5; \ | ||
find /usr/local/bin/redis* -maxdepth 0 \ | ||
-type f -not -name redis-server \ | ||
-exec sh -eux -c ' \ | ||
md5="$(md5sum "$1" | cut -d" " -f1)"; \ | ||
test "$md5" = "$serverMd5"; \ | ||
' -- '{}' ';' \ | ||
-exec ln -svfT 'redis-server' '{}' ';' \ | ||
; \ | ||
\ | ||
rm -r /usr/src/redis; \ | ||
\ | ||
runDeps="$( \ | ||
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local \ | ||
| tr ',' '\n' \ | ||
| sort -u \ | ||
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \ | ||
)"; \ | ||
apk add --no-network --virtual .redis-rundeps $runDeps; \ | ||
apk del --no-network .build-deps; \ | ||
\ | ||
redis-cli --version; \ | ||
redis-server --version | ||
|
||
RUN mkdir /data && chown redis:redis /data | ||
VOLUME /data | ||
WORKDIR /data | ||
|
||
COPY docker-entrypoint.sh /usr/local/bin/ | ||
ENTRYPOINT ["docker-entrypoint.sh"] | ||
|
||
EXPOSE 6379 | ||
CMD ["redis-server"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
FROM debian:buster-slim | ||
|
||
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added | ||
RUN groupadd -r -g 999 redis && useradd -r -g redis -u 999 redis | ||
|
||
# grab gosu for easy step-down from root | ||
# https://github.com/tianon/gosu/releases | ||
ENV GOSU_VERSION 1.11 | ||
RUN set -eux; \ | ||
# save list of currently installed packages for later so we can clean up | ||
savedAptMark="$(apt-mark showmanual)"; \ | ||
apt-get update; \ | ||
apt-get install -y --no-install-recommends \ | ||
ca-certificates \ | ||
dirmngr \ | ||
gnupg \ | ||
wget \ | ||
; \ | ||
rm -rf /var/lib/apt/lists/*; \ | ||
\ | ||
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \ | ||
wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \ | ||
wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \ | ||
\ | ||
# verify the signature | ||
export GNUPGHOME="$(mktemp -d)"; \ | ||
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \ | ||
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \ | ||
gpgconf --kill all; \ | ||
rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \ | ||
\ | ||
# clean up fetch dependencies | ||
apt-mark auto '.*' > /dev/null; \ | ||
[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; \ | ||
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ | ||
\ | ||
chmod +x /usr/local/bin/gosu; \ | ||
# verify that the binary works | ||
gosu --version; \ | ||
gosu nobody true | ||
|
||
ENV REDIS_VERSION placeholder | ||
ENV REDIS_DOWNLOAD_URL placeholder | ||
ENV REDIS_DOWNLOAD_SHA placeholder | ||
|
||
RUN set -eux; \ | ||
\ | ||
savedAptMark="$(apt-mark showmanual)"; \ | ||
apt-get update; \ | ||
apt-get install -y --no-install-recommends \ | ||
ca-certificates \ | ||
wget \ | ||
\ | ||
gcc \ | ||
libc6-dev \ | ||
make \ | ||
; \ | ||
rm -rf /var/lib/apt/lists/*; \ | ||
\ | ||
wget -O redis.tar.gz "$REDIS_DOWNLOAD_URL"; \ | ||
echo "$REDIS_DOWNLOAD_SHA *redis.tar.gz" | sha256sum -c -; \ | ||
mkdir -p /usr/src/redis; \ | ||
tar -xzf redis.tar.gz -C /usr/src/redis --strip-components=1; \ | ||
rm redis.tar.gz; \ | ||
\ | ||
# disable Redis protected mode [1] as it is unnecessary in context of Docker | ||
# (ports are not automatically exposed when running inside Docker, but rather explicitly by specifying -p / -P) | ||
# [1]: https://github.com/antirez/redis/commit/edd4d555df57dc84265fdfb4ef59a4678832f6da | ||
##<protected-mode-sed>## | ||
grep -E '^ *createBoolConfig[(]"protected-mode",.*, *1 *,.*[)],$' /usr/src/redis/src/config.c; \ | ||
sed -ri 's!^( *createBoolConfig[(]"protected-mode",.*, *)1( *,.*[)],)$!\10\2!' /usr/src/redis/src/config.c; \ | ||
grep -E '^ *createBoolConfig[(]"protected-mode",.*, *0 *,.*[)],$' /usr/src/redis/src/config.c; \ | ||
##</protected-mode-sed>## | ||
# 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" | ||
# see also https://github.com/docker-library/redis/issues/4#issuecomment-50780840 | ||
# (more exactly, this makes sure the default behavior of "save on SIGTERM" stays functional by default) | ||
\ | ||
make -C /usr/src/redis -j "$(nproc)"; \ | ||
make -C /usr/src/redis install; \ | ||
\ | ||
# TODO https://github.com/antirez/redis/pull/3494 (deduplicate "redis-server" copies) | ||
serverMd5="$(md5sum /usr/local/bin/redis-server | cut -d' ' -f1)"; export serverMd5; \ | ||
find /usr/local/bin/redis* -maxdepth 0 \ | ||
-type f -not -name redis-server \ | ||
-exec sh -eux -c ' \ | ||
md5="$(md5sum "$1" | cut -d" " -f1)"; \ | ||
test "$md5" = "$serverMd5"; \ | ||
' -- '{}' ';' \ | ||
-exec ln -svfT 'redis-server' '{}' ';' \ | ||
; \ | ||
\ | ||
rm -r /usr/src/redis; \ | ||
\ | ||
apt-mark auto '.*' > /dev/null; \ | ||
[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; \ | ||
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ | ||
\ | ||
redis-cli --version; \ | ||
redis-server --version | ||
|
||
RUN mkdir /data && chown redis:redis /data | ||
VOLUME /data | ||
WORKDIR /data | ||
|
||
COPY docker-entrypoint.sh /usr/local/bin/ | ||
ENTRYPOINT ["docker-entrypoint.sh"] | ||
|
||
EXPOSE 6379 | ||
CMD ["redis-server"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# this changes in Redis 6.0+: https://github.com/docker-library/redis/pull/212#issuecomment-567705694 (see "update.sh" for where this template gets injected) | ||
grep -q '^#define CONFIG_DEFAULT_PROTECTED_MODE 1$' /usr/src/redis/src/server.h; \ | ||
sed -ri 's!^(#define CONFIG_DEFAULT_PROTECTED_MODE) 1$!\1 0!' /usr/src/redis/src/server.h; \ | ||
grep -q '^#define CONFIG_DEFAULT_PROTECTED_MODE 0$' /usr/src/redis/src/server.h; \ |
Oops, something went wrong.