musarehmani100 commited on
Commit
86413f1
1 Parent(s): b9e3a1a

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +143 -0
Dockerfile ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #
2
+ # NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh"
3
+ #
4
+ # PLEASE DO NOT EDIT IT DIRECTLY.
5
+ #
6
+
7
+ FROM alpine:3.19
8
+
9
+ # add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
10
+ RUN set -eux; \
11
+ # alpine already has a gid 999, so we'll use the next id
12
+ addgroup -S -g 1000 redis; \
13
+ adduser -S -G redis -u 999 redis
14
+
15
+ # runtime dependencies
16
+ RUN set -eux; \
17
+ apk add --no-cache \
18
+ # add tzdata for https://github.com/docker-library/redis/issues/138
19
+ tzdata \
20
+ ;
21
+
22
+ # grab gosu for easy step-down from root
23
+ # https://github.com/tianon/gosu/releases
24
+ ENV GOSU_VERSION 1.17
25
+ RUN set -eux; \
26
+ apk add --no-cache --virtual .gosu-fetch gnupg; \
27
+ arch="$(apk --print-arch)"; \
28
+ case "$arch" in \
29
+ 'x86_64') url='https://github.com/tianon/gosu/releases/download/1.17/gosu-amd64'; sha256='bbc4136d03ab138b1ad66fa4fc051bafc6cc7ffae632b069a53657279a450de3' ;; \
30
+ 'aarch64') url='https://github.com/tianon/gosu/releases/download/1.17/gosu-arm64'; sha256='c3805a85d17f4454c23d7059bcb97e1ec1af272b90126e79ed002342de08389b' ;; \
31
+ 'armhf') url='https://github.com/tianon/gosu/releases/download/1.17/gosu-armhf'; sha256='e5866286277ff2a2159fb9196fea13e0a59d3f1091ea46ddb985160b94b6841b' ;; \
32
+ 'x86') url='https://github.com/tianon/gosu/releases/download/1.17/gosu-i386'; sha256='087dbb8fe479537e64f9c86fa49ff3b41dee1cbd28739a19aaef83dc8186b1ca' ;; \
33
+ 'ppc64le') url='https://github.com/tianon/gosu/releases/download/1.17/gosu-ppc64el'; sha256='1891acdcfa70046818ab6ed3c52b9d42fa10fbb7b340eb429c8c7849691dbd76' ;; \
34
+ 'riscv64') url='https://github.com/tianon/gosu/releases/download/1.17/gosu-riscv64'; sha256='38a6444b57adce135c42d5a3689f616fc7803ddc7a07ff6f946f2ebc67a26ba6' ;; \
35
+ 's390x') url='https://github.com/tianon/gosu/releases/download/1.17/gosu-s390x'; sha256='69873bab588192f760547ca1f75b27cfcf106e9f7403fee6fd0600bc914979d0' ;; \
36
+ 'armv7') url='https://github.com/tianon/gosu/releases/download/1.17/gosu-armhf'; sha256='e5866286277ff2a2159fb9196fea13e0a59d3f1091ea46ddb985160b94b6841b' ;; \
37
+ *) echo >&2 "error: unsupported gosu architecture: '$arch'"; exit 1 ;; \
38
+ esac; \
39
+ wget -O /usr/local/bin/gosu.asc "$url.asc"; \
40
+ wget -O /usr/local/bin/gosu "$url"; \
41
+ echo "$sha256 */usr/local/bin/gosu" | sha256sum -c -; \
42
+ export GNUPGHOME="$(mktemp -d)"; \
43
+ gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
44
+ gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
45
+ gpgconf --kill all; \
46
+ rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
47
+ apk del --no-network .gosu-fetch; \
48
+ chmod +x /usr/local/bin/gosu; \
49
+ gosu --version; \
50
+ gosu nobody true
51
+
52
+ ENV REDIS_VERSION 7.2.4
53
+ ENV REDIS_DOWNLOAD_URL http://download.redis.io/releases/redis-7.2.4.tar.gz
54
+ ENV REDIS_DOWNLOAD_SHA 8d104c26a154b29fd67d6568b4f375212212ad41e0c2caa3d66480e78dbd3b59
55
+
56
+ RUN set -eux; \
57
+ \
58
+ apk add --no-cache --virtual .build-deps \
59
+ coreutils \
60
+ dpkg-dev dpkg \
61
+ gcc \
62
+ linux-headers \
63
+ make \
64
+ musl-dev \
65
+ openssl-dev \
66
+ # install real "wget" to avoid:
67
+ # + wget -O redis.tar.gz https://download.redis.io/releases/redis-x.y.z.tar.gz
68
+ # Connecting to download.redis.io (45.60.121.1:80)
69
+ # wget: bad header line: XxhODalH: btu; path=/; Max-Age=900
70
+ wget \
71
+ ; \
72
+ \
73
+ wget -O redis.tar.gz "$REDIS_DOWNLOAD_URL"; \
74
+ echo "$REDIS_DOWNLOAD_SHA *redis.tar.gz" | sha256sum -c -; \
75
+ mkdir -p /usr/src/redis; \
76
+ tar -xzf redis.tar.gz -C /usr/src/redis --strip-components=1; \
77
+ rm redis.tar.gz; \
78
+ \
79
+ # disable Redis protected mode [1] as it is unnecessary in context of Docker
80
+ # (ports are not automatically exposed when running inside Docker, but rather explicitly by specifying -p / -P)
81
+ # [1]: https://github.com/redis/redis/commit/edd4d555df57dc84265fdfb4ef59a4678832f6da
82
+ grep -E '^ *createBoolConfig[(]"protected-mode",.*, *1 *,.*[)],$' /usr/src/redis/src/config.c; \
83
+ sed -ri 's!^( *createBoolConfig[(]"protected-mode",.*, *)1( *,.*[)],)$!\10\2!' /usr/src/redis/src/config.c; \
84
+ grep -E '^ *createBoolConfig[(]"protected-mode",.*, *0 *,.*[)],$' /usr/src/redis/src/config.c; \
85
+ # 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"
86
+ # see also https://github.com/docker-library/redis/issues/4#issuecomment-50780840
87
+ # (more exactly, this makes sure the default behavior of "save on SIGTERM" stays functional by default)
88
+ \
89
+ # https://github.com/jemalloc/jemalloc/issues/467 -- we need to patch the "./configure" for the bundled jemalloc to match how Debian compiles, for compatibility
90
+ # (also, we do cross-builds, so we need to embed the appropriate "--build=xxx" values to that "./configure" invocation)
91
+ gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \
92
+ extraJemallocConfigureFlags="--build=$gnuArch"; \
93
+ # https://salsa.debian.org/debian/jemalloc/-/blob/c0a88c37a551be7d12e4863435365c9a6a51525f/debian/rules#L8-23
94
+ dpkgArch="$(dpkg --print-architecture)"; \
95
+ case "${dpkgArch##*-}" in \
96
+ amd64 | i386 | x32) extraJemallocConfigureFlags="$extraJemallocConfigureFlags --with-lg-page=12" ;; \
97
+ *) extraJemallocConfigureFlags="$extraJemallocConfigureFlags --with-lg-page=16" ;; \
98
+ esac; \
99
+ extraJemallocConfigureFlags="$extraJemallocConfigureFlags --with-lg-hugepage=21"; \
100
+ grep -F 'cd jemalloc && ./configure ' /usr/src/redis/deps/Makefile; \
101
+ sed -ri 's!cd jemalloc && ./configure !&'"$extraJemallocConfigureFlags"' !' /usr/src/redis/deps/Makefile; \
102
+ grep -F "cd jemalloc && ./configure $extraJemallocConfigureFlags " /usr/src/redis/deps/Makefile; \
103
+ \
104
+ export BUILD_TLS=yes; \
105
+ make -C /usr/src/redis -j "$(nproc)" all; \
106
+ make -C /usr/src/redis install; \
107
+ \
108
+ # TODO https://github.com/redis/redis/pull/3494 (deduplicate "redis-server" copies)
109
+ serverMd5="$(md5sum /usr/local/bin/redis-server | cut -d' ' -f1)"; export serverMd5; \
110
+ find /usr/local/bin/redis* -maxdepth 0 \
111
+ -type f -not -name redis-server \
112
+ -exec sh -eux -c ' \
113
+ md5="$(md5sum "$1" | cut -d" " -f1)"; \
114
+ test "$md5" = "$serverMd5"; \
115
+ ' -- '{}' ';' \
116
+ -exec ln -svfT 'redis-server' '{}' ';' \
117
+ ; \
118
+ \
119
+ rm -r /usr/src/redis; \
120
+ \
121
+ runDeps="$( \
122
+ scanelf --needed --nobanner --format '%n#p' --recursive /usr/local \
123
+ | tr ',' '\n' \
124
+ | sort -u \
125
+ | awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
126
+ )"; \
127
+ apk add --no-network --virtual .redis-rundeps $runDeps; \
128
+ apk del --no-network .build-deps; \
129
+ \
130
+ redis-cli --version; \
131
+ redis-server --version; \
132
+ \
133
+ echo '{"spdxVersion":"SPDX-2.3","SPDXID":"SPDXRef-DOCUMENT","name":"redis-server-sbom","packages":[{"name":"redis-server","versionInfo":"7.2.4","SPDXID":"SPDXRef-Package--redis-server","externalRefs":[{"referenceCategory":"PACKAGE-MANAGER","referenceType":"purl","referenceLocator":"pkg:generic/redis-server@7.2.4?os_name=alpine&os_version=3.19"}],"licenseDeclared":"BSD-3-Clause"}]}' > /usr/local/redis.spdx.json
134
+
135
+ RUN mkdir /data && chown redis:redis /data
136
+ VOLUME /data
137
+ WORKDIR /data
138
+
139
+ COPY docker-entrypoint.sh /usr/local/bin/
140
+ ENTRYPOINT ["docker-entrypoint.sh"]
141
+
142
+ EXPOSE 6379
143
+ CMD ["redis-server"]