-
Notifications
You must be signed in to change notification settings - Fork 279
/
Dockerfile.template
197 lines (187 loc) · 7.91 KB
/
Dockerfile.template
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
{{
def major: env.version | split(".")[0] | tonumber
-}}
FROM {{ .FROM.version }}
# explicitly set user/group IDs
RUN set -eux; \
groupadd -r cassandra --gid=999; \
useradd -r -g cassandra --uid=999 cassandra
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
# solves warning: "jemalloc shared library could not be preloaded to speed up memory allocations"
libjemalloc2 \
# "free" is used by cassandra-env.sh
procps \
# "cqlsh" needs a python interpreter
{{
# python3 is only supported in 4.0+
# https://issues.apache.org/jira/browse/CASSANDRA-10190
# https://github.com/apache/cassandra/blob/cassandra-3.11.16/bin/cqlsh#L18-L26
# https://github.com/apache/cassandra/blob/cassandra-3.0.29/bin/cqlsh#L18-L26
# (only looking for/accepting Python 2.7 specifically)
if major < 4 then (
-}}
python2 \
{{ ) else ( -}}
python3 \
{{ ) end -}}
# "ip" is not required by Cassandra itself, but is commonly used in scripting Cassandra's configuration (since it is so fixated on explicit IP addresses)
iproute2 \
# Cassandra will automatically use numactl if available
# https://github.com/apache/cassandra/blob/18bcda2d4c2eba7370a0b21f33eed37cb730bbb3/bin/cassandra#L90-L100
# https://github.com/apache/cassandra/commit/604c0e87dc67fa65f6904ef9a98a029c9f2f865a
numactl \
; \
rm -rf /var/lib/apt/lists/*; \
# https://issues.apache.org/jira/browse/CASSANDRA-15767 ("bin/cassandra" only looks for "libjemalloc.so" or "libjemalloc.so.1" which doesn't match our "libjemalloc.so.2")
libjemalloc="$(readlink -e /usr/lib/*/libjemalloc.so.2)"; \
ln -sT "$libjemalloc" /usr/local/lib/libjemalloc.so; \
ldconfig
# grab gosu for easy step-down from root
# https://github.com/tianon/gosu/releases
ENV GOSU_VERSION 1.17
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 }')"; \
wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \
wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \
export GNUPGHOME="$(mktemp -d)"; \
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
gpgconf --kill all; \
rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
apt-mark auto '.*' > /dev/null; \
[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; \
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
chmod +x /usr/local/bin/gosu; \
gosu --version; \
gosu nobody true
ENV CASSANDRA_HOME /opt/cassandra
ENV CASSANDRA_CONF /etc/cassandra
ENV PATH $CASSANDRA_HOME/bin:$PATH
# https://cwiki.apache.org/confluence/display/CASSANDRA2/DebianPackaging#DebianPackaging-AddingRepositoryKeys
# $ docker run --rm buildpack-deps:bullseye-curl bash -c 'wget -qO- https://downloads.apache.org/cassandra/KEYS | gpg --batch --import &> /dev/null && gpg --batch --list-keys --with-fingerprint --with-colons' | awk -F: '$1 == "pub" && $2 == "-" { pub = 1 } pub && $1 == "fpr" { fpr = $10 } $1 == "sub" { pub = 0 } pub && fpr && $1 == "uid" && $2 == "-" { print "#", $10; print "\t" fpr " \\"; pub = 0 }'
ENV GPG_KEYS \
# Eric Evans <[email protected]>
CEC86BB4A0BA9D0F90397CAEF8358FA2F2833C93 \
# Eric Evans <[email protected]>
C4965EE9E3015D192CCCF2B6F758CE318D77295D \
# Sylvain Lebresne (pcmanus) <[email protected]>
5AED1BF378E9A19DADE1BCB34BD736A82B5C1B00 \
# T Jake Luciani <[email protected]>
514A2AD631A57A16DD0047EC749D6EEC0353B12C \
# Michael Shuler <[email protected]>
A26E528B271F19B9E5D8E19EA278B781FE4B2BDA \
# Michael Semb Wever <[email protected]>
A4C465FEA0C552561A392A61E91335D77E3E87CB \
# Alex Petrov <[email protected]>
9E66CEC6106D578D0B1EB9BFF1000962B7F6840C \
# Jordan West <[email protected]>
C4009872C59B49561310D966D0062876AF30F054 \
# Brandon Williams <[email protected]>
B7842CDAF36E6A3214FAE35D5E85B9AE0B84C041 \
# Ekaterina Buryanova Dimitrova (CODE SIGNING KEY) <[email protected]>
3E9C876907A560ACA00964F363E9BAD215BBF5F0 \
# Sam Tunnicliffe (CODE SIGNING KEY) <[email protected]>
F8B7FD00E05C932991A2CD6150EE103D162C5A55 \
# Stefan Miklosovic <[email protected]>
7464AAD9068241C50BA6A26232F35CB2F546D93E \
# Berenguer Blasi (Code Signing Key) <[email protected]>
CEC5C50B9C629EF0F5AB2706650B72EB14CCD622
ENV CASSANDRA_VERSION {{ .version }}
ENV CASSANDRA_SHA512 {{ .sha512 }}
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/*; \
\
ddist() { \
local f="$1"; shift; \
local distFile="$1"; shift; \
local success=; \
local distUrl=; \
for distUrl in \
# https://github.com/docker-library/tomcat/pull/308
https://dlcdn.apache.org/ \
# if the version is outdated, we have to pull from the archive
https://archive.apache.org/dist/ \
; do \
if wget --progress=dot:giga -O "$f" "$distUrl$distFile" && [ -s "$f" ]; then \
success=1; \
break; \
fi; \
done; \
[ -n "$success" ]; \
}; \
\
ddist 'cassandra-bin.tgz' "cassandra/$CASSANDRA_VERSION/apache-cassandra-$CASSANDRA_VERSION-bin.tar.gz"; \
echo "$CASSANDRA_SHA512 *cassandra-bin.tgz" | sha512sum --check --strict -; \
\
ddist 'cassandra-bin.tgz.asc' "cassandra/$CASSANDRA_VERSION/apache-cassandra-$CASSANDRA_VERSION-bin.tar.gz.asc"; \
export GNUPGHOME="$(mktemp -d)"; \
for key in $GPG_KEYS; do \
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key"; \
done; \
gpg --batch --verify cassandra-bin.tgz.asc cassandra-bin.tgz; \
rm -rf "$GNUPGHOME"; \
\
apt-mark auto '.*' > /dev/null; \
[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; \
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
\
mkdir -p "$CASSANDRA_HOME"; \
tar --extract --file cassandra-bin.tgz --directory "$CASSANDRA_HOME" --strip-components 1; \
rm cassandra-bin.tgz*; \
\
[ ! -e "$CASSANDRA_CONF" ]; \
mv "$CASSANDRA_HOME/conf" "$CASSANDRA_CONF"; \
ln -sT "$CASSANDRA_CONF" "$CASSANDRA_HOME/conf"; \
\
dpkgArch="$(dpkg --print-architecture)"; \
case "$dpkgArch" in \
ppc64el) \
# https://issues.apache.org/jira/browse/CASSANDRA-13345
# "The stack size specified is too small, Specify at least 328k"
{{ if env.version == "3.0" then ( -}}
grep -- '-Xss256k' "$CASSANDRA_CONF/cassandra-env.sh"; \
sed -ri 's/-Xss256k/-Xss512k/g' "$CASSANDRA_CONF/cassandra-env.sh"; \
grep -- '-Xss512k' "$CASSANDRA_CONF/cassandra-env.sh"; \
{{ ) elif major == 3 then ( -}}
grep -- '^-Xss256k$' "$CASSANDRA_CONF/jvm.options"; \
sed -ri 's/^-Xss256k$/-Xss512k/' "$CASSANDRA_CONF/jvm.options"; \
grep -- '^-Xss512k$' "$CASSANDRA_CONF/jvm.options"; \
{{ ) else ( -}}
grep -- '^-Xss256k$' "$CASSANDRA_CONF/jvm-server.options"; \
sed -ri 's/^-Xss256k$/-Xss512k/' "$CASSANDRA_CONF/jvm-server.options"; \
grep -- '^-Xss512k$' "$CASSANDRA_CONF/jvm-server.options"; \
{{ ) end -}}
;; \
esac; \
\
mkdir -p "$CASSANDRA_CONF" /var/lib/cassandra /var/log/cassandra; \
chown -R cassandra:cassandra "$CASSANDRA_CONF" /var/lib/cassandra /var/log/cassandra; \
chmod 1777 "$CASSANDRA_CONF" /var/lib/cassandra /var/log/cassandra; \
chmod -R a+rwX "$CASSANDRA_CONF"; \
ln -sT /var/lib/cassandra "$CASSANDRA_HOME/data"; \
ln -sT /var/log/cassandra "$CASSANDRA_HOME/logs"; \
\
# smoke test
cassandra -v
VOLUME /var/lib/cassandra
COPY docker-entrypoint.sh /usr/local/bin/
{{ if env.version | split(".") | .[0] | tonumber < 4 then ( -}}
RUN ln -s usr/local/bin/docker-entrypoint.sh /docker-entrypoint.sh # backwards compat
{{ ) else "" end -}}
ENTRYPOINT ["docker-entrypoint.sh"]
# 7000: intra-node communication
# 7001: TLS intra-node communication
# 7199: JMX
# 9042: CQL
# 9160: thrift service
EXPOSE 7000 7001 7199 9042 9160
CMD ["cassandra", "-f"]