Repository navigation
Bound primary apt mirror builds before CLI E2E fallback #21849
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
Merged
Adam Ratzman (adamint)
merged 9 commits into
main
from
ievangelist-bound-ci-mirror-fallback
Nov 25, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5d26690
Bound primary apt mirror attempts in shared CLI E2E image builds
IEvangelist 4bb054c
Restore inherited apt sources and preserve external cancellation
IEvangelist 296e3e9
Preserve external cancellation during mirror deadline cleanup
IEvangelist b8274fc
Fail closed when the image client is killed during cleanup
IEvangelist 7e667c6
Fail closed when the Buildx plugin is killed during deadline cleanup
adamint 2fcd19b
Merge remote-tracking branch 'origin/main' into ievangelist-bound-ci-…
adamint 9ffeb16
Fix DcpConnectionHealthCheckTests build after temporary storage refactor
adamint c4005a4
Treat a killed Buildx plugin as unconfirmed cancellation before the d…
adamint a4a7fdc
Update App Service slot config snapshots for resource outputs
adamint File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| build_with_mirror_retry() { | ||
| local primary_timeout="$1" | ||
| local display_name="$2" | ||
| shift 2 | ||
| local status | ||
|
|
||
| echo "Building $display_name with Azure Ubuntu apt mirror (limit: $primary_timeout)" | ||
| if node "$(dirname "${BASH_SOURCE[0]}")/run-bounded-image-build.ts" "$primary_timeout" \ | ||
| "$@" --build-arg "UBUNTU_APT_MIRROR=http://azure.archive.ubuntu.com/ubuntu/" .; then | ||
| return 0 | ||
| else | ||
| status=$? | ||
| fi | ||
|
|
||
| case "$status" in | ||
| 124) | ||
| echo "$display_name primary mirror build exceeded $primary_timeout; retrying with default Ubuntu apt sources" >&2 | ||
| ;; | ||
| 125|126|127|130|137|143) | ||
| # A forced kill cannot confirm BuildKit acknowledged cancellation. Do | ||
| # not overlap another build or turn workflow cancellation into a retry. | ||
| echo "$display_name primary build stopped with exit code $status; not retrying after cancellation or timeout execution failure" >&2 | ||
| return "$status" | ||
| ;; | ||
| *) | ||
| echo "$display_name build failed with the Azure Ubuntu apt mirror (exit code $status); retrying with default Ubuntu apt sources" >&2 | ||
| ;; | ||
| esac | ||
|
|
||
| "$@" . | ||
|
IEvangelist marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| build_cli_e2e_images() { | ||
| # Four primary attempts can spend at most 20m plus 2m cancellation grace, | ||
| # leaving 23m of the 45m job for default sources, setup and artifact handling. | ||
| # Throttled apt downloads have otherwise consumed 38-41m in a single image. | ||
| local primary_timeout=5m | ||
| local dotnet_cache_scope=cli-e2e-dotnet | ||
| local polyglot_cache_scope=cli-e2e-polyglot-base | ||
|
|
||
| docker buildx create --name cli-e2e-builder --use | ||
| docker buildx inspect --bootstrap | ||
|
|
||
| build_with_mirror_retry "$primary_timeout" ".NET image" docker buildx build \ | ||
| --load \ | ||
| --cache-from "type=gha,scope=$dotnet_cache_scope" \ | ||
| --cache-to "type=gha,scope=$dotnet_cache_scope,mode=max,ignore-error=true" \ | ||
| --build-arg SKIP_SOURCE_BUILD=true \ | ||
| -f tests/Shared/Docker/Dockerfile.e2e \ | ||
| -t "$CLI_E2E_DOTNET_IMAGE_TAG" | ||
|
|
||
| if [[ "$CLI_E2E_INCLUDE_POLYGLOT_IMAGES" == "true" ]]; then | ||
| build_with_mirror_retry "$primary_timeout" "polyglot base image" docker buildx build \ | ||
| --load \ | ||
| --cache-from "type=gha,scope=$polyglot_cache_scope" \ | ||
| --cache-to "type=gha,scope=$polyglot_cache_scope,mode=max,ignore-error=true" \ | ||
| --build-arg SKIP_SOURCE_BUILD=true \ | ||
| -f tests/Shared/Docker/Dockerfile.e2e-polyglot-base \ | ||
| -t "$CLI_E2E_POLYGLOT_BASE_IMAGE_TAG" | ||
| docker tag "$CLI_E2E_POLYGLOT_BASE_IMAGE_TAG" "$CLI_E2E_POLYGLOT_IMAGE_TAG" | ||
|
|
||
| DOCKER_BUILDKIT=1 build_with_mirror_retry "$primary_timeout" "Java polyglot image" docker build \ | ||
| -f tests/Shared/Docker/Dockerfile.e2e-polyglot-java \ | ||
| -t "$CLI_E2E_POLYGLOT_JAVA_IMAGE_TAG" | ||
| DOCKER_BUILDKIT=1 build_with_mirror_retry "$primary_timeout" "Go polyglot image" docker build \ | ||
| -f tests/Shared/Docker/Dockerfile.e2e-polyglot-go \ | ||
| -t "$CLI_E2E_POLYGLOT_GO_IMAGE_TAG" | ||
| fi | ||
| } | ||
|
|
||
| if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then | ||
| build_cli_e2e_images | ||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| #!/usr/bin/env node | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| import { spawn } from 'node:child_process'; | ||
| import { constants } from 'node:os'; | ||
|
|
||
| const [duration, executable, ...args] = process.argv.slice(2); | ||
| const match = /^([1-9]\d*)(s|m)$/.exec(duration ?? ''); | ||
| if (!match || !executable || process.platform !== 'linux') { | ||
| console.error('Usage (Linux): node run-bounded-image-build.ts <positive duration in s or m> <command> [arguments...]'); | ||
| process.exit(125); | ||
| } | ||
|
|
||
| const milliseconds = Number(match[1]) * (match[2] === 'm' ? 60000 : 1000); | ||
| if (!Number.isSafeInteger(milliseconds) || milliseconds > 2147483647) { | ||
| console.error(`Invalid image build duration: ${duration}`); | ||
| process.exit(125); | ||
| } | ||
|
|
||
| // A separate session lets us signal the client and all of its descendants, | ||
| // without signaling the workflow shell or other builds on the runner. | ||
| const child = spawn(executable, args, { detached: true, stdio: 'inherit' }); | ||
| let deadlineReached = false; | ||
| let cancellationExitCode = 0; | ||
| let forcedKill = false; | ||
| let deadline: NodeJS.Timeout | undefined; | ||
| let grace: NodeJS.Timeout | undefined; | ||
|
|
||
| function signalGroup(signal: NodeJS.Signals): void { | ||
| if (child.pid === undefined) { | ||
| return; | ||
| } | ||
| try { | ||
| process.kill(-child.pid, signal); | ||
| } catch (error) { | ||
| // The client may finish between the signal event and the group kill. | ||
| if (!(error instanceof Error && 'code' in error && error.code === 'ESRCH')) { | ||
| throw error; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function stopClient(): void { | ||
| signalGroup('SIGTERM'); | ||
| grace ??= setTimeout(() => { | ||
| forcedKill = true; | ||
| console.error('Image build did not acknowledge cancellation within 30s; killing its process group'); | ||
| signalGroup('SIGKILL'); | ||
| }, 30000); | ||
| } | ||
|
|
||
| function cancel(exitCode: number): void { | ||
| // Keep cancellation independent of the deadline, including signals arriving | ||
| // during the deadline's cleanup grace. GNU timeout returns 124 in that race. | ||
| cancellationExitCode = exitCode; | ||
| console.error('Image build externally cancelled; default-source retry is disabled'); | ||
| stopClient(); | ||
| } | ||
|
|
||
| process.on('SIGTERM', () => cancel(143)); | ||
| process.on('SIGINT', () => cancel(130)); | ||
| child.once('spawn', () => { | ||
| deadline = setTimeout(() => { | ||
| deadlineReached = true; | ||
| console.error(`Image build exceeded ${duration}; cancelling its process group`); | ||
| stopClient(); | ||
| }, milliseconds); | ||
| }); | ||
| child.once('error', error => { | ||
| console.error(`Could not start image build: ${error.message}`); | ||
| process.exit('code' in error && error.code === 'ENOENT' ? 127 : 125); | ||
| }); | ||
| child.once('exit', (code, signal) => { | ||
| clearTimeout(deadline); | ||
| clearTimeout(grace); | ||
| const clientExitCode = code ?? (signal ? 128 + constants.signals[signal] : 1); | ||
| // An external kill/OOM is not acknowledged cancellation, before or during | ||
| // deadline cleanup. `docker buildx` and `docker build` run Buildx as a CLI | ||
| // plugin. When the plugin dies from a signal, Docker exits 255: it propagates | ||
| // syscall.WaitStatus.ExitStatus(), which is -1 for a signaled process. See | ||
| // https://github.com/docker/cli/blob/v28.0.4/cmd/docker/docker.go#L366-L376 | ||
| const killed = clientExitCode === 137 || clientExitCode === 255; | ||
| process.exit(forcedKill || killed ? 137 : cancellationExitCode || (deadlineReached ? 124 : clientExitCode)); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.