forked from valkey-io/valkey-container
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.template
More file actions
189 lines (177 loc) · 6.17 KB
/
Dockerfile.template
File metadata and controls
189 lines (177 loc) · 6.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
{{ include ".template-helper-functions" -}}
{{ if env.variant == "alpine" then ( -}}
FROM alpine:{{ .alpine.version }} AS base
{{ ) else ( -}}
FROM debian:{{ .debian.version }}-slim AS base
{{ ) end -}}
FROM base AS build
ENV VALKEY_DOWNLOAD_SHA {{ .sha256 // error("no sha256 for \(.version) (\(env.version))") }}
ADD "{{ .url }}" /valkey.tar.gz
RUN set -eux; \
\
{{ if env.variant == "alpine" then ( -}}
apk add --no-cache \
coreutils \
dpkg-dev dpkg \
gcc \
g++ \
linux-headers \
make \
musl-dev \
openssl-dev \
; \
{{ ) else ( -}}
apt-get update; \
apt-get install -y --no-install-recommends \
dpkg-dev \
gcc \
libc6-dev \
libssl-dev \
libsystemd-dev \
make \
; \
rm -rf /var/lib/apt/lists/*; \
{{ ) end -}}
\
{{ if .version == "unstable" then ( -}}
echo "Unstable Valkey version, do not compare SHA256SUM" ;\
{{ ) else ( -}}
echo "$VALKEY_DOWNLOAD_SHA *valkey.tar.gz" | sha256sum -c -; \
{{ ) end -}}
\
mkdir -p /usr/src/valkey; \
tar -xzf valkey.tar.gz -C /usr/src/valkey --strip-components=1; \
rm valkey.tar.gz; \
\
# disable Valkey 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)
grep -E '^ *createBoolConfig[(]"protected-mode",.*, *1 *,.*[)],$' /usr/src/valkey/src/config.c; \
sed -ri 's!^( *createBoolConfig[(]"protected-mode",.*, *)1( *,.*[)],)$!\10\2!' /usr/src/valkey/src/config.c; \
grep -E '^ *createBoolConfig[(]"protected-mode",.*, *0 *,.*[)],$' /usr/src/valkey/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 valkey-server, [it assumes] you are going to specify everything"
# (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/valkey/deps/Makefile; \
sed -ri 's!cd jemalloc && ./configure !&'"$extraJemallocConfigureFlags"' !' /usr/src/valkey/deps/Makefile; \
grep -F "cd jemalloc && ./configure $extraJemallocConfigureFlags " /usr/src/valkey/deps/Makefile; \
\
{{ if .version == "unstable" then ( -}}
echo "Unstable version detected — enabling USE_FAST_FLOAT"; \
{{ if env.variant == "alpine" then ( -}}
{{ ) else ( -}}
apt-get update; \
apt-get install -y --no-install-recommends g++; \
rm -rf /var/lib/apt/lists/*; \
{{ ) end -}}
export BUILD_TLS=yes USE_FAST_FLOAT=yes; \
{{ ) elif ( (.version | split(".") | .[0] | tonumber) * 100 + (.version | split(".") | .[1] | tonumber) ) >= 801 then ( -}}
echo "Version {{ .version }} is 8.1 or higher - enabling USE_FAST_FLOAT"; \
{{ if env.variant == "alpine" then ( -}}
{{ ) else ( -}}
apt-get update; \
apt-get install -y --no-install-recommends g++; \
rm -rf /var/lib/apt/lists/*; \
{{ ) end -}}
export BUILD_TLS=yes USE_FAST_FLOAT=yes; \
{{ ) else ( -}}
export BUILD_TLS=yes; \
{{ ) end -}}
{{ if env.variant == "alpine" then ( -}}
\
{{ ) else ( -}}
export USE_SYSTEMD=yes; \
{{ ) end -}}
make -C /usr/src/valkey -j "$(nproc)" all; \
make -C /usr/src/valkey install; \
\
serverMd5="$(md5sum /usr/local/bin/valkey-server | cut -d' ' -f1)"; export serverMd5; \
find /usr/local/bin/valkey* -maxdepth 0 \
-type f -not -name valkey-server \
-exec sh -eux -c ' \
md5="$(md5sum "$1" | cut -d" " -f1)"; \
test "$md5" = "$serverMd5"; \
' -- '{}' ';' \
-exec ln -svfT 'valkey-server' '{}' ';' \
; \
\
echo {{
{
name: "valkey-server",
version: .version,
params: (
if env.variant == "alpine" then
{
os_name: "alpine",
os_version: .alpine.version,
}
else
{
os_name: "debian",
os_version: .debian.version,
}
end
),
licenses: [
"BSD-3-Clause"
]
} | sbom | tostring | @sh
}} > /usr/local/valkey.spdx.json
FROM base
ENV VALKEY_VERSION {{ .version }}
LABEL org.opencontainers.image.source="https://github.com/valkey-io/valkey"
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
{{ if env.variant == "alpine" then ( -}}
RUN set -eux; \
# alpine already has a gid 999, so we'll use the next id
addgroup -S -g 1000 valkey; \
adduser -S -G valkey -u 999 valkey
{{ ) else ( -}}
RUN set -eux; \
groupadd -r -g 999 valkey; \
useradd -r -g valkey -u 999 valkey
{{ ) end -}}
# runtime dependencies
{{ if env.variant == "alpine" then ( -}}
RUN set -eux; \
apk add --no-cache \
# add tzdata for https://github.com/docker-library/redis/issues/138
tzdata \
# add setpriv for step down from root.
setpriv \
openssl \
libgcc \
;
{{ ) else ( -}}
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 \
{{ if .debian.version != "bookworm" then "libssl3t64" else "libssl3" end }} \
; \
rm -rf /var/lib/apt/lists/*
{{ ) end -}}
# Install valkey built earlier
COPY --from=build /usr/local /usr/local
RUN mkdir /data && \
chown valkey:valkey /data && \
mkdir -p /run/valkey && \
chown valkey:valkey /run/valkey && \
valkey-cli --version && \
valkey-server --version
WORKDIR /data
COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]
EXPOSE 6379
CMD ["valkey-server"]