-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathDockerfile.template
More file actions
142 lines (136 loc) · 4.08 KB
/
Copy pathDockerfile.template
File metadata and controls
142 lines (136 loc) · 4.08 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
{{ if env.variant == "alpine" then ( -}}
FROM alpine:{{ .alpine.version }}
{{ ) else ( -}}
FROM debian:{{ .debian.version }}-slim
{{ ) end -}}
# 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; \
addgroup -g 11211 memcache; \
adduser -D -u 11211 -G memcache memcache
{{ ) else ( -}}
RUN set -eux; \
groupadd --system --gid 11211 memcache; \
useradd --system --gid memcache --uid 11211 memcache
{{ ) end -}}
# ensure SASL's "libplain.so" is installed as per https://github.com/memcached/memcached/wiki/SASLHowto
{{ if env.variant == "alpine" then ( -}}
RUN apk add --no-cache libsasl
{{ ) else ( -}}
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
libsasl2-modules \
; \
rm -rf /var/lib/apt/lists/*
{{ ) end -}}
ENV MEMCACHED_VERSION {{ .version }}
ENV MEMCACHED_URL {{ .url }}
ENV MEMCACHED_SHA1 {{ .sha1 }}
RUN set -eux; \
\
{{ if env.variant == "alpine" then ( -}}
apk add --no-cache --virtual .build-deps \
ca-certificates \
coreutils \
cyrus-sasl-dev \
dpkg-dev dpkg \
gcc \
libc-dev \
libevent-dev \
linux-headers \
make \
openssl \
openssl-dev \
perl \
perl-io-socket-ssl \
perl-utils \
; \
{{ ) else ( -}}
savedAptMark="$(apt-mark showmanual)"; \
apt-get update; \
apt-get install -y --no-install-recommends \
ca-certificates \
dpkg-dev \
gcc \
libc6-dev \
libevent-dev \
libio-socket-ssl-perl \
libsasl2-dev \
libssl-dev \
make \
perl \
wget \
; \
rm -rf /var/lib/apt/lists/*; \
{{ ) end -}}
\
wget -O memcached.tar.gz "$MEMCACHED_URL"; \
echo "$MEMCACHED_SHA1 memcached.tar.gz" | sha1sum -c -; \
mkdir -p /usr/src/memcached; \
tar -xzf memcached.tar.gz -C /usr/src/memcached --strip-components=1; \
rm memcached.tar.gz; \
\
cd /usr/src/memcached; \
\
gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \
# https://github.com/memcached/memcached/issues/1220#issuecomment-2770251664: on arm32, we need to override the upstream alignment check (which fails to detect the need for alignment on arm32v6+ on our hardware for some reason, which then causes us to fail the tests 😭)
case "$gnuArch" in \
arm-*abihf) export ac_cv_c_alignment=need ;; \
esac; \
./configure \
--build="$gnuArch" \
--enable-extstore \
--enable-proxy \
--enable-sasl \
--enable-sasl-pwdb \
--enable-tls \
; \
nproc="$(nproc)"; \
make -j "$nproc"; \
\
{{ if env.variant == "debian" then ( -}}
# see https://github.com/docker-library/memcached/pull/54#issuecomment-562797748 and https://bugs.debian.org/927461 for why we have to munge openssl.cnf
sed -i.bak 's/SECLEVEL=2/SECLEVEL=1/g' /etc/ssl/openssl.cnf; \
{{ ) else "" end -}}
# try the tests in parallel first, but many of them are resource-intensive, so fall back to serial
make test PARALLEL="$nproc" || make test; \
{{ if env.variant == "debian" then ( -}}
mv /etc/ssl/openssl.cnf.bak /etc/ssl/openssl.cnf; \
{{ ) else "" end -}}
\
make install; \
\
cd /; \
rm -rf /usr/src/memcached; \
\
{{ if env.variant == "alpine" then ( -}}
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 .memcached-rundeps $runDeps; \
apk del --no-network .build-deps; \
{{ ) else ( -}}
apt-mark auto '.*' > /dev/null; \
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); printf "*%s\n", 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; \
{{ ) end -}}
\
memcached -V
COPY docker-entrypoint.sh /usr/local/bin/
RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat
ENTRYPOINT ["docker-entrypoint.sh"]
USER memcache
EXPOSE 11211
CMD ["memcached"]