Skip to content

Commit 7ea875e

Browse files
Fix the image build process for release repository (#762)
# Summary While [releasing the MCK 1.7.0](https://spruce.mongodb.com/version/mongodb_kubernetes_1.7.0_698a552d2879870007b70e36/tasks?sorts=STATUS%3AASC%3BBASE_STATUS%3ADESC) we got into some strange issues where the tasks that release the images failed with error like this ``` [2026/02/09 23:03:44.088] ERROR: EOF [2026/02/09 23:03:44.088] ERROR 2026-02-09 22:03:44,088 [image_build_process] Failed to build image ['quay.io/mongodb/mongodb-kubernetes-database:1.7.0', 'quay.io/mongodb/mongodb-kubernetes-database:1.7.0-olm-20260209220344']: The command executed was `/usr/bin/docker buildx build --build-arg version=1.7.0 --builder multiarch --provenance=false --push --file docker/mongodb-kubernetes-database/Dockerfile --cache-to --platform linux/arm64,linux/amd64,linux/s390x,linux/ppc64le --tag quay.io/mongodb/mongodb-kubernetes-database:1.7.0 --tag quay.io/mongodb/mongodb-kubernetes-database:1.7.0-olm-20260209220344 .`. [2026/02/09 23:03:44.088] It returned with code 1 [2026/02/09 23:03:44.088] The content of stdout is '' ``` If we notice the command that was executed to build/push the image it has empty `--cache-to` and because of that the `docker buildx biuld` command fails with `ERROR: EOF`. This was happening because in `_build_cache` we returned `{}` as `cache_to_refs` for non ECR registries ``` def _build_cache(self, tags: list[str]) -> tuple[list[Any], dict[str, str]]: """ Build cache configuration for the given tags. Only ECR tags trigger caching because our CI infrastructure uses ECR for remote cache storage. Local or other registry builds skip caching to avoid authentication failures. :param tags: List of image tags :return: Tuple of (cache_from_refs, cache_to_refs) """ # Filter tags to only include ECR ones (containing ".dkr.ecr.") ecr_tags = [tag for tag in tags if ".dkr.ecr." in tag] if not ecr_tags: return [], {} ``` and returned `{}` resulted into `docker buildx build --cache-to --other-flags ...` because that's how `python_on_whales` works. This PR fixes that issue by returning `None` instead to `{}` and if `None` gets returned `python_on_whales` makes sure that flag `--cache-to` is not added to the `docker buildx build` command. ## Proof of Work I added a simple function to print the command that gets created and this is what I saw ```bash For this call: docker.buildx.build( context_path=".", tags=["test-image:latest"], file="Dockerfile", build_args={"ARG1": "value1", "ARG2": "value2"}, labels={"label1": "val1"}, cache=True, load=True, cache_to=None ) full cmd is [PosixPath('/usr/local/bin/docker'), 'buildx', 'build', '--build-arg', 'ARG1=value1', '--build-arg', 'ARG2=value2', '--label', 'label1=val1', '--load', '--file', 'Dockerfile', '--tag', 'test-image:latest'] For this call: docker.buildx.build( context_path=".", tags=["test-image:latest"], file="Dockerfile", build_args={"ARG1": "value1", "ARG2": "value2"}, labels={"label1": "val1"}, cache=True, load=True, cache_to={} ) full cmd is [PosixPath('/usr/local/bin/docker'), 'buildx', 'build', '--build-arg', 'ARG1=value1', '--build-arg', 'ARG2=value2', '--label', 'label1=val1', '--load', '--file', 'Dockerfile', '--cache-to', '', '--tag', 'test-image:latest'] ``` ## Checklist - [ ] Have you linked a jira ticket and/or is the ticket in the title? - [x] Have you checked whether your jira ticket required DOCSP changes? - [x] Have you added changelog file? - use `skip-changelog` label if not needed - refer to [Changelog files and Release Notes](https://github.com/mongodb/mongodb-kubernetes/blob/master/CONTRIBUTING.md#changelog-files-and-release-notes) section in CONTRIBUTING.md for more details
1 parent 8509144 commit 7ea875e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

scripts/release/build/image_build_process.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,20 +133,20 @@ def get_manfiest_list_digest(self, image) -> Optional[str]:
133133
except FileNotFoundError:
134134
raise Exception("docker is not installed on the system.")
135135

136-
def _build_cache(self, tags: list[str]) -> tuple[list[Any], dict[str, str]]:
136+
def _build_cache(self, tags: list[str]) -> tuple[list[Any], Optional[dict[str, str]]]:
137137
"""
138138
Build cache configuration for the given tags.
139139
140140
Only ECR tags trigger caching because our CI infrastructure uses ECR for remote cache
141141
storage. Local or other registry builds skip caching to avoid authentication failures.
142142
143143
:param tags: List of image tags
144-
:return: Tuple of (cache_from_refs, cache_to_refs)
144+
:return: Tuple of (cache_from_refs, cache_to_refs) where cache_to_refs may be None
145145
"""
146146
# Filter tags to only include ECR ones (containing ".dkr.ecr.")
147147
ecr_tags = [tag for tag in tags if ".dkr.ecr." in tag]
148148
if not ecr_tags:
149-
return [], {}
149+
return [], None
150150

151151
primary_tag = ecr_tags[0]
152152
# Extract the repository URL without tag

0 commit comments

Comments
 (0)