Skip to content

Commit 07a91dc

Browse files
CLOUDP-333181: Combined dockerfiles (#289)
# Summary Since we will stop re-building images daily, we won't have `-context` images anymore. We then don't need Dockerfiles templating. This PR creates self-sufficient Dockerfiles that build our images without templating. They only need variables passed with ARG. For images which already had a plain Dockerfile, it was renamed `Dockerfile.old`, and inventories modified accordingly. For now, we keep templates and Sonar, until the Atomic Release epic is completed and we fully get rid of all of it. ## Proof of Work The proof of work will come when actually using them in a build pipeline. In a future PR. This one is a noop, Dockerfiles are created but not used yet. ## Methodology The Dockerfiles were automatically generated, using Sonar templating, by adding special `final_dockerfile` tag to stages necessary to generate one. Using code like: ``` def test_build_init_database_dockerfile(): process_image( image_name="init-database", skip_tags=["release"], include_tags=["final_dockerfile"], build_args={ "registry": "localhost:5000", "version": "1.1.0", "is_appdb": False, "mongodb_tools_url_ubi": "https://downloads.mongodb.org/tools/db/mongodb-database-tools-rhel93-x86_64-100.12.0.tgz", }, build_options={}, inventory="inventories/init_database.yaml", ) ``` --------- Co-authored-by: Maciej Karaś <[email protected]>
1 parent 8cd399d commit 07a91dc

File tree

34 files changed

+762
-55
lines changed

34 files changed

+762
-55
lines changed

.gitignore

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ public/architectures/**/secrets/*
4343

4444
docker/mongodb-kubernetes-appdb/content/readinessprobe
4545
mongodb-kubernetes
46-
docker/mongodb-kubernetes-operator/Dockerfile
47-
docker/mongodb-kubernetes-database/Dockerfile
48-
docker/mongodb-enterprise-ops-manager/Dockerfile
49-
docker/mongodb-kubernetes-init-database/Dockerfile
50-
docker/mongodb-kubernetes-init-ops-manager/Dockerfile
5146
docker/mongodb-kubernetes-operator/content/mongodb-kubernetes-operator.tar
5247
docker/mongodb-kubernetes-tests/helm_chart/
5348
docker/mongodb-kubernetes-tests/public/

docker/mongodb-agent-non-matrix/Dockerfile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
ARG imagebase
2-
FROM ${imagebase} as base
1+
FROM scratch AS base
2+
3+
ARG agent_version
4+
ARG agent_distro
5+
ARG tools_version
6+
ARG tools_distro
7+
8+
ADD https://mciuploads.s3.amazonaws.com/mms-automation/mongodb-mms-build-agent/builds/automation-agent/prod/mongodb-mms-automation-agent-${agent_version}.${agent_distro}.tar.gz /data/mongodb-agent.tar.gz
9+
ADD https://downloads.mongodb.org/tools/db/mongodb-database-tools-${tools_distro}-${tools_version}.tgz /data/mongodb-tools.tgz
10+
11+
COPY ./docker/mongodb-kubernetes-init-database/content/LICENSE /data/LICENSE
312

413
FROM registry.access.redhat.com/ubi9/ubi-minimal
514

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
ARG imagebase
2+
FROM ${imagebase} as base
3+
4+
FROM registry.access.redhat.com/ubi9/ubi-minimal
5+
6+
ARG version
7+
8+
LABEL name="MongoDB Agent" \
9+
version="${version}" \
10+
summary="MongoDB Agent" \
11+
description="MongoDB Agent" \
12+
vendor="MongoDB" \
13+
release="1" \
14+
maintainer="[email protected]"
15+
16+
# Replace libcurl-minimal and curl-minimal with the full versions
17+
# https://bugzilla.redhat.com/show_bug.cgi?id=1994521
18+
RUN microdnf install -y libssh libpsl libbrotli \
19+
&& microdnf download curl libcurl \
20+
&& rpm -Uvh --nodeps --replacefiles "*curl*$( uname -i ).rpm" \
21+
&& microdnf remove -y libcurl-minimal curl-minimal
22+
23+
RUN microdnf install -y --disableplugin=subscription-manager --setopt=install_weak_deps=0 nss_wrapper
24+
# Copy-pasted from https://www.mongodb.com/docs/manual/tutorial/install-mongodb-enterprise-on-red-hat-tarball/
25+
RUN microdnf install -y --disableplugin=subscription-manager \
26+
cyrus-sasl cyrus-sasl-gssapi cyrus-sasl-plain krb5-libs openldap openssl xz-libs
27+
# Dependencies for the Agent
28+
RUN microdnf install -y --disableplugin=subscription-manager --setopt=install_weak_deps=0 \
29+
net-snmp \
30+
net-snmp-agent-libs
31+
RUN microdnf install -y --disableplugin=subscription-manager \
32+
hostname tar gzip procps jq \
33+
&& microdnf upgrade -y \
34+
&& rm -rf /var/lib/apt/lists/*
35+
36+
RUN mkdir -p /agent \
37+
&& mkdir -p /var/lib/mongodb-mms-automation \
38+
&& mkdir -p /var/log/mongodb-mms-automation/ \
39+
&& chmod -R +wr /var/log/mongodb-mms-automation/ \
40+
# ensure that the agent user can write the logs in OpenShift
41+
&& touch /var/log/mongodb-mms-automation/readiness.log \
42+
&& chmod ugo+rw /var/log/mongodb-mms-automation/readiness.log
43+
44+
45+
COPY --from=base /data/mongodb-agent.tar.gz /agent
46+
COPY --from=base /data/mongodb-tools.tgz /agent
47+
COPY --from=base /data/LICENSE /licenses/LICENSE
48+
49+
RUN tar xfz /agent/mongodb-agent.tar.gz \
50+
&& mv mongodb-mms-automation-agent-*/mongodb-mms-automation-agent /agent/mongodb-agent \
51+
&& chmod +x /agent/mongodb-agent \
52+
&& mkdir -p /var/lib/automation/config \
53+
&& chmod -R +r /var/lib/automation/config \
54+
&& rm /agent/mongodb-agent.tar.gz \
55+
&& rm -r mongodb-mms-automation-agent-*
56+
57+
RUN tar xfz /agent/mongodb-tools.tgz --directory /var/lib/mongodb-mms-automation/ && rm /agent/mongodb-tools.tgz
58+
59+
USER 2000
60+
CMD ["/agent/mongodb-agent", "-cluster=/var/lib/automation/config/automation-config.json"]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
### Building locally
2+
3+
For building the MongoDB Agent (non-static) image locally use the example command:
4+
5+
TODO: What to do with label quay.expires-after=48h?
6+
```bash
7+
AGENT_VERSION="108.0.7.8810-1"
8+
TOOLS_VERSION="100.12.0"
9+
AGENT_DISTRO="rhel9_x86_64"
10+
TOOLS_DISTRO="rhel93-x86_64"
11+
docker buildx build --load --progress plain . -f docker/mongodb-agent/Dockerfile -t "mongodb-agent:${AGENT_VERSION}" \
12+
--build-arg version="${VERSION}" \
13+
--build-arg agent_version="${AGENT_VERSION}" \
14+
--build-arg tools_version="${TOOLS_VERSION}" \
15+
--build-arg agent_distro="${AGENT_DISTRO}" \
16+
--build-arg tools_distro="${TOOLS_DISTRO}"
17+
```

docker/mongodb-agent/Dockerfile

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
1-
ARG imagebase
2-
FROM ${imagebase} as base
1+
# the init database image gets supplied by pipeline.py and corresponds to the operator version we want to release
2+
# the agent with. This enables us to release the agent for older operator.
3+
ARG init_database_image
4+
FROM ${init_database_image} AS init_database
5+
6+
FROM public.ecr.aws/docker/library/golang:1.24 AS dependency_downloader
7+
8+
WORKDIR /go/src/github.com/mongodb/mongodb-kubernetes/
9+
10+
COPY go.mod go.sum ./
11+
12+
RUN go mod download
13+
14+
FROM public.ecr.aws/docker/library/golang:1.24 AS readiness_builder
15+
16+
WORKDIR /go/src/github.com/mongodb/mongodb-kubernetes/
17+
18+
COPY --from=dependency_downloader /go/pkg /go/pkg
19+
COPY . /go/src/github.com/mongodb/mongodb-kubernetes
20+
21+
RUN CGO_ENABLED=0 GOFLAGS=-buildvcs=false go build -o /readinessprobe ./mongodb-community-operator/cmd/readiness/main.go
22+
RUN CGO_ENABLED=0 GOFLAGS=-buildvcs=false go build -o /version-upgrade-hook ./mongodb-community-operator/cmd/versionhook/main.go
23+
24+
FROM scratch AS base
25+
ARG mongodb_tools_url_ubi
26+
ARG mongodb_agent_url_ubi
27+
28+
COPY --from=readiness_builder /readinessprobe /data/
29+
COPY --from=readiness_builder /version-upgrade-hook /data/
30+
31+
ADD ${mongodb_tools_url_ubi} /data/mongodb_tools_ubi.tgz
32+
ADD ${mongodb_agent_url_ubi} /data/mongodb_agent_ubi.tgz
33+
34+
COPY --from=init_database /probes/probe.sh /data/probe.sh
35+
COPY --from=init_database /scripts/agent-launcher-lib.sh /data/
36+
COPY --from=init_database /scripts/agent-launcher.sh /data/
37+
COPY --from=init_database /licenses/LICENSE /data/
338

439
FROM registry.access.redhat.com/ubi9/ubi-minimal
540

docker/mongodb-agent/Dockerfile.old

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
ARG imagebase
2+
FROM ${imagebase} as base
3+
4+
FROM registry.access.redhat.com/ubi9/ubi-minimal
5+
6+
ARG version
7+
8+
LABEL name="MongoDB Agent" \
9+
version="${version}" \
10+
summary="MongoDB Agent" \
11+
description="MongoDB Agent" \
12+
vendor="MongoDB" \
13+
release="1" \
14+
maintainer="[email protected]"
15+
16+
COPY --from=base /data/probe.sh /opt/scripts/probe.sh
17+
COPY --from=base /data/readinessprobe /opt/scripts/readinessprobe
18+
COPY --from=base /data/version-upgrade-hook /opt/scripts/version-upgrade-hook
19+
COPY --from=base /data/agent-launcher-lib.sh /opt/scripts/agent-launcher-lib.sh
20+
COPY --from=base /data/agent-launcher.sh /opt/scripts/agent-launcher.sh
21+
COPY --from=base /data/LICENSE /licenses/LICENSE
22+
23+
# Replace libcurl-minimal and curl-minimal with the full versions
24+
# https://bugzilla.redhat.com/show_bug.cgi?id=1994521
25+
RUN microdnf install -y libssh libpsl libbrotli \
26+
&& microdnf download curl libcurl \
27+
&& rpm -Uvh --nodeps --replacefiles "*curl*$( uname -i ).rpm" \
28+
&& microdnf remove -y libcurl-minimal curl-minimal
29+
30+
RUN microdnf install -y --disableplugin=subscription-manager --setopt=install_weak_deps=0 nss_wrapper
31+
# Copy-pasted from https://www.mongodb.com/docs/manual/tutorial/install-mongodb-enterprise-on-red-hat-tarball/
32+
RUN microdnf install -y --disableplugin=subscription-manager \
33+
cyrus-sasl cyrus-sasl-gssapi cyrus-sasl-plain krb5-libs openldap openssl xz-libs
34+
# Dependencies for the Agent
35+
RUN microdnf install -y --disableplugin=subscription-manager --setopt=install_weak_deps=0 \
36+
net-snmp \
37+
net-snmp-agent-libs
38+
RUN microdnf install -y --disableplugin=subscription-manager \
39+
hostname tar gzip procps jq \
40+
&& microdnf upgrade -y \
41+
&& rm -rf /var/lib/apt/lists/*
42+
43+
44+
COPY --from=base /data/mongodb_tools_ubi.tgz /tools/mongodb_tools.tgz
45+
COPY --from=base /data/mongodb_agent_ubi.tgz /agent/mongodb_agent.tgz
46+
47+
RUN tar xfz /tools/mongodb_tools.tgz
48+
RUN mv mongodb-database-tools-*/bin/* /tools
49+
RUN chmod +x /tools/*
50+
RUN rm /tools/mongodb_tools.tgz
51+
RUN rm -rf /mongodb-database-tools-*
52+
53+
RUN tar xfz /agent/mongodb_agent.tgz
54+
RUN mv mongodb-mms-automation-agent-*/mongodb-mms-automation-agent /agent/mongodb-agent
55+
RUN chmod +x /agent/mongodb-agent
56+
RUN rm /agent/mongodb_agent.tgz
57+
RUN rm -rf mongodb-mms-automation-agent-*
58+
59+
RUN mkdir -p /var/lib/automation/config
60+
RUN chmod -R +r /var/lib/automation/config
61+
62+
USER 2000
63+
64+
HEALTHCHECK --timeout=30s CMD ls /opt/scripts/readinessprobe || exit 1

docker/mongodb-agent/README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
# Mongodb-Agent
22
The agent gets released in a matrix style with the init-database image, which gets tagged with the operator version.
3-
This works by using the multi-stage pattern and build-args. First - retrieve the `init-database:<version>` and retrieve the
4-
binaries from there. Then we continue with the other steps to fully build the image.
3+
This works by using the multi-stage pattern and build-args. First - retrieve the `init-database:<version>` and retrieve the
4+
binaries from there. Then we continue with the other steps to fully build the image.
5+
6+
### Building locally
7+
8+
For building the MongoDB Agent image locally use the example command:
9+
10+
```bash
11+
VERSION="108.0.7.8810-1"
12+
INIT_DATABASE_IMAGE="268558157000.dkr.ecr.us-east-1.amazonaws.com/dev/mongodb-kubernetes-init-database:1.1.0"
13+
MONGODB_TOOLS_URL_UBI="https://downloads.mongodb.org/tools/db/mongodb-database-tools-rhel93-x86_64-100.12.0.tgz"
14+
MONGODB_AGENT_URL_UBI="https://mciuploads.s3.amazonaws.com/mms-automation/mongodb-mms-build-agent/builds/automation-agent/prod/mongodb-mms-automation-agent-108.0.7.8810-1.rhel9_x86_64.tar.gz"
15+
docker buildx build --load --progress plain . -f docker/mongodb-agent/Dockerfile -t "mongodb-agent:${VERSION}_1.1.0" \
16+
--build-arg version="${VERSION}" \
17+
--build-arg init_database_image="${INIT_DATABASE_IMAGE}" \
18+
--build-arg mongodb_tools_url_ubi="${MONGODB_TOOLS_URL_UBI}" \
19+
--build-arg mongodb_agent_url_ubi="${MONGODB_AGENT_URL_UBI}"
20+
```
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Build compilable stuff
2+
3+
FROM public.ecr.aws/docker/library/golang:1.24 AS readiness_builder
4+
COPY . /go/src/github.com/mongodb/mongodb-kubernetes
5+
WORKDIR /go/src/github.com/mongodb/mongodb-kubernetes
6+
7+
RUN CGO_ENABLED=0 go build -a -buildvcs=false -o /data/scripts/mmsconfiguration ./docker/mongodb-kubernetes-init-ops-manager/mmsconfiguration/edit_mms_configuration.go
8+
RUN CGO_ENABLED=0 go build -a -buildvcs=false -o /data/scripts/backup-daemon-readiness-probe ./docker/mongodb-kubernetes-init-ops-manager/backupdaemon_readinessprobe/backupdaemon_readiness.go
9+
10+
# Move binaries and scripts
11+
FROM scratch AS base
12+
13+
COPY --from=readiness_builder /data/scripts/mmsconfiguration /data/scripts/mmsconfiguration
14+
COPY --from=readiness_builder /data/scripts/backup-daemon-readiness-probe /data/scripts/backup-daemon-readiness-probe
15+
16+
# After v2.0, when non-Static Agent images will be removed, please ensure to copy those files
17+
# into ./docker/mongodb-enterprise-ops-manager directory. Leaving it this way will make the maintenance easier.
18+
COPY ./docker/mongodb-kubernetes-init-ops-manager/scripts/docker-entry-point.sh /data/scripts
19+
COPY ./docker/mongodb-kubernetes-init-ops-manager/scripts/backup-daemon-liveness-probe.sh /data/scripts
20+
COPY ./docker/mongodb-kubernetes-init-ops-manager/LICENSE /data/licenses/mongodb-enterprise-ops-manager
21+
22+
FROM registry.access.redhat.com/ubi9/ubi-minimal
23+
24+
ARG version
25+
ARG om_download_url
26+
27+
LABEL name="MongoDB Enterprise Ops Manager" \
28+
maintainer="[email protected]" \
29+
vendor="MongoDB" \
30+
version=${version} \
31+
release="1" \
32+
summary="MongoDB Enterprise Ops Manager Image" \
33+
description="MongoDB Enterprise Ops Manager"
34+
35+
ENV MMS_HOME=/mongodb-ops-manager
36+
ENV MMS_PROP_FILE=${MMS_HOME}/conf/conf-mms.properties
37+
ENV MMS_CONF_FILE=${MMS_HOME}/conf/mms.conf
38+
ENV MMS_LOG_DIR=${MMS_HOME}/logs
39+
ENV MMS_TMP_DIR=${MMS_HOME}/tmp
40+
41+
EXPOSE 8080
42+
43+
# OpsManager docker image needs to have the MongoDB dependencies because the
44+
# backup daemon is running its database locally
45+
46+
# Replace libcurl-minimal and curl-minimal with the full versions
47+
# https://bugzilla.redhat.com/show_bug.cgi?id=1994521
48+
RUN microdnf install -y libssh libpsl libbrotli \
49+
&& microdnf download curl libcurl \
50+
&& rpm -Uvh --nodeps --replacefiles "*curl*$( uname -i ).rpm" \
51+
&& microdnf remove -y libcurl-minimal curl-minimal
52+
53+
RUN microdnf install --disableplugin=subscription-manager -y \
54+
cyrus-sasl \
55+
cyrus-sasl-gssapi \
56+
cyrus-sasl-plain \
57+
krb5-libs \
58+
libpcap \
59+
lm_sensors-libs \
60+
net-snmp \
61+
net-snmp-agent-libs \
62+
openldap \
63+
openssl \
64+
tar \
65+
rpm-libs \
66+
net-tools \
67+
procps-ng \
68+
ncurses
69+
70+
COPY --from=base /data/licenses /licenses/
71+
COPY --from=base /data/scripts /opt/scripts
72+
73+
RUN curl --fail -L -o ops_manager.tar.gz ${om_download_url} \
74+
&& tar -xzf ops_manager.tar.gz \
75+
&& rm ops_manager.tar.gz \
76+
&& mv mongodb-mms* "${MMS_HOME}"
77+
78+
# permissions
79+
RUN chmod -R 0777 "${MMS_LOG_DIR}" \
80+
&& chmod -R 0777 "${MMS_TMP_DIR}" \
81+
&& chmod -R 0775 "${MMS_HOME}/conf" \
82+
&& chmod -R 0775 "${MMS_HOME}/jdk" \
83+
&& mkdir "${MMS_HOME}/mongodb-releases/" \
84+
&& chmod -R 0775 "${MMS_HOME}/mongodb-releases" \
85+
&& chmod -R 0777 "${MMS_CONF_FILE}" \
86+
&& chmod -R 0777 "${MMS_PROP_FILE}"
87+
88+
# The "${MMS_HOME}/conf" will be populated by the docker-entry-point.sh.
89+
# For now we need to move into the templates directory.
90+
RUN cp -r "${MMS_HOME}/conf" "${MMS_HOME}/conf-template"
91+
92+
USER 2000
93+
94+
# operator to change the entrypoint to: /mongodb-ops-manager/bin/mongodb-mms start_mms (or a wrapper around this)
95+
ENTRYPOINT [ "sleep infinity" ]

docker/mongodb-enterprise-ops-manager/Dockerfile.dcar

Lines changed: 0 additions & 25 deletions
This file was deleted.

docker/mongodb-enterprise-ops-manager/LICENSE

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)