Skip to content

[pipeline] add multiarch mco #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docker/mongodb-kubernetes-operator/Dockerfile.builder
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ FROM public.ecr.aws/docker/library/golang:1.24 as builder
ARG release_version
ARG log_automation_config_diff
ARG use_race
ARG TARGETOS
ARG TARGETARCH

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

Expand All @@ -22,14 +24,14 @@ RUN git version
RUN mkdir /build && \
if [ $use_race = "true" ]; then \
echo "Building with race detector" && \
CGO_ENABLED=1 go build -o /build/mongodb-kubernetes-operator \
CGO_ENABLED=1 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /build/mongodb-kubernetes-operator \
-buildvcs=false \
-race \
-ldflags=" -X github.com/mongodb/mongodb-kubernetes/pkg/util.OperatorVersion=${release_version} \
-X github.com/mongodb/mongodb-kubernetes/pkg/util.LogAutomationConfigDiff=${log_automation_config_diff}"; \
else \
echo "Building without race detector" && \
CGO_ENABLED=0 go build -o /build/mongodb-kubernetes-operator \
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /build/mongodb-kubernetes-operator \
-buildvcs=false \
-ldflags="-s -w -X github.com/mongodb/mongodb-kubernetes/pkg/util.OperatorVersion=${release_version} \
-X github.com/mongodb/mongodb-kubernetes/pkg/util.LogAutomationConfigDiff=${log_automation_config_diff}"; \
Expand Down
39 changes: 22 additions & 17 deletions inventory.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,39 @@ images:
vars:
context: .
template_context: docker/mongodb-kubernetes-operator
platform: linux/amd64
platform: linux/$(inputs.params.architecture)
inputs:
- version
- log_automation_config_diff
- architecture

stages:

- name: operator-context-dockerfile
- name: mongodb-kubernetes-context
task_type: docker_build
dockerfile: docker/mongodb-kubernetes-operator/Dockerfile.builder
buildargs:
release_version: $(inputs.params.version)
log_automation_config_diff: $(inputs.params.log_automation_config_diff)
use_race: "false"
TARGETOS: linux
TARGETARCH: $(inputs.params.architecture)
output:
- registry: $(inputs.params.registry)/operator-context
tag: $(inputs.params.version_id)
- registry: $(inputs.params.registry)/mongodb-kubernetes
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all of those repo changes should be fine as they are targeting $(inputs.params.registry) which points to ecr

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how that worked before? So we didn't publish -context images to quay at all? There is no operator-context repo in quay.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a stage in this file called operator-context-release (now called mongodb-kubernetes-release) which retags the image from ecr to quay. The quay_registry already contains image name and this didn't change.

tag: $(inputs.params.version_id)-context-$(inputs.params.architecture)

- name: operator-race-context-dockerfile
- name: operator-race-context
task_type: docker_build
dockerfile: docker/mongodb-kubernetes-operator/Dockerfile.builder
buildargs:
release_version: $(inputs.params.version)
log_automation_config_diff: $(inputs.params.log_automation_config_diff)
use_race: "true"
TARGETOS: linux
TARGETARCH: $(inputs.params.architecture)
output:
- registry: $(inputs.params.registry)/operator-context
tag: $(inputs.params.version_id)-race
- registry: $(inputs.params.registry)/mongodb-kubernetes
tag: $(inputs.params.version_id)-context-race-$(inputs.params.architecture)

- name: operator-template-ubi
task_type: dockerfile_template
Expand All @@ -50,39 +55,39 @@ images:
task_type: docker_build
dockerfile: $(stages['operator-template-ubi'].outputs[0].dockerfile)
buildargs:
imagebase: $(inputs.params.registry)/operator-context:$(inputs.params.version_id)
imagebase: $(inputs.params.registry)/mongodb-kubernetes:$(inputs.params.version_id)-context-$(inputs.params.architecture)
output:
- registry: $(inputs.params.registry)/mongodb-kubernetes
tag: $(inputs.params.version_id)
tag: $(inputs.params.version_id)-$(inputs.params.architecture)

- name: operator-ubi-race-build
task_type: docker_build
dockerfile: $(stages['operator-template-ubi'].outputs[0].dockerfile)
buildargs:
imagebase: $(inputs.params.registry)/operator-context:$(inputs.params.version_id)-race
imagebase: $(inputs.params.registry)/mongodb-kubernetes:$(inputs.params.version_id)-context-race-$(inputs.params.architecture)
output:
- registry: $(inputs.params.registry)/mongodb-kubernetes
tag: $(inputs.params.version_id)-race
tag: $(inputs.params.version_id)-race-$(inputs.params.architecture)

- name: master-latest
task_type: tag_image
tags: [ "master" ]
source:
registry: $(inputs.params.registry)/mongodb-kubernetes
tag: $(inputs.params.version_id)
tag: $(inputs.params.version_id)-$(inputs.params.architecture)
destination:
- registry: $(inputs.params.registry)/mongodb-kubernetes
tag: latest
tag: latest-$(inputs.params.architecture)

- name: operator-context-release
- name: mongodb-kubernetes-release
task_type: tag_image
tags: ["release"]
source:
registry: $(inputs.params.registry)/operator-context
tag: $(inputs.params.version_id)
registry: $(inputs.params.registry)/mongodb-kubernetes
tag: $(inputs.params.version_id)-context-$(inputs.params.architecture)
destination:
- registry: $(inputs.params.quay_registry)
tag: $(inputs.params.version)-context
tag: $(inputs.params.version)-context-$(inputs.params.architecture)

- name: operator-template-ubi
task_type: dockerfile_template
Expand Down
44 changes: 34 additions & 10 deletions pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,30 +483,54 @@ def build_mco_tests_image(build_configuration: BuildConfiguration):
sonar_build_image(image_name, build_configuration, buildargs, "inventories/mco_test.yaml")


TRACER.start_as_current_span("build_operator_image")


def build_operator_image(build_configuration: BuildConfiguration):
"""Calculates arguments required to build the operator image, and starts the build process."""
# In evergreen, we can pass test_suffix env to publish the operator to a quay
# repository with a given suffix.
test_suffix = os.environ.get("test_suffix", "")
log_automation_config_diff = os.environ.get("LOG_AUTOMATION_CONFIG_DIFF", "false")
version, _ = get_git_release_tag()
version, is_release = get_git_release_tag()

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

logger.info(f"Building Operator args: {args}")
multi_arch_args_list = []

for arch in architectures:
arch_args = {
"version": version,
"log_automation_config_diff": log_automation_config_diff,
"test_suffix": test_suffix,
"debug": build_configuration.debug,
"architecture": arch,
}
multi_arch_args_list.append(arch_args)

logger.info(f"Building Operator args: {multi_arch_args_list}")

image_name = "mongodb-kubernetes"

current_span = trace.get_current_span()
current_span.set_attribute("mck.image_name", image_name)
current_span.set_attribute("mck.architecture", architectures)

ecr_registry = os.environ.get("BASE_REPO_URL", "268558157000.dkr.ecr.us-east-1.amazonaws.com/dev")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we should fail if not set. We should require running it with some context at least.

base_repo = QUAY_REGISTRY_URL if is_release else ecr_registry
Comment on lines +524 to +525
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is needed. Looking into the definition of build_image_generic I see that registry_address is set to the quay_registry arg in sonar. In the operator_build_configuration method we already read BASE_REPO_URL and set it in the registry arg for sonar.


build_image_generic(
config=build_configuration,
image_name=image_name,
inventory_file="inventory.yaml",
extra_args=args,
registry_address=f"{QUAY_REGISTRY_URL}/{image_name}",
registry_address=f"{base_repo}/{image_name}",
multi_arch_args_list=multi_arch_args_list,
is_multi_arch=True,
)


Expand Down
1 change: 1 addition & 0 deletions scripts/evergreen/release/helm_files_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def update_standalone_installer(yaml_file_path: str, version: str):
yaml.explicit_start = True # Ensure explicit `---` in the output
yaml.indent(mapping=2, sequence=4, offset=2) # Align with tab width produced by Helm
yaml.preserve_quotes = True # Preserve original quotes in the YAML file
yaml.width = 4096 # Set a very large line width to prevent inconsistent line wrapping

with open(yaml_file_path, "r") as fd:
data = list(yaml.load_all(fd)) # Convert the generator to a list
Expand Down
6 changes: 3 additions & 3 deletions scripts/evergreen/release/update_helm_values_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def main() -> int:


def update_standalone(operator_version):
update_standalone_installer("public/mongodb-kubernetes.yaml", operator_version),
update_standalone_installer("public/mongodb-kubernetes-openshift.yaml", operator_version),
update_standalone_installer("public/mongodb-kubernetes-multi-cluster.yaml", operator_version),
update_standalone_installer("public/mongodb-kubernetes.yaml", operator_version)
update_standalone_installer("public/mongodb-kubernetes-openshift.yaml", operator_version)
update_standalone_installer("public/mongodb-kubernetes-multi-cluster.yaml", operator_version)


def update_helm_charts(operator_version, release):
Expand Down