Skip to content

Commit 9ec721a

Browse files
authored
[pipeline] add multiarch mco (#156)
# Summary - adding multiarch to the operator ## Proof of Work - passing [ci](https://spruce.mongodb.com/task/mongodb_kubernetes_init_test_run_build_operator_ubi_patch_ca24d93d7a931f7853a679b4576674cace37bb16_68529dd6c138970007119b4f_25_06_18_11_07_03/logs?execution=0) while skipping arm - passing [ci](https://spruce.mongodb.com/version/6852aae56808a40007526b93/tasks?sorts=STATUS%3AASC%3BBASE_STATUS%3ADESC) while running arm build - pulling multiarch image ``` docker run --rm -it --platform linux/arm64 --entrypoint sh 268558157000.dkr.ecr.us-east-1.amazonaws.com/dev/mongodb-kubernetes:6852aae56808a40007526b93 Unable to find image '268558157000.dkr.ecr.us-east-1.amazonaws.com/dev/mongodb-kubernetes:6852aae56808a40007526b93' locally 6852aae56808a40007526b93: Pulling from dev/mongodb-kubernetes 88dac9674920: Already exists 01860f9dcfa8: Pull complete ef547372e92b: Pull complete e177c021bea7: Pull complete f10b6cc419b7: Pull complete 05a62aa57d3f: Pull complete Digest: sha256:5c158225fad4d9b92b28b43e034f46eaacc6488e74846e3e22fc6e5d0b243e05 Status: Downloaded newer image for 268558157000.dkr.ecr.us-east-1.amazonaws.com/dev/mongodb-kubernetes:6852aae56808a40007526b93 sh-5.1$ uname -a Linux 0c05ec3b5548 6.10.14-linuxkit #1 SMP Tue Apr 15 16:00:54 UTC 2025 aarch64 aarch64 aarch64 GNU/Linux sh-5.1$ ``` ``` (venv) ~/projects/mongodb-kubernetes git:[multi-arch-mco] docker run --rm -it --platform linux/amd64 --entrypoint sh 268558157000.dkr.ecr.us-east-1.amazonaws.com/dev/mongodb-kubernetes:6852aae56808a40007526b93 Unable to find image '268558157000.dkr.ecr.us-east-1.amazonaws.com/dev/mongodb-kubernetes:6852aae56808a40007526b93' locally 6852aae56808a40007526b93: Pulling from dev/mongodb-kubernetes ff6f4d5fce2a: Already exists 8c4dc0e68dba: Pull complete 433bb9a7e77e: Pull complete 3f00ac9cf359: Pull complete 11b2571dd667: Pull complete 05a62aa57d3f: Pull complete Digest: sha256:5c158225fad4d9b92b28b43e034f46eaacc6488e74846e3e22fc6e5d0b243e05 Status: Downloaded newer image for 268558157000.dkr.ecr.us-east-1.amazonaws.com/dev/mongodb-kubernetes:6852aae56808a40007526b93 sh-5.1$ uname -a Linux 03d6c9cd16d9 6.10.14-linuxkit #1 SMP Tue Apr 15 16:00:54 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux ``` ## Checklist - [ ] Have you linked a jira ticket and/or is the ticket in the title? - [ ] Have you checked whether your jira ticket required DOCSP changes? - [ ] Have you checked for release_note changes? ## Reminder (Please remove this when merging) - Please try to Approve or Reject Changes the PR, keep PRs in review as short as possible - Our Short Guide for PRs: [Link](https://docs.google.com/document/d/1T93KUtdvONq43vfTfUt8l92uo4e4SEEvFbIEKOxGr44/edit?tab=t.0) - Remember the following Communication Standards - use comment prefixes for clarity: * **blocking**: Must be addressed before approval. * **follow-up**: Can be addressed in a later PR or ticket. * **q**: Clarifying question. * **nit**: Non-blocking suggestions. * **note**: Side-note, non-actionable. Example: Praise * --> no prefix is considered a question
1 parent e5a8641 commit 9ec721a

File tree

3 files changed

+60
-28
lines changed

3 files changed

+60
-28
lines changed

docker/mongodb-kubernetes-operator/Dockerfile.builder

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ FROM public.ecr.aws/docker/library/golang:1.24 as builder
99
ARG release_version
1010
ARG log_automation_config_diff
1111
ARG use_race
12+
ARG TARGETOS
13+
ARG TARGETARCH
1214

1315
COPY go.sum go.mod /go/src/github.com/mongodb/mongodb-kubernetes/
1416

@@ -22,14 +24,14 @@ RUN git version
2224
RUN mkdir /build && \
2325
if [ $use_race = "true" ]; then \
2426
echo "Building with race detector" && \
25-
CGO_ENABLED=1 go build -o /build/mongodb-kubernetes-operator \
27+
CGO_ENABLED=1 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /build/mongodb-kubernetes-operator \
2628
-buildvcs=false \
2729
-race \
2830
-ldflags=" -X github.com/mongodb/mongodb-kubernetes/pkg/util.OperatorVersion=${release_version} \
2931
-X github.com/mongodb/mongodb-kubernetes/pkg/util.LogAutomationConfigDiff=${log_automation_config_diff}"; \
3032
else \
3133
echo "Building without race detector" && \
32-
CGO_ENABLED=0 go build -o /build/mongodb-kubernetes-operator \
34+
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /build/mongodb-kubernetes-operator \
3335
-buildvcs=false \
3436
-ldflags="-s -w -X github.com/mongodb/mongodb-kubernetes/pkg/util.OperatorVersion=${release_version} \
3537
-X github.com/mongodb/mongodb-kubernetes/pkg/util.LogAutomationConfigDiff=${log_automation_config_diff}"; \

inventory.yaml

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,39 @@ images:
88
vars:
99
context: .
1010
template_context: docker/mongodb-kubernetes-operator
11-
platform: linux/amd64
11+
platform: linux/$(inputs.params.architecture)
1212
inputs:
1313
- version
1414
- log_automation_config_diff
15+
- architecture
1516

1617
stages:
1718

18-
- name: operator-context-dockerfile
19+
- name: mongodb-kubernetes-context
1920
task_type: docker_build
2021
dockerfile: docker/mongodb-kubernetes-operator/Dockerfile.builder
2122
buildargs:
2223
release_version: $(inputs.params.version)
2324
log_automation_config_diff: $(inputs.params.log_automation_config_diff)
2425
use_race: "false"
26+
TARGETOS: linux
27+
TARGETARCH: $(inputs.params.architecture)
2528
output:
26-
- registry: $(inputs.params.registry)/operator-context
27-
tag: $(inputs.params.version_id)
29+
- registry: $(inputs.params.registry)/mongodb-kubernetes
30+
tag: $(inputs.params.version_id)-context-$(inputs.params.architecture)
2831

29-
- name: operator-race-context-dockerfile
32+
- name: operator-race-context
3033
task_type: docker_build
3134
dockerfile: docker/mongodb-kubernetes-operator/Dockerfile.builder
3235
buildargs:
3336
release_version: $(inputs.params.version)
3437
log_automation_config_diff: $(inputs.params.log_automation_config_diff)
3538
use_race: "true"
39+
TARGETOS: linux
40+
TARGETARCH: $(inputs.params.architecture)
3641
output:
37-
- registry: $(inputs.params.registry)/operator-context
38-
tag: $(inputs.params.version_id)-race
42+
- registry: $(inputs.params.registry)/mongodb-kubernetes
43+
tag: $(inputs.params.version_id)-context-race-$(inputs.params.architecture)
3944

4045
- name: operator-template-ubi
4146
task_type: dockerfile_template
@@ -50,16 +55,17 @@ images:
5055
task_type: docker_build
5156
dockerfile: $(stages['operator-template-ubi'].outputs[0].dockerfile)
5257
buildargs:
53-
imagebase: $(inputs.params.registry)/operator-context:$(inputs.params.version_id)
58+
imagebase: $(inputs.params.registry)/mongodb-kubernetes:$(inputs.params.version_id)-context-$(inputs.params.architecture)
5459
output:
5560
- registry: $(inputs.params.registry)/mongodb-kubernetes
56-
tag: $(inputs.params.version_id)
61+
tag: $(inputs.params.version_id)-$(inputs.params.architecture)
5762

63+
# we don't do multi-arch for race images; so we can just directly release it
5864
- name: operator-ubi-race-build
5965
task_type: docker_build
6066
dockerfile: $(stages['operator-template-ubi'].outputs[0].dockerfile)
6167
buildargs:
62-
imagebase: $(inputs.params.registry)/operator-context:$(inputs.params.version_id)-race
68+
imagebase: $(inputs.params.registry)/mongodb-kubernetes:$(inputs.params.version_id)-context-race-$(inputs.params.architecture)
6369
output:
6470
- registry: $(inputs.params.registry)/mongodb-kubernetes
6571
tag: $(inputs.params.version_id)-race
@@ -69,20 +75,20 @@ images:
6975
tags: [ "master" ]
7076
source:
7177
registry: $(inputs.params.registry)/mongodb-kubernetes
72-
tag: $(inputs.params.version_id)
78+
tag: $(inputs.params.version_id)-$(inputs.params.architecture)
7379
destination:
7480
- registry: $(inputs.params.registry)/mongodb-kubernetes
75-
tag: latest
81+
tag: latest-$(inputs.params.architecture)
7682

77-
- name: operator-context-release
83+
- name: mongodb-kubernetes-release
7884
task_type: tag_image
7985
tags: ["release"]
8086
source:
81-
registry: $(inputs.params.registry)/operator-context
82-
tag: $(inputs.params.version_id)
87+
registry: $(inputs.params.registry)/mongodb-kubernetes
88+
tag: $(inputs.params.version_id)-context-$(inputs.params.architecture)
8389
destination:
8490
- registry: $(inputs.params.quay_registry)
85-
tag: $(inputs.params.version)-context
91+
tag: $(inputs.params.version)-context-$(inputs.params.architecture)
8692

8793
- name: operator-template-ubi
8894
task_type: dockerfile_template

pipeline.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -483,30 +483,54 @@ def build_mco_tests_image(build_configuration: BuildConfiguration):
483483
sonar_build_image(image_name, build_configuration, buildargs, "inventories/mco_test.yaml")
484484

485485

486+
TRACER.start_as_current_span("build_operator_image")
487+
488+
486489
def build_operator_image(build_configuration: BuildConfiguration):
487490
"""Calculates arguments required to build the operator image, and starts the build process."""
488491
# In evergreen, we can pass test_suffix env to publish the operator to a quay
489492
# repository with a given suffix.
490493
test_suffix = os.environ.get("test_suffix", "")
491494
log_automation_config_diff = os.environ.get("LOG_AUTOMATION_CONFIG_DIFF", "false")
492-
version, _ = get_git_release_tag()
495+
version, is_release = get_git_release_tag()
493496

494-
args = {
495-
"version": version,
496-
"log_automation_config_diff": log_automation_config_diff,
497-
"test_suffix": test_suffix,
498-
"debug": build_configuration.debug,
499-
}
497+
# Use only amd64 if we should skip arm64 builds
498+
if should_skip_arm64(build_configuration):
499+
architectures = ["amd64"]
500+
logger.info("Skipping ARM64 builds for operator image as this is running in EVG pipeline as a patch")
501+
else:
502+
architectures = build_configuration.architecture or ["amd64", "arm64"]
500503

501-
logger.info(f"Building Operator args: {args}")
504+
multi_arch_args_list = []
505+
506+
for arch in architectures:
507+
arch_args = {
508+
"version": version,
509+
"log_automation_config_diff": log_automation_config_diff,
510+
"test_suffix": test_suffix,
511+
"debug": build_configuration.debug,
512+
"architecture": arch,
513+
}
514+
multi_arch_args_list.append(arch_args)
515+
516+
logger.info(f"Building Operator args: {multi_arch_args_list}")
502517

503518
image_name = "mongodb-kubernetes"
519+
520+
current_span = trace.get_current_span()
521+
current_span.set_attribute("mck.image_name", image_name)
522+
current_span.set_attribute("mck.architecture", architectures)
523+
524+
ecr_registry = os.environ.get("BASE_REPO_URL", "268558157000.dkr.ecr.us-east-1.amazonaws.com/dev")
525+
base_repo = QUAY_REGISTRY_URL if is_release else ecr_registry
526+
504527
build_image_generic(
505528
config=build_configuration,
506529
image_name=image_name,
507530
inventory_file="inventory.yaml",
508-
extra_args=args,
509-
registry_address=f"{QUAY_REGISTRY_URL}/{image_name}",
531+
registry_address=f"{base_repo}/{image_name}",
532+
multi_arch_args_list=multi_arch_args_list,
533+
is_multi_arch=True,
510534
)
511535

512536

0 commit comments

Comments
 (0)