Skip to content

Commit 60d6307

Browse files
[main] Update common Docker engineering infrastructure with latest (#1300)
1 parent 404759d commit 60d6307

1 file changed

Lines changed: 85 additions & 1 deletion

File tree

eng/docker-tools/DEV-GUIDE.md

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ The `generateBuildMatrix` command is key to understanding how builds are paralle
171171
1. **Reads the manifest.json** - Understands which images exist
172172
2. **Builds a dependency graph** - Knows that `runtime-deps` must build before `runtime`
173173
3. **Groups by platform** - Creates jobs for each OS/Architecture combo
174-
4. **Optimizes with caching** - Can detect and exclude unchanged images
174+
4. **Optimizes with caching** - Can detect and exclude unchanged images (see [Image Caching](#image-caching) below)
175175

176176
### Controlling Which Build Stages Run
177177

@@ -338,6 +338,34 @@ The `autobuilder` label is how the infrastructure tracks that the failure cycle
338338

339339
---
340340

341+
### Image Caching
342+
343+
The infrastructure includes caching to avoid rebuilding images that haven't changed. Caching operates at two levels:
344+
345+
**1. Matrix Trimming (job-level caching)**
346+
347+
When `trimCachedImagesForMatrix` is enabled, the `generateBuildMatrix` command excludes platforms from the build matrix if they would result in cache hits. This means no build job is even created for those platforms—they're completely skipped.
348+
349+
**2. Build-time Caching**
350+
351+
Even if a platform isn't trimmed from the matrix, the `build` command checks each image against the cache before building. If the image is cached, it outputs `CACHE HIT`, pulls the previously-built image from the registry, and skips the actual Docker build.
352+
353+
#### Cache Conditions
354+
355+
An image is considered cached when **both** of the following conditions are true:
356+
357+
1. **Base image digest is unchanged** — The digest of the base image (FROM image) matches the digest recorded in the image info file from the last successful publish. If the upstream base image has been updated, this condition fails and the image will be rebuilt.
358+
359+
2. **Dockerfile commit is unchanged** — The git commit URL for the Dockerfile matches the commit URL recorded in the image info file. If you've modified the Dockerfile, this condition fails and the image will be rebuilt.
360+
361+
Caching compares against the published image info stored in the [versions repo](https://github.com/dotnet/versions). This means caching compares against what's been officially published, not what's in your current branch.
362+
363+
#### Disabling Caching
364+
365+
To force a rebuild regardless of cache state, set the `noCache` parameter to `true` when queuing the build. This disables both matrix trimming and build-time caching.
366+
367+
---
368+
341369
## Common Customization Patterns
342370

343371
### Pattern: Adding Build Arguments
@@ -389,3 +417,59 @@ When you queue a new run, you can override these as runtime parameters:
389417
2. Set `sourceBuildPipelineRunId` to the run ID containing the artifacts you need (find the build ID in the URL when viewing a pipeline run, e.g., `buildId=123456`)
390418

391419
This avoids the multi-hour rebuild cycle when you just need to retry a failed operation.
420+
421+
---
422+
423+
## Troubleshooting
424+
425+
### Why isn't my Dockerfile being built?
426+
427+
When you trigger a pipeline run, you might find that your Dockerfile isn't being built.
428+
429+
#### Symptom 1: The Dockerfile isn't included in any build job
430+
431+
If your Dockerfile doesn't appear in any build job, first verify the Dockerfile is included in the manifest file.
432+
433+
**How to verify:** Check `manifest.json` to ensure your Dockerfile path is defined under the appropriate repo and image. You can also run `generateBuildMatrix` locally to see which Dockerfiles are included:
434+
435+
```powershell
436+
./eng/docker-tools/Invoke-ImageBuilder.ps1 "generateBuildMatrix --manifest manifest.json --type platformDependencyGraph"
437+
```
438+
439+
**How to fix:** Add the Dockerfile to `manifest.json` under the correct repo, image, and platform configuration.
440+
441+
#### Symptom 2: The pipeline job isn't running at all
442+
443+
If the Dockerfile is in the manifest but you don't see a build job for it, the build matrix was likely trimmed due to [matrix trimming](#image-caching).
444+
445+
**How to verify:** Look at the "Generate platformDependencyGraph Matrix" step output in the `GenerateBuildMatrix` job. This is an example of what the output in that step looks like:
446+
447+
```yaml
448+
windowsLtsc2025Amd64:
449+
src-windowsservercore-ltsc2025-helix-graph:
450+
imageBuilderPaths: --path src/windowsservercore/ltsc2025/helix/amd64 --path src/windowsservercore/ltsc2025/helix/webassembly-net8/amd64 --path src/windowsservercore/ltsc2025/helix/webassembly/amd64
451+
legName: windows-ltsc2025amd64src-windowsservercore-ltsc2025-helix-graph
452+
osType: windows
453+
architecture: amd64
454+
osVersions: --os-version windowsservercore-ltsc2025
455+
```
456+
457+
If your Dockerfile path doesn't appear in any of the matrix legs, it was trimmed.
458+
459+
**How to fix:** Set the `noCache` parameter to `true` when queuing the build.
460+
461+
#### Symptom 3: The build output shows `CACHE HIT`
462+
463+
If your build job runs but you see `CACHE HIT` in the output of the `Build Images` step and the Dockerfile isn't actually built, the [build-time caching](#image-caching) determined that the image doesn't need to be rebuilt. This is an example of what the output in that step looks like:
464+
465+
```
466+
Image info's Dockerfile commit: https://github.com/dotnet/dotnet-buildtools-prereqs-docker/blob/aa85f0dcc3b3d6757c80dc8c2a6f38c290b372cc/src/windowsservercore/ltsc2025/helix/amd64/Dockerfile
467+
Latest Dockerfile commit: https://github.com/dotnet/dotnet-buildtools-prereqs-docker/blob/aa85f0dcc3b3d6757c80dc8c2a6f38c290b372cc/src/windowsservercore/ltsc2025/helix/amd64/Dockerfile
468+
Dockerfile commits match: True
469+
470+
CACHE HIT
471+
472+
-- EXECUTING: docker pull mcr.microsoft.com/dotnet-buildtools/prereqs@sha256:40d36a0aab610f4d513ed7c7300a5d962968a547ffe8a859a0e599691b74b77f
473+
```
474+
475+
**How to fix:** Set the `noCache` parameter to `true` when queuing the build.

0 commit comments

Comments
 (0)