-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
328 lines (310 loc) · 14.1 KB
/
Dockerfile
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# global args
ARG __BUILD_DIR__="/build"
ARG MEMCACHED_VERSION="1.6.15"
FROM fscm/centos:stream-9 as build
ARG __BUILD_DIR__
ARG __WORK_DIR__="/work"
ARG MEMCACHED_VERSION
ARG __USER__="root"
ARG __SOURCE_DIR__="${__WORK_DIR__}/src"
ENV \
LANG="C.utf8" \
LC_ALL="C.utf8"
USER "${__USER__}"
COPY "LICENSE" "files/" "${__WORK_DIR__}"/
WORKDIR "${__WORK_DIR__}"
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN \
# build env
echo '--> setting build env' && \
set +h && \
export __NPROC__="$(getconf _NPROCESSORS_ONLN || echo 1)" && \
#export DCACHE_LINESIZE="$(getconf LEVEL1_DCACHE_LINESIZE || echo 64)" && \
export DCACHE_LINESIZE="64" && \
export __KARCH__="$(case `arch` in x86_64*) echo x86;; aarch64) echo arm64;; esac)" && \
export __MARCH__="$(case `arch` in x86_64*) echo x86-64;; aarch64) echo armv8-a;; esac)" && \
export MAKEFLAGS="--silent --no-print-directory --jobs ${__NPROC__}" && \
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig && \
# build structure
echo '--> creating build structure' && \
for folder in 'bin'; do \
install --directory --owner="${__USER__}" --group="${__USER__}" --mode=0755 "${__BUILD_DIR__}/usr/${folder}"; \
done && \
for folder in '/tmp'; do \
install --directory --owner="${__USER__}" --group="${__USER__}" --mode=1777 "${__BUILD_DIR__}${folder}"; \
done && \
# dependencies
echo '--> instaling dependencies' && \
dnf --quiet makecache --refresh && \
dnf --assumeyes --quiet --setopt=install_weak_deps='no' install \
binutils \
ca-certificates \
curl \
diffutils \
file \
findutils \
gcc \
gperf \
gzip \
jq \
make \
patch \
perl-interpreter \
perl-base \
perl-lib \
perl-File-Compare \
perl-File-Copy \
perl-FindBin \
perl-IPC-Cmd \
python3-devel \
rsync \
tar \
xz \
> /dev/null && \
ln --symbolic --force python3 /usr/bin/python && \
# kernel headers
echo '--> installing kernel headers' && \
KERNEL_VERSION="$(curl --silent --location --retry 3 'https://www.kernel.org/releases.json' | jq -r '.latest_stable.version')" && \
install --directory "${__SOURCE_DIR__}/kernel" && \
curl --silent --location --retry 3 "https://cdn.kernel.org/pub/linux/kernel/v${KERNEL_VERSION%%.*}.x/linux-${KERNEL_VERSION}.tar.xz" \
| tar xJ --no-same-owner --strip-components=1 -C "${__SOURCE_DIR__}/kernel" && \
cd "${__SOURCE_DIR__}/kernel" && \
make mrproper > /dev/null && \
make ARCH="${__KARCH__}" INSTALL_HDR_PATH="/usr/local" headers_install > /dev/null && \
# The kernel headers that exported to user space are not covered by the GPLv2 license.
# This is documented in the "Linux kernel licensing rules":
# https://www.kernel.org/doc/html/latest/process/license-rules.html
cd ~- && \
rm -rf "${__SOURCE_DIR__}/kernel" && \
# musl
echo '--> installing musl libc' && \
install --directory "${__SOURCE_DIR__}/musl/_build" && \
curl --silent --location --retry 3 "https://musl.libc.org/releases/musl-latest.tar.gz" \
| tar xz --no-same-owner --strip-components=1 -C "${__SOURCE_DIR__}/musl" && \
cd "${__SOURCE_DIR__}/musl/_build" && \
../configure \
CFLAGS="-fPIC -O2 -g0 -s -w -pipe -march=${__MARCH__} -mtune=generic -DNDEBUG -DCLS=${__DCACHE_LINESIZE__}" \
--prefix='/usr/local' \
--disable-debug \
--disable-shared \
--enable-wrapper=all \
--enable-static \
> /dev/null && \
make > /dev/null && \
make install > /dev/null && \
# Applications linked against all musl public header files and crt files are allowed to
# omit copyright notice and permission notice otherwise required by the license.
# This is documented in the "COPYRIGHT" file.
# https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
cd ~- && \
rm -rf "${__SOURCE_DIR__}/musl" && \
# zlib
echo '--> installing zlib' && \
ZLIB_VERSION="$(rpm -q --qf "%{VERSION}" zlib)" && \
install --directory "${__SOURCE_DIR__}/zlib/_build" && \
curl --silent --location --retry 3 "https://zlib.net/fossils/zlib-${ZLIB_VERSION}.tar.gz" \
| tar xz --no-same-owner --strip-components=1 -C "${__SOURCE_DIR__}/zlib" && \
cd "${__SOURCE_DIR__}/zlib/_build" && \
sed -i.orig -e '/(man3dir)/d' ../Makefile.in && \
CC="musl-gcc -static --static" \
CFLAGS="-fPIC -O2 -g0 -s -w -pipe -mmusl -march=${__MARCH__} -mtune=generic -DNDEBUG -DCLS=${__DCACHE_LINESIZE__}" \
../configure \
--prefix='/usr/local' \
--includedir='/usr/local/include' \
--libdir='/usr/local/lib' \
--static \
> /dev/null && \
make > /dev/null && \
make install > /dev/null && \
install --directory --owner="${__USER__}" --group="${__USER__}" --mode=0755 "${__BUILD_DIR__}/licenses/zlib" && \
install --owner="${__USER__}" --group="${__USER__}" --mode=0644 --target-directory="${__BUILD_DIR__}/licenses/zlib" '../README' && \
(cd .. && find ./ -type f -a \( -iname '*LICENSE*' -o -iname '*COPYING*' \) -exec cp --parents {} "${__BUILD_DIR__}/licenses/zlib" ';') && \
cd ~- && \
rm -rf "${__SOURCE_DIR__}/zlib" && \
# openssl
echo '--> installing openssl' && \
OPENSSL_VERSION="$(rpm -q --qf "%{VERSION}" openssl-libs)" && \
install --directory "${__SOURCE_DIR__}/openssl/_build" && \
curl --silent --location --retry 3 "https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz" \
| tar xz --no-same-owner --strip-components=1 -C "${__SOURCE_DIR__}/openssl" && \
cd "${__SOURCE_DIR__}/openssl/_build" && \
../config \
CC="musl-gcc -static --static" \
--openssldir='/etc/ssl' \
--prefix='/usr/local' \
--libdir='/usr/local/lib' \
--release \
--static \
enable-cms \
enable-ec_nistp_64_gcc_128 \
enable-rfc3779 \
no-comp \
no-shared \
no-ssl3 \
no-weak-ssl-ciphers \
zlib \
-static \
-DCLS=${DCACHE_LINESIZE} \
-DNDEBUG \
-DOPENSSL_NO_HEARTBEATS \
-fPIC -O2 -g0 -s -w -pipe -mmusl -march=${__MARCH__} -mtune=generic '-DDEVRANDOM="\"/dev/urandom\""' && \
make > /dev/null && \
make install_sw > /dev/null && \
make install_ssldirs > /dev/null && \
install --directory --owner="${__USER__}" --group="${__USER__}" --mode=0755 "${__BUILD_DIR__}/licenses/openssl" && \
(cd .. && find ./ -type f -a \( -iname '*LICENSE*' -o -iname '*COPYING*' \) -exec cp --parents {} "${__BUILD_DIR__}/licenses/openssl" ';') && \
cd ~- && \
rm -rf "${__SOURCE_DIR__}/openssl" && \
# libevent
echo '--> installing libevent' && \
LIBEVENT_URL="$(curl --silent --location --retry 3 'https://api.github.com/repos/libevent/libevent/releases/latest' | jq -r '.assets[] | select(.content_type=="application/gzip") | .browser_download_url')" && \
install --directory "${__SOURCE_DIR__}/libevent/_build" && \
curl --silent --location --retry 3 "${LIBEVENT_URL}" \
| tar xz --no-same-owner --strip-components=1 -C "${__SOURCE_DIR__}/libevent" && \
cd "${__SOURCE_DIR__}/libevent/_build" && \
../configure \
CC="musl-gcc -static --static" \
CFLAGS="-fPIC -O2 -g0 -s -w -pipe -mmusl -march=${__MARCH__} -mtune=generic -DNDEBUG -DCLS=${__DCACHE_LINESIZE__}" \
--quiet \
--prefix='/usr/local' \
--includedir='/usr/local/include' \
--libdir='/usr/local/lib' \
--sysconfdir='/etc' \
--enable-fast-install \
--enable-silent-rules \
--enable-static \
--disable-debug-mode \
--disable-samples \
--disable-shared && \
make > /dev/null && \
make install > /dev/null && \
install --directory --owner="${__USER__}" --group="${__USER__}" --mode=0755 "${__BUILD_DIR__}/licenses/libevent" && \
(cd .. && find ./ -type f -a \( -iname '*LICENSE*' -o -iname '*COPYING*' \) -exec cp --parents {} "${__BUILD_DIR__}/licenses/libevent" ';') && \
cd ~- && \
rm -rf "${__SOURCE_DIR__}/libevent" && \
# libseccomp
echo '--> installing libseccomp' && \
LIBSECCOMP_URL="$(curl --silent --location --retry 3 'https://api.github.com/repos/seccomp/libseccomp/releases/latest' | jq -r '.assets[] | select(.content_type=="application/gzip") | .browser_download_url')" && \
install --directory "${__SOURCE_DIR__}/libseccomp/_build" && \
curl --silent --location --retry 3 "${LIBSECCOMP_URL}" \
| tar xz --no-same-owner --strip-components=1 -C "${__SOURCE_DIR__}/libseccomp" && \
cd "${__SOURCE_DIR__}/libseccomp/_build" && \
sed -i.orig -e '/^SUBDIRS/ s/ \(doc\|tests\)//g' ../Makefile.in && \
../configure \
CC="musl-gcc -static --static" \
CFLAGS="-fPIC -O2 -g0 -s -w -pipe -mmusl -march=${__MARCH__} -mtune=generic -DNDEBUG -DCLS=${__DCACHE_LINESIZE__}" \
--quiet \
--prefix='/usr/local' \
--includedir='/usr/local/include' \
--libdir='/usr/local/lib' \
--sysconfdir='/etc' \
--enable-fast-install \
--enable-silent-rules \
--enable-static \
--disable-python \
--disable-shared && \
make > /dev/null && \
make install > /dev/null && \
install --directory --owner="${__USER__}" --group="${__USER__}" --mode=0755 "${__BUILD_DIR__}/licenses/libseccomp" && \
(cd .. && find ./ -type f -a \( -iname '*LICENSE*' -o -iname '*COPYING*' \) -exec cp --parents {} "${__BUILD_DIR__}/licenses/libseccomp" ';') && \
cd ~- && \
rm -rf "${__SOURCE_DIR__}/libseccomp" && \
# cyrus-sasl
# echo '--> installing cyrus-sasl' && \
# CYRUS_SASL_URL="$(curl --silent --location --retry 3 'https://api.github.com/repos/cyrusimap/cyrus-sasl/releases/latest' | jq -r '.assets[] | select(.content_type=="application/x-gzip") | .browser_download_url')" && \
# install --directory "${__SOURCE_DIR__}/cyrus-sasl/_build" && \
# curl --silent --location --retry 3 "${CYRUS_SASL_URL}" \
# | tar xz --no-same-owner --strip-components=1 -C "${__SOURCE_DIR__}/cyrus-sasl" && \
# cd "${__SOURCE_DIR__}/cyrus-sasl/_build" && \
# ../configure \
# CC="musl-gcc -static --static" \
# CFLAGS="-fPIC -O2 -g0 -s -w -pipe -mmusl -march=${__MARCH__} -mtune=generic -DNDEBUG -DCLS=${__DCACHE_LINESIZE__}" \
# --quiet \
# --prefix='/usr/local' \
# --includedir='/usr/local/include' \
# --libdir='/usr/local/lib' \
# --sysconfdir='/etc' \
# --with-lib-subdir='lib' \
# --with-openssl='/usr/local' \
# --with-devrandom='/dev/urandom' \
# --with-rc4 \
# --without-pwcheck \
# --without-sqlite \
# --enable-fast-install \
# --enable-silent-rules \
# --enable-static \
# --enable-staticdlopen \
# --disable-java \
# --disable-otp \
# --enable-anon \
# --enable-cram \
# --enable-digest \
# --enable-ntlm \
# --enable-plain \
# --enable-login \
# --enable-auth-sasldb \
# --enable-alwaystrue \
# --disable-shared && \
# make --directory='./common' > /dev/null && \
# make --directory='./plugins' > /dev/null && \
# make > /dev/null && \
# make dist_man3_MANS='' install > /dev/null && \
# cd ~- && \
# rm -rf "${__SOURCE_DIR__}/cyrus-sasl" && \
# memcached
echo '--> installing memcached' && \
install --directory "${__SOURCE_DIR__}/memcached/_build" && \
curl --silent --location --retry 3 "http://www.memcached.org/files/memcached-${MEMCACHED_VERSION}.tar.gz" \
| tar xz --no-same-owner --strip-components=1 -C "${__SOURCE_DIR__}/memcached" && \
for p in "${__WORK_DIR__}/patches/memcached-${MEMCACHED_VERSION//./_}"*.patch; do \
patch --quiet --backup --unified --strip=0 --directory="${__SOURCE_DIR__}/memcached" < ${p}; \
done && \
cd "${__SOURCE_DIR__}/memcached/_build" && \
../configure \
CC="musl-gcc -static --static" \
CFLAGS="-fPIC -O2 -g0 -s -w -pipe -mmusl -march=${__MARCH__} -mtune=generic -DCLS=${__DCACHE_LINESIZE__}" \
--quiet \
--prefix='/usr' \
--includedir='/usr/include' \
--libdir='/usr/lib' \
--sysconfdir='/etc' \
# --enable-sasl \
# --enable-sasl-pwdb \
--enable-seccomp \
--enable-silent-rules \
--enable-static \
--enable-tls \
--disable-docs && \
make > /dev/null && \
make DESTDIR="${__BUILD_DIR__}" install-exec > /dev/null && \
install --directory --owner="${__USER__}" --group="${__USER__}" --mode=0755 "${__BUILD_DIR__}/licenses/memcached" && \
install --owner="${__USER__}" --group="${__USER__}" --mode=0644 --target-directory="${__BUILD_DIR__}/licenses/memcached" '../COPYING' && \
cd ~- && \
rm -rf "${__SOURCE_DIR__}/memcached" && \
# stripping
# echo '--> stripping binaries' && \
# find "${__BUILD_DIR__}"/usr/bin -type f -not -links +1 -exec strip --strip-all {} ';' && \
# licenses
echo '--> project licenses' && \
install --owner="${__USER__}" --group="${__USER__}" --mode=0644 --target-directory="${__BUILD_DIR__}/licenses" "${__WORK_DIR__}/LICENSE" && \
# done
echo '--> all done!'
FROM scratch
ARG __BUILD_DIR__
ARG REDIS_VERSION
LABEL \
maintainer="Frederico Martins <https://hub.docker.com/u/fscm/>" \
vendor="fscm" \
cmd="docker container run --detach --publish 11211:11211/tcp fscm/memcached" \
org.label-schema.schema-version="1.0" \
org.label-schema.name="fscm/memcached" \
org.label-schema.description="A small image that can be used to run the memcached server" \
org.label-schema.url="https://memcached.org/" \
org.label-schema.vcs-url="https://github.com/fscm/docker-memcached/" \
org.label-schema.vendor="fscm" \
org.label-schema.version=${REDIS_VERSION} \
org.label-schema.docker.cmd="docker container run --interactive --rm --tty --publish 11211:11211/tcp fscm/memcached" \
org.label-schema.docker.cmd.test="docker container run --interactive --rm --tty fscm/memcached --version"
EXPOSE 11211/tcp
COPY --from=build "${__BUILD_DIR__}" "/"
ENTRYPOINT ["/usr/bin/memcached"]