Commit 7ea875e
authored
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 details1 parent 8509144 commit 7ea875e
1 file changed
+3
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
136 | | - | |
| 136 | + | |
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | | - | |
| 144 | + | |
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
149 | | - | |
| 149 | + | |
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
| |||
0 commit comments