Skip to content

Commit 3e482c3

Browse files
authored
CLOUDP-333692: Re-design images building (#303)
# Re-design images building ## Note for review: Since `atomic_pipeline.py` is largely a refactored version of `pipeline.py`, it’s much clearer to review their side-by-side diff than to wade through GitHub’s “all new lines” view. Here's the diff: https://gist.github.com/Julien-Ben/3698d532d17bafb380f2e4f05b5db153 You can also take a look at the related [TD Section](https://docs.google.com/document/d/1eJ8iKsI0libbpcJakGjxcPfbrTn8lmcZDbQH1UqMR_g/edit?tab=t.thts6hu4qyrq) # Changes The PR refactors our Docker image build system. Most notably by replacing `pipeline.py` along with other components, detailed below. ## Usage of standalone Dockerfiles Added in a previous PR, they eliminate the need for templating, and make it possible to **retire Sonar** once the Atomic Releases Epic is completed. ## Building with docker buildx, multi-platform builds In `build_images.py` we use docker buildx through a python API. It eliminates the need for building images separately for each platform (ARM/AMD), and then manually bundling them in a manifest. ## Handle build environments explicitly We’ve introduced a framework that centralizes build configuration by scenario (e.g local development, staging releases etc) so the pipeline automatically picks sensible defaults (registry, target platforms, signing flags, and more) based on where you’re running. In `pipeline_main.py` (with support from `build_configuration.py` and `build_context.py`) we treat each execution context (local dev, merge to master, release etc...) as an explicit, top-level environment. It infers defaults automatically but lets you override any value via CLI flags, ensuring all build parameters live in one single source of truth rather than scattered through pipeline scripts. ## CLI usage ``` usage: pipeline_main.py [-h] [--parallel] [--debug] [--sign] [--scenario {BuildScenario.RELEASE,BuildScenario.PATCH,BuildScenario.STAGING,BuildScenario.DEVELOPMENT}] [--platform PLATFORM] [--version VERSION] [--registry REGISTRY] [--parallel-factor PARALLEL_FACTOR] image Build container images. positional arguments: image Image to build. options: -h, --help show this help message and exit --parallel Build images in parallel. --debug Enable debug logging. --sign Sign images. --scenario {BuildScenario.RELEASE,BuildScenario.PATCH,BuildScenario.STAGING,BuildScenario.DEVELOPMENT} Override the build scenario instead of inferring from environment. Options: release, patch, master, development --platform PLATFORM Target platforms for multi-arch builds (comma-separated). Example: linux/amd64,linux/arm64. Defaults to linux/amd64. --version VERSION Override the version/tag instead of resolving from build scenario --registry REGISTRY Override the base registry instead of resolving from build scenario --parallel-factor PARALLEL_FACTOR Number of builds to run in parallel, defaults to number of cores ``` # Proof of work CI is building images with the new pipeline, and tests pass. # Note For the duration of the Atomic Releases epic, both pipelines will be in the repository, until we are done with the staging and promotion process. This new pipeline will only be used for Evergreen patches. This PR also heavily depends on changes that are introduced by the agent matrix removal, and the multi-platform support epic. The existing Evergreen function, that uses `pipeline.py` has been renamed `legacy_pipeline`, and is used for release and periodic builds tasks. A new one has been created, calling the new pipeline. Once the Atomic Release Epic is complete, we'll be able to remove: - Sonar - Inventories - Periodic builds - `pipeline.py` Follow up ticket to this PR: https://jira.mongodb.org/browse/CLOUDP-335471
1 parent 79ae98d commit 3e482c3

File tree

12 files changed

+1026
-40
lines changed

12 files changed

+1026
-40
lines changed

.evergreen-functions.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,43 @@ functions:
505505
- ${workdir}
506506

507507
pipeline:
508+
- *switch_context
509+
- command: shell.exec
510+
type: setup
511+
params:
512+
shell: bash
513+
script: |
514+
# Docker Hub workaround
515+
# docker buildx needs the moby/buildkit image when setting up a builder so we pull it from our mirror
516+
docker buildx create --driver=docker-container --driver-opt=image=268558157000.dkr.ecr.eu-west-1.amazonaws.com/docker-hub-mirrors/moby/buildkit:buildx-stable-1 --use
517+
docker buildx inspect --bootstrap
518+
- command: ec2.assume_role
519+
display_name: Assume IAM role with permissions to pull Kondukto API token
520+
params:
521+
role_arn: ${kondukto_role_arn}
522+
- command: shell.exec
523+
display_name: Pull Kondukto API token from AWS Secrets Manager and write it to file
524+
params:
525+
silent: true
526+
shell: bash
527+
include_expansions_in_env: [AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN]
528+
script: |
529+
set -e
530+
# use AWS CLI to get the Kondukto API token from AWS Secrets Manager
531+
kondukto_token=$(aws secretsmanager get-secret-value --secret-id "kondukto-token" --region "us-east-1" --query 'SecretString' --output text)
532+
# write the KONDUKTO_TOKEN environment variable to Silkbomb environment file
533+
echo "KONDUKTO_TOKEN=$kondukto_token" > ${workdir}/silkbomb.env
534+
- command: subprocess.exec
535+
retry_on_failure: true
536+
type: setup
537+
params:
538+
shell: bash
539+
<<: *e2e_include_expansions_in_env
540+
working_dir: src/github.com/mongodb/mongodb-kubernetes
541+
binary: scripts/dev/run_python.sh scripts/release/pipeline_main.py --parallel ${image_name}
542+
543+
# TODO: CLOUDP-335471 ; once all image builds are made with the new atomic pipeline, remove the following function
544+
legacy_pipeline:
508545
- *switch_context
509546
- command: shell.exec
510547
type: setup

.evergreen-periodic-builds.yaml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ variables:
2121
tasks:
2222
- name: periodic_build_operator
2323
commands:
24-
- func: pipeline
24+
- func: legacy_pipeline
2525
vars:
2626
image_name: operator-daily
2727

@@ -35,49 +35,49 @@ tasks:
3535

3636
- name: periodic_build_init_appdb
3737
commands:
38-
- func: pipeline
38+
- func: legacy_pipeline
3939
vars:
4040
image_name: init-appdb-daily
4141

4242
- name: periodic_build_init_database
4343
commands:
44-
- func: pipeline
44+
- func: legacy_pipeline
4545
vars:
4646
image_name: init-database-daily
4747

4848
- name: periodic_build_init_opsmanager
4949
commands:
50-
- func: pipeline
50+
- func: legacy_pipeline
5151
vars:
5252
image_name: init-ops-manager-daily
5353

5454
- name: periodic_build_database
5555
commands:
56-
- func: pipeline
56+
- func: legacy_pipeline
5757
vars:
5858
image_name: database-daily
5959

6060
- name: periodic_build_sbom_cli
6161
commands:
62-
- func: pipeline
62+
- func: legacy_pipeline
6363
vars:
6464
image_name: cli
6565

6666
- name: periodic_build_ops_manager_6
6767
commands:
68-
- func: pipeline
68+
- func: legacy_pipeline
6969
vars:
7070
image_name: ops-manager-6-daily
7171

7272
- name: periodic_build_ops_manager_7
7373
commands:
74-
- func: pipeline
74+
- func: legacy_pipeline
7575
vars:
7676
image_name: ops-manager-7-daily
7777

7878
- name: periodic_build_ops_manager_8
7979
commands:
80-
- func: pipeline
80+
- func: legacy_pipeline
8181
vars:
8282
image_name: ops-manager-8-daily
8383

@@ -91,15 +91,15 @@ tasks:
9191
exec_timeout_secs: 43200
9292
commands:
9393
- func: enable_QEMU
94-
- func: pipeline
94+
- func: legacy_pipeline
9595
vars:
9696
image_name: mongodb-agent-daily
9797

9898
- name: periodic_build_agent_1
9999
exec_timeout_secs: 43200
100100
commands:
101101
- func: enable_QEMU
102-
- func: pipeline
102+
- func: legacy_pipeline
103103
vars:
104104
image_name: mongodb-agent-1-daily
105105

@@ -123,19 +123,19 @@ tasks:
123123
- name: periodic_build_community_operator
124124
commands:
125125
- func: enable_QEMU
126-
- func: pipeline
126+
- func: legacy_pipeline
127127
vars:
128128
image_name: mongodb-kubernetes-operator-daily
129129

130130
- name: periodic_build_readiness_probe
131131
commands:
132-
- func: pipeline
132+
- func: legacy_pipeline
133133
vars:
134134
image_name: readinessprobe-daily
135135

136136
- name: periodic_build_version_upgrade_post_start_hook
137137
commands:
138-
- func: pipeline
138+
- func: legacy_pipeline
139139
vars:
140140
image_name: operator-version-upgrade-post-start-hook-daily
141141

.evergreen.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ tasks:
283283
- func: setup_building_host
284284
- func: quay_login
285285
- func: setup_docker_sbom
286-
- func: pipeline
286+
- func: legacy_pipeline
287287
vars:
288288
image_name: operator
289289
include_tags: release
@@ -297,7 +297,7 @@ tasks:
297297
- func: setup_building_host
298298
- func: quay_login
299299
- func: setup_docker_sbom
300-
- func: pipeline
300+
- func: legacy_pipeline
301301
vars:
302302
image_name: init-appdb
303303
include_tags: release
@@ -310,7 +310,7 @@ tasks:
310310
- func: setup_building_host
311311
- func: quay_login
312312
- func: setup_docker_sbom
313-
- func: pipeline
313+
- func: legacy_pipeline
314314
vars:
315315
image_name: init-database
316316
include_tags: release
@@ -323,7 +323,7 @@ tasks:
323323
- func: setup_building_host
324324
- func: quay_login
325325
- func: setup_docker_sbom
326-
- func: pipeline
326+
- func: legacy_pipeline
327327
vars:
328328
image_name: init-ops-manager
329329
include_tags: release
@@ -336,7 +336,7 @@ tasks:
336336
- func: setup_building_host
337337
- func: quay_login
338338
- func: setup_docker_sbom
339-
- func: pipeline
339+
- func: legacy_pipeline
340340
vars:
341341
image_name: agent
342342
include_tags: release
@@ -350,7 +350,7 @@ tasks:
350350
- func: setup_building_host
351351
- func: quay_login
352352
- func: setup_docker_sbom
353-
- func: pipeline
353+
- func: legacy_pipeline
354354
vars:
355355
image_name: agent-pct
356356
include_tags: release
@@ -395,7 +395,7 @@ tasks:
395395
commands:
396396
- func: clone
397397
- func: setup_building_host
398-
- func: pipeline
398+
- func: legacy_pipeline
399399
vars:
400400
image_name: agent-pct
401401
skip_tags: release
@@ -410,7 +410,7 @@ tasks:
410410
commands:
411411
- func: clone
412412
- func: setup_building_host
413-
- func: pipeline
413+
- func: legacy_pipeline
414414
vars:
415415
image_name: agent-pct
416416
skip_tags: release
@@ -551,7 +551,7 @@ tasks:
551551
- func: setup_building_host
552552
- func: quay_login
553553
- func: setup_docker_sbom
554-
- func: pipeline
554+
- func: legacy_pipeline
555555
vars:
556556
image_name: database
557557

@@ -570,7 +570,7 @@ tasks:
570570
- func: setup_building_host
571571
- func: quay_login
572572
- func: setup_docker_sbom
573-
- func: pipeline
573+
- func: legacy_pipeline
574574
vars:
575575
image_name: ops-manager
576576
include_tags: release

Makefile

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ operator: configure-operator build-and-push-operator-image
7575

7676
# build-push, (todo) restart database
7777
database: aws_login
78-
@ scripts/dev/run_python.sh pipeline.py --include database
78+
@ scripts/dev/run_python.sh scripts/release/pipeline_main.py database
7979

8080
readiness_probe: aws_login
81-
@ scripts/dev/run_python.sh pipeline.py --include readiness-probe
81+
@ scripts/dev/run_python.sh scripts/release/pipeline_main.py readiness-probe
8282

8383
upgrade_hook: aws_login
84-
@ scripts/dev/run_python.sh pipeline.py --include upgrade-hook
84+
@ scripts/dev/run_python.sh scripts/release/pipeline_main.py upgrade-hook
8585

8686
# ensures cluster is up, cleans Kubernetes + OM, build-push-deploy operator,
8787
# push-deploy database, create secrets, config map, resources etc
@@ -90,7 +90,7 @@ full: build-and-push-images
9090

9191
# build-push appdb image
9292
appdb: aws_login
93-
@ scripts/dev/run_python.sh pipeline.py --include appdb
93+
@ scripts/dev/run_python.sh scripts/release/pipeline_main.py --include appdb
9494

9595
# runs the e2e test: make e2e test=e2e_sharded_cluster_pv. The Operator is redeployed before the test, the namespace is cleaned.
9696
# The e2e test image is built and pushed together with all main ones (operator, database, init containers)
@@ -154,19 +154,19 @@ aws_cleanup:
154154
@ scripts/evergreen/prepare_aws.sh
155155

156156
build-and-push-operator-image: aws_login
157-
@ scripts/dev/run_python.sh pipeline.py --include operator-quick
157+
@ scripts/dev/run_python.sh scripts/release/pipeline_main.py operator
158158

159159
build-and-push-database-image: aws_login
160160
@ scripts/dev/build_push_database_image
161161

162162
build-and-push-test-image: aws_login build-multi-cluster-binary
163163
@ if [[ -z "$(local)" ]]; then \
164-
scripts/dev/run_python.sh pipeline.py --include test; \
164+
scripts/dev/run_python.sh scripts/release/pipeline_main.py test; \
165165
fi
166166

167167
build-and-push-mco-test-image: aws_login
168168
@ if [[ -z "$(local)" ]]; then \
169-
scripts/dev/run_python.sh pipeline.py --include mco-test; \
169+
scripts/dev/run_python.sh scripts/release/pipeline_main.py mco-test; \
170170
fi
171171

172172
build-multi-cluster-binary:
@@ -181,27 +181,27 @@ build-and-push-images: build-and-push-operator-image appdb-init-image om-init-im
181181
build-and-push-init-images: appdb-init-image om-init-image database-init-image
182182

183183
database-init-image:
184-
@ scripts/dev/run_python.sh pipeline.py --include init-database
184+
@ scripts/dev/run_python.sh scripts/release/pipeline_main.py init-database
185185

186186
appdb-init-image:
187-
@ scripts/dev/run_python.sh pipeline.py --include init-appdb
187+
@ scripts/dev/run_python.sh scripts/release/pipeline_main.py init-appdb
188188

189189
# Not setting a parallel-factor will default to 0 which will lead to using all CPUs, that can cause docker to die.
190190
# Here we are defaulting to 6, a higher value might work for you.
191191
agent-image:
192-
@ scripts/dev/run_python.sh pipeline.py --include agent --all-agents --parallel --parallel-factor 6
192+
@ scripts/dev/run_python.sh scripts/release/pipeline_main.py --parallel --parallel-factor 6 agent
193193

194194
agent-image-slow:
195-
@ scripts/dev/run_python.sh pipeline.py --include agent --parallel-factor 1
195+
@ scripts/dev/run_python.sh scripts/release/pipeline_main.py --parallel-factor 1 agent
196196

197197
operator-image:
198-
@ scripts/dev/run_python.sh pipeline.py --include operator
198+
@ scripts/dev/run_python.sh scripts/release/pipeline_main.py operator
199199

200200
om-init-image:
201-
@ scripts/dev/run_python.sh pipeline.py --include init-ops-manager
201+
@ scripts/dev/run_python.sh scripts/release/pipeline_main.py init-ops-manager
202202

203203
om-image:
204-
@ scripts/dev/run_python.sh pipeline.py --include ops-manager
204+
@ scripts/dev/run_python.sh scripts/release/pipeline_main.py ops-manager
205205

206206
configure-operator:
207207
@ scripts/dev/configure_operator.sh

docker/mongodb-kubernetes-readinessprobe/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ WORKDIR /go/src
44
ADD . .
55

66
ARG TARGETARCH
7-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build -a -o /data/scripts/readinessprobe ./mongodb-community-operator/cmd/readiness/main.go
7+
ARG TARGETOS
8+
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -a -o /data/scripts/readinessprobe ./mongodb-community-operator/cmd/readiness/main.go
89

910
FROM registry.access.redhat.com/ubi9/ubi-minimal
1011

docker/mongodb-kubernetes-upgrade-hook/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ WORKDIR /go/src
44
ADD . .
55

66
ARG TARGETARCH
7-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build -a -o /data/scripts/version-upgrade-hook ./mongodb-community-operator/cmd/versionhook/main.go
7+
ARG TARGETOS
8+
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -a -o /data/scripts/version-upgrade-hook ./mongodb-community-operator/cmd/versionhook/main.go
89

910
FROM registry.access.redhat.com/ubi9/ubi-minimal
1011

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ wrapt==1.17.2
3434
botocore==1.39.4
3535
boto3==1.39.4
3636
python-frontmatter==1.1.0
37+
python-on-whales==0.78.0
3738

3839
# from kubeobject
3940
freezegun==1.5.3

0 commit comments

Comments
 (0)