-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: yzewei <[email protected]>
- Loading branch information
Showing
4 changed files
with
185 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# This file is generated by the template. | ||
|
||
REGISTRY?=lcr.loongnix.cn | ||
ORGANIZATION?=library | ||
REPOSITORY?=redis | ||
TAG?=5.0.14 | ||
VERSION?=5.0.14 | ||
|
||
IMAGE=$(REGISTRY)/$(ORGANIZATION)/$(REPOSITORY):$(TAG) | ||
|
||
default: image | ||
|
||
image: | ||
docker build \ | ||
--build-arg https_proxy=$(https_proxy) \ | ||
-t $(IMAGE) \ | ||
-t $(IMAGE)-sid \ | ||
./debian | ||
|
||
push: | ||
docker push $(IMAGE) | ||
docker push $(IMAGE)-sid |
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,135 @@ | ||
FROM lcr.loongnix.cn/library/debian:sid | ||
|
||
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added | ||
RUN set -eux; \ | ||
groupadd -r -g 999 redis; \ | ||
useradd -r -g redis -u 999 redis | ||
|
||
# runtime dependencies | ||
RUN set -eux; \ | ||
apt-get update; \ | ||
apt-get install -y --no-install-recommends \ | ||
# add tzdata explicitly for https://github.com/docker-library/redis/issues/138 (see also https://bugs.debian.org/837060 and related) | ||
tzdata \ | ||
; \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
# grab gosu for easy step-down from root | ||
# https://github.com/tianon/gosu/releases | ||
ENV GOSU_VERSION 1.17 | ||
#ADD gosu /usr/local/bin/gosu | ||
RUN set -eux; \ | ||
savedAptMark="$(apt-mark showmanual)"; \ | ||
apt-get update; \ | ||
apt-get install -y --no-install-recommends ca-certificates gnupg wget; \ | ||
rm -rf /var/lib/apt/lists/*; \ | ||
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \ | ||
case "$dpkgArch" in \ | ||
#loongarch64) GOSU_REPO="http://cloud.loongnix.cn/releases/loongarch64/tianon/gosu/1.17/gosu-loongarch64";; \ | ||
loongarch64) GOSU_REPO="http://cloud.loongnix.cn/releases/loongarch64/tianon/gosu/1.14/gosu-1.14_Linux_loong64.tar.gz";; \ | ||
*) GOSU_REPO="https://github.com/tianon/gosu";; \ | ||
esac; \ | ||
# wget -O /usr/local/bin/gosu "${GOSU_REPO}/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \ | ||
wget -O gosu.tar.gz http://cloud.loongnix.cn/releases/loongarch64/tianon/gosu/1.14/gosu-1.14_Linux_loong64.tar.gz && tar xf gosu.tar.gz && cp gosu-loong64 /usr/local/bin/gosu && rm gosu.tar.gz; \ | ||
apt-mark auto '.*' > /dev/null; \ | ||
[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; \ | ||
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; | ||
|
||
RUN chmod +x /usr/local/bin/gosu; \ | ||
gosu nobody true; | ||
|
||
ENV REDIS_VERSION 5.0.14 | ||
ENV REDIS_DOWNLOAD_URL http://download.redis.io/releases/redis-5.0.14.tar.gz | ||
|
||
RUN set -eux; \ | ||
\ | ||
savedAptMark="$(apt-mark showmanual)"; \ | ||
apt-get update; \ | ||
apt-get install -y --no-install-recommends \ | ||
ca-certificates \ | ||
wget \ | ||
\ | ||
dpkg-dev \ | ||
gcc \ | ||
libc6-dev \ | ||
libssl-dev \ | ||
make \ | ||
; \ | ||
rm -rf /var/lib/apt/lists/*; \ | ||
\ | ||
wget -O redis.tar.gz "$REDIS_DOWNLOAD_URL"; \ | ||
mkdir -p /usr/src/redis; \ | ||
tar -xzf redis.tar.gz -C /usr/src/redis --strip-components=1; \ | ||
rm -f /usr/src/redis/deps/jemalloc/build-aux/config.guess /usr/src/redis/deps/jemalloc/build-aux/config.sub; \ | ||
wget -O /usr/src/redis/deps/jemalloc/build-aux/config.sub "git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD"; \ | ||
wget -O /usr/src/redis/deps/jemalloc/build-aux/config.guess "git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD"; \ | ||
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/redis/redis/commit/edd4d555df57dc84265fdfb4ef59a4678832f6da | ||
RUN 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; \ | ||
# 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) | ||
\ | ||
# https://github.com/jemalloc/jemalloc/issues/467 -- we need to patch the "./configure" for the bundled jemalloc to match how Debian compiles, for compatibility | ||
# (also, we do cross-builds, so we need to embed the appropriate "--build=xxx" values to that "./configure" invocation) | ||
gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \ | ||
extraJemallocConfigureFlags="--build=$gnuArch"; \ | ||
# https://salsa.debian.org/debian/jemalloc/-/blob/c0a88c37a551be7d12e4863435365c9a6a51525f/debian/rules#L8-23 | ||
dpkgArch="$(dpkg --print-architecture)"; \ | ||
case "${dpkgArch##*-}" in \ | ||
amd64 | i386 | x32) extraJemallocConfigureFlags="$extraJemallocConfigureFlags --with-lg-page=12" ;; \ | ||
*) extraJemallocConfigureFlags="$extraJemallocConfigureFlags --with-lg-page=16" ;; \ | ||
esac; \ | ||
extraJemallocConfigureFlags="$extraJemallocConfigureFlags --with-lg-hugepage=21"; \ | ||
grep -F 'cd jemalloc && ./configure ' /usr/src/redis/deps/Makefile; \ | ||
sed -ri 's!cd jemalloc && ./configure !&'"$extraJemallocConfigureFlags"' !' /usr/src/redis/deps/Makefile; \ | ||
grep -F "cd jemalloc && ./configure $extraJemallocConfigureFlags " /usr/src/redis/deps/Makefile; \ | ||
\ | ||
export BUILD_TLS=yes; \ | ||
make -C /usr/src/redis -j "$(nproc)" all; \ | ||
make -C /usr/src/redis install; \ | ||
\ | ||
# TODO https://github.com/redis/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; \ | ||
find /usr/local -type f -executable -exec ldd '{}' ';' \ | ||
| awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); print so }' \ | ||
| sort -u \ | ||
| xargs -r dpkg-query --search \ | ||
| cut -d: -f1 \ | ||
| sort -u \ | ||
| xargs -r apt-mark manual \ | ||
; \ | ||
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ | ||
\ | ||
redis-cli --version; \ | ||
redis-server --version; \ | ||
\ | ||
echo '{"spdxVersion":"SPDX-2.3","SPDXID":"SPDXRef-DOCUMENT","name":"redis-server-sbom","packages":[{"name":"redis-server","versionInfo":"6.0.20","SPDXID":"SPDXRef-Package--redis-server","externalRefs":[{"referenceCategory":"PACKAGE-MANAGER","referenceType":"purl","referenceLocator":"pkg:generic/[email protected]?os_name=debian&os_version=buster"}],"licenseDeclared":"BSD-3-Clause"}]}' > /usr/local/redis.spdx.json | ||
|
||
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,24 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
# first arg is `-f` or `--some-option` | ||
# or first arg is `something.conf` | ||
if [ "${1#-}" != "$1" ] || [ "${1%.conf}" != "$1" ]; then | ||
set -- redis-server "$@" | ||
fi | ||
|
||
# allow the container to be started with `--user` | ||
if [ "$1" = 'redis-server' -a "$(id -u)" = '0' ]; then | ||
find . \! -user redis -exec chown redis '{}' + | ||
exec gosu redis "$0" "$@" | ||
fi | ||
|
||
# set an appropriate umask (if one isn't set already) | ||
# - https://github.com/docker-library/redis/issues/305 | ||
# - https://github.com/redis/redis/blob/bb875603fb7ff3f9d19aad906bd45d7db98d9a39/utils/systemd-redis_server.service#L37 | ||
um="$(umask)" | ||
if [ "$um" = '0022' ]; then | ||
umask 0077 | ||
fi | ||
|
||
exec "$@" |
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