Skip to content

Commit c05d667

Browse files
authored
Merge pull request #320 from infosiftr/template
Add templating for simplified maintenance
2 parents c5720ca + cac8a53 commit c05d667

14 files changed

+661
-91
lines changed

3.4/Dockerfile

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ FROM debian:jessie-slim
33
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
44
RUN groupadd -r mongodb && useradd -r -g mongodb mongodb
55

6-
RUN apt-get update \
7-
&& apt-get install -y --no-install-recommends \
6+
RUN set -eux; \
7+
apt-get update; \
8+
apt-get install -y --no-install-recommends \
89
ca-certificates \
910
jq \
1011
numactl \
11-
&& rm -rf /var/lib/apt/lists/*
12+
; \
13+
if ! command -v ps > /dev/null; then \
14+
apt-get install -y --no-install-recommends procps; \
15+
fi; \
16+
rm -rf /var/lib/apt/lists/*
1217

1318
# grab gosu for easy step-down from root (https://github.com/tianon/gosu/releases)
1419
ENV GOSU_VERSION 1.10
@@ -21,6 +26,9 @@ RUN set -ex; \
2126
apt-get install -y --no-install-recommends \
2227
wget \
2328
; \
29+
if ! command -v gpg > /dev/null; then \
30+
apt-get install -y --no-install-recommends gnupg dirmngr; \
31+
fi; \
2432
rm -rf /var/lib/apt/lists/*; \
2533
\
2634
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
@@ -41,12 +49,7 @@ RUN set -ex; \
4149

4250
RUN mkdir /docker-entrypoint-initdb.d
4351

44-
ENV GPG_KEYS \
45-
# pub 4096R/A15703C6 2016-01-11 [expires: 2018-01-10]
46-
# Key fingerprint = 0C49 F373 0359 A145 1858 5931 BC71 1F9B A157 03C6
47-
# uid MongoDB 3.4 Release Signing Key <[email protected]>
48-
0C49F3730359A14518585931BC711F9BA15703C6
49-
# https://docs.mongodb.com/manual/tutorial/verify-mongodb-packages/#download-then-import-the-key-file
52+
ENV GPG_KEYS 0C49F3730359A14518585931BC711F9BA15703C6
5053
RUN set -ex; \
5154
export GNUPGHOME="$(mktemp -d)"; \
5255
for key in $GPG_KEYS; do \
@@ -87,7 +90,7 @@ RUN mkdir -p /data/db /data/configdb \
8790
VOLUME /data/db /data/configdb
8891

8992
COPY docker-entrypoint.sh /usr/local/bin/
90-
RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat
93+
RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat (3.4)
9194
ENTRYPOINT ["docker-entrypoint.sh"]
9295

9396
EXPOSE 27017

3.4/docker-entrypoint.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ if [ "$originalArgOne" = 'mongod' ]; then
232232
fi
233233
_mongod_hack_ensure_arg_val --bind_ip 127.0.0.1 "${mongodHackedArgs[@]}"
234234
_mongod_hack_ensure_arg_val --port 27017 "${mongodHackedArgs[@]}"
235+
_mongod_hack_ensure_no_arg --bind_ip_all "${mongodHackedArgs[@]}"
235236

236237
# remove "--auth" and "--replSet" for our initial startup (see https://docs.mongodb.com/manual/tutorial/enable-authentication/#start-mongodb-without-access-control)
237238
# https://github.com/docker-library/mongo/issues/211
@@ -319,6 +320,20 @@ if [ "$originalArgOne" = 'mongod' ]; then
319320
echo
320321
fi
321322

323+
# MongoDB 3.6+ defaults to localhost-only binding
324+
if mongod --help 2>&1 | grep -q -- --bind_ip_all; then # TODO remove this conditional when 3.4 is no longer supported
325+
haveBindIp=
326+
if _mongod_hack_have_arg --bind_ip "$@" || _mongod_hack_have_arg --bind_ip_all "$@"; then
327+
haveBindIp=1
328+
elif _parse_config "$@" && jq --exit-status '.net.bindIp // .net.bindIpAll' "$jsonConfigFile" > /dev/null; then
329+
haveBindIp=1
330+
fi
331+
if [ -z "$haveBindIp" ]; then
332+
# so if no "--bind_ip" is specified, let's add "--bind_ip_all"
333+
set -- "$@" --bind_ip_all
334+
fi
335+
fi
336+
322337
unset "${!MONGO_INITDB_@}"
323338
fi
324339

3.6/Dockerfile

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ FROM debian:stretch-slim
33
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
44
RUN groupadd -r mongodb && useradd -r -g mongodb mongodb
55

6-
RUN apt-get update \
7-
&& apt-get install -y --no-install-recommends \
6+
RUN set -eux; \
7+
apt-get update; \
8+
apt-get install -y --no-install-recommends \
89
ca-certificates \
9-
gnupg dirmngr \
1010
jq \
1111
numactl \
12-
procps \
13-
&& rm -rf /var/lib/apt/lists/*
12+
; \
13+
if ! command -v ps > /dev/null; then \
14+
apt-get install -y --no-install-recommends procps; \
15+
fi; \
16+
rm -rf /var/lib/apt/lists/*
1417

1518
# grab gosu for easy step-down from root (https://github.com/tianon/gosu/releases)
1619
ENV GOSU_VERSION 1.10
@@ -23,6 +26,9 @@ RUN set -ex; \
2326
apt-get install -y --no-install-recommends \
2427
wget \
2528
; \
29+
if ! command -v gpg > /dev/null; then \
30+
apt-get install -y --no-install-recommends gnupg dirmngr; \
31+
fi; \
2632
rm -rf /var/lib/apt/lists/*; \
2733
\
2834
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
@@ -31,7 +37,7 @@ RUN set -ex; \
3137
export GNUPGHOME="$(mktemp -d)"; \
3238
gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
3339
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
34-
gpgconf --kill all; \
40+
command -v gpgconf && gpgconf --kill all || :; \
3541
rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc; \
3642
chmod +x /usr/local/bin/gosu; \
3743
gosu nobody true; \
@@ -43,19 +49,14 @@ RUN set -ex; \
4349

4450
RUN mkdir /docker-entrypoint-initdb.d
4551

46-
ENV GPG_KEYS \
47-
# pub 4096R/91FA4AD5 2016-12-14 [expires: 2018-12-14]
48-
# Key fingerprint = 2930 ADAE 8CAF 5059 EE73 BB4B 5871 2A22 91FA 4AD5
49-
# uid MongoDB 3.6 Release Signing Key <[email protected]>
50-
2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
51-
# https://docs.mongodb.com/manual/tutorial/verify-mongodb-packages/#download-then-import-the-key-file
52+
ENV GPG_KEYS 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
5253
RUN set -ex; \
5354
export GNUPGHOME="$(mktemp -d)"; \
5455
for key in $GPG_KEYS; do \
5556
gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
5657
done; \
5758
gpg --batch --export $GPG_KEYS > /etc/apt/trusted.gpg.d/mongodb.gpg; \
58-
gpgconf --kill all; \
59+
command -v gpgconf && gpgconf --kill all || :; \
5960
rm -r "$GNUPGHOME"; \
6061
apt-key list
6162

3.6/docker-entrypoint.sh

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -321,15 +321,17 @@ if [ "$originalArgOne" = 'mongod' ]; then
321321
fi
322322

323323
# MongoDB 3.6+ defaults to localhost-only binding
324-
haveBindIp=
325-
if _mongod_hack_have_arg --bind_ip "$@" || _mongod_hack_have_arg --bind_ip_all "$@"; then
326-
haveBindIp=1
327-
elif _parse_config "$@" && jq --exit-status '.net.bindIp // .net.bindIpAll' "$jsonConfigFile" > /dev/null; then
328-
haveBindIp=1
329-
fi
330-
if [ -z "$haveBindIp" ]; then
331-
# so if no "--bind_ip" is specified, let's add "--bind_ip_all"
332-
set -- "$@" --bind_ip_all
324+
if mongod --help 2>&1 | grep -q -- --bind_ip_all; then # TODO remove this conditional when 3.4 is no longer supported
325+
haveBindIp=
326+
if _mongod_hack_have_arg --bind_ip "$@" || _mongod_hack_have_arg --bind_ip_all "$@"; then
327+
haveBindIp=1
328+
elif _parse_config "$@" && jq --exit-status '.net.bindIp // .net.bindIpAll' "$jsonConfigFile" > /dev/null; then
329+
haveBindIp=1
330+
fi
331+
if [ -z "$haveBindIp" ]; then
332+
# so if no "--bind_ip" is specified, let's add "--bind_ip_all"
333+
set -- "$@" --bind_ip_all
334+
fi
333335
fi
334336

335337
unset "${!MONGO_INITDB_@}"

4.0/Dockerfile

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ FROM ubuntu:xenial
33
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
44
RUN groupadd -r mongodb && useradd -r -g mongodb mongodb
55

6-
RUN apt-get update \
7-
&& apt-get install -y --no-install-recommends \
6+
RUN set -eux; \
7+
apt-get update; \
8+
apt-get install -y --no-install-recommends \
89
ca-certificates \
910
jq \
1011
numactl \
11-
&& rm -rf /var/lib/apt/lists/*
12+
; \
13+
if ! command -v ps > /dev/null; then \
14+
apt-get install -y --no-install-recommends procps; \
15+
fi; \
16+
rm -rf /var/lib/apt/lists/*
1217

1318
# grab gosu for easy step-down from root (https://github.com/tianon/gosu/releases)
1419
ENV GOSU_VERSION 1.10
@@ -21,6 +26,9 @@ RUN set -ex; \
2126
apt-get install -y --no-install-recommends \
2227
wget \
2328
; \
29+
if ! command -v gpg > /dev/null; then \
30+
apt-get install -y --no-install-recommends gnupg dirmngr; \
31+
fi; \
2432
rm -rf /var/lib/apt/lists/*; \
2533
\
2634
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
@@ -41,12 +49,7 @@ RUN set -ex; \
4149

4250
RUN mkdir /docker-entrypoint-initdb.d
4351

44-
ENV GPG_KEYS \
45-
# pub rsa4096 2018-04-18 [SC] [expires: 2023-04-17]
46-
# 9DA3 1620 334B D75D 9DCB 49F3 6881 8C72 E525 29D4
47-
# uid [ unknown] MongoDB 4.0 Release Signing Key <[email protected]>
48-
9DA31620334BD75D9DCB49F368818C72E52529D4
49-
# https://docs.mongodb.com/manual/tutorial/verify-mongodb-packages/#download-then-import-the-key-file
52+
ENV GPG_KEYS 9DA31620334BD75D9DCB49F368818C72E52529D4
5053
RUN set -ex; \
5154
export GNUPGHOME="$(mktemp -d)"; \
5255
for key in $GPG_KEYS; do \

4.0/docker-entrypoint.sh

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -321,15 +321,17 @@ if [ "$originalArgOne" = 'mongod' ]; then
321321
fi
322322

323323
# MongoDB 3.6+ defaults to localhost-only binding
324-
haveBindIp=
325-
if _mongod_hack_have_arg --bind_ip "$@" || _mongod_hack_have_arg --bind_ip_all "$@"; then
326-
haveBindIp=1
327-
elif _parse_config "$@" && jq --exit-status '.net.bindIp // .net.bindIpAll' "$jsonConfigFile" > /dev/null; then
328-
haveBindIp=1
329-
fi
330-
if [ -z "$haveBindIp" ]; then
331-
# so if no "--bind_ip" is specified, let's add "--bind_ip_all"
332-
set -- "$@" --bind_ip_all
324+
if mongod --help 2>&1 | grep -q -- --bind_ip_all; then # TODO remove this conditional when 3.4 is no longer supported
325+
haveBindIp=
326+
if _mongod_hack_have_arg --bind_ip "$@" || _mongod_hack_have_arg --bind_ip_all "$@"; then
327+
haveBindIp=1
328+
elif _parse_config "$@" && jq --exit-status '.net.bindIp // .net.bindIpAll' "$jsonConfigFile" > /dev/null; then
329+
haveBindIp=1
330+
fi
331+
if [ -z "$haveBindIp" ]; then
332+
# so if no "--bind_ip" is specified, let's add "--bind_ip_all"
333+
set -- "$@" --bind_ip_all
334+
fi
333335
fi
334336

335337
unset "${!MONGO_INITDB_@}"

4.1/Dockerfile

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ FROM ubuntu:xenial
33
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
44
RUN groupadd -r mongodb && useradd -r -g mongodb mongodb
55

6-
RUN apt-get update \
7-
&& apt-get install -y --no-install-recommends \
6+
RUN set -eux; \
7+
apt-get update; \
8+
apt-get install -y --no-install-recommends \
89
ca-certificates \
910
jq \
1011
numactl \
11-
&& rm -rf /var/lib/apt/lists/*
12+
; \
13+
if ! command -v ps > /dev/null; then \
14+
apt-get install -y --no-install-recommends procps; \
15+
fi; \
16+
rm -rf /var/lib/apt/lists/*
1217

1318
# grab gosu for easy step-down from root (https://github.com/tianon/gosu/releases)
1419
ENV GOSU_VERSION 1.10
@@ -21,6 +26,9 @@ RUN set -ex; \
2126
apt-get install -y --no-install-recommends \
2227
wget \
2328
; \
29+
if ! command -v gpg > /dev/null; then \
30+
apt-get install -y --no-install-recommends gnupg dirmngr; \
31+
fi; \
2432
rm -rf /var/lib/apt/lists/*; \
2533
\
2634
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
@@ -41,12 +49,7 @@ RUN set -ex; \
4149

4250
RUN mkdir /docker-entrypoint-initdb.d
4351

44-
ENV GPG_KEYS \
45-
# pub rsa4096 2018-04-18 [SC] [expires: 2023-04-17]
46-
# E162 F504 A20C DF15 827F 718D 4B7C 549A 058F 8B6B
47-
# uid [ unknown] MongoDB 4.2 Release Signing Key <[email protected]>
48-
E162F504A20CDF15827F718D4B7C549A058F8B6B
49-
# https://docs.mongodb.com/manual/tutorial/verify-mongodb-packages/#download-then-import-the-key-file
52+
ENV GPG_KEYS E162F504A20CDF15827F718D4B7C549A058F8B6B
5053
RUN set -ex; \
5154
export GNUPGHOME="$(mktemp -d)"; \
5255
for key in $GPG_KEYS; do \

4.1/docker-entrypoint.sh

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -321,15 +321,17 @@ if [ "$originalArgOne" = 'mongod' ]; then
321321
fi
322322

323323
# MongoDB 3.6+ defaults to localhost-only binding
324-
haveBindIp=
325-
if _mongod_hack_have_arg --bind_ip "$@" || _mongod_hack_have_arg --bind_ip_all "$@"; then
326-
haveBindIp=1
327-
elif _parse_config "$@" && jq --exit-status '.net.bindIp // .net.bindIpAll' "$jsonConfigFile" > /dev/null; then
328-
haveBindIp=1
329-
fi
330-
if [ -z "$haveBindIp" ]; then
331-
# so if no "--bind_ip" is specified, let's add "--bind_ip_all"
332-
set -- "$@" --bind_ip_all
324+
if mongod --help 2>&1 | grep -q -- --bind_ip_all; then # TODO remove this conditional when 3.4 is no longer supported
325+
haveBindIp=
326+
if _mongod_hack_have_arg --bind_ip "$@" || _mongod_hack_have_arg --bind_ip_all "$@"; then
327+
haveBindIp=1
328+
elif _parse_config "$@" && jq --exit-status '.net.bindIp // .net.bindIpAll' "$jsonConfigFile" > /dev/null; then
329+
haveBindIp=1
330+
fi
331+
if [ -z "$haveBindIp" ]; then
332+
# so if no "--bind_ip" is specified, let's add "--bind_ip_all"
333+
set -- "$@" --bind_ip_all
334+
fi
333335
fi
334336

335337
unset "${!MONGO_INITDB_@}"

0 commit comments

Comments
 (0)