Commit a5b601d
authored
fix(infra): Resolve Race Condition in Parallel Base Image Builds (#14189)
## Summary
This PR fixes a critical race condition in the base image build process
that caused the `gcr.io/oss-fuzz-base/base-builder:ubuntu-24-04` image
to be incorrectly built with an Ubuntu 20.04 base.
The fix ensures build steps are executed in the correct order by
explicitly defining a dependency graph, guaranteeing that versioned
images are always built on top of their corresponding, freshly-built
base layers.
## The Problem
A report indicated that the `base-builder:ubuntu-24-04` image contained
Ubuntu 20.04. An initial investigation confirmed this behavior.
### Investigation Steps
1. **Dockerfile Verification:** The entire dependency chain of
Dockerfiles was inspected:
* `base-builder:ubuntu-24-04` correctly used `FROM
base-clang:ubuntu-24-04`.
* `base-clang:ubuntu-24-04` correctly used `FROM
base-image:ubuntu-24-04`.
* `base-image:ubuntu-24-04` correctly used `FROM ubuntu:24.04`.
This ruled out any static configuration errors in the Dockerfiles
themselves.
2. **Build Process Analysis:** A `dry-run` of the
`infra/build/functions/base_images.py` script revealed that all build
steps for the different base images were being generated to run in
parallel in Google Cloud Build.
### Root Cause: Race Condition
The parallel execution was the source of the problem. Because the builds
for `base-image`, `base-clang`, and `base-builder` were triggered
simultaneously, a race condition occurred:
* The `base-builder:ubuntu-24-04` build would start.
* It would immediately try to pull its base image,
`gcr.io/oss-fuzz-base/base-clang:ubuntu-24-04`.
* However, the build for the *new* `base-clang:ubuntu-24-04` had not yet
finished.
* The build process would then fall back to using the existing image
with that tag in the container registry, which was an older, incorrectly
built version based on Ubuntu 20.04.
The same issue was happening between `base-clang` and `base-image`.
## The Solution
To resolve this, we now enforce a sequential build order that respects
the image dependency hierarchy.
1. **Dependency Map:** An `IMAGE_DEPENDENCIES` dictionary was introduced
in `infra/build/functions/base_images.py` to define the explicit build
order (e.g., `base-clang` depends on `base-image`).
2. **Sequential Build Steps:** The `get_base_image_steps` function was
updated to read this map and inject a `waitFor` clause into each Google
Cloud Build step. This forces GCB to wait for a dependency to finish
building before starting the next step in the chain.
### Verification
A `dry-run` was executed after the fix, and the generated build steps
now correctly reflect the sequential dependency order. A full build was
also triggered, confirming that the fix works in a real environment and
produces the correct image.
This change ensures the integrity and correctness of our base images
without sacrificing the parallelism between different Ubuntu version
builds (e.g., the `ubuntu-20-04` and `ubuntu-24-04` builds still run in
parallel with each other).1 parent 211c3eb commit a5b601d
1 file changed
+35
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
50 | 67 | | |
51 | 68 | | |
52 | 69 | | |
| |||
85 | 102 | | |
86 | 103 | | |
87 | 104 | | |
| 105 | + | |
| 106 | + | |
88 | 107 | | |
89 | 108 | | |
90 | 109 | | |
| |||
156 | 175 | | |
157 | 176 | | |
158 | 177 | | |
| 178 | + | |
| 179 | + | |
159 | 180 | | |
160 | 181 | | |
161 | 182 | | |
| |||
167 | 188 | | |
168 | 189 | | |
169 | 190 | | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
175 | 205 | | |
176 | 206 | | |
177 | 207 | | |
| |||
0 commit comments