-
Notifications
You must be signed in to change notification settings - Fork 43
feat(builtins): add aspect ci warming task
#1063
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
Draft
gregmagolan
wants to merge
3
commits into
main
Choose a base branch
from
aspect_ci_warming_task
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+104
−0
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| """A 'warming' task: pre-populate Bazel caches on a CI runner. | ||
|
|
||
| Cleans the prior Bazel state under ${ASPECT__STORAGE_PATH}, then runs | ||
| `bazel build --nobuild` against the given targets so the repository, | ||
| output, and bazel caches under that mount (and the aspect-launcher / | ||
| aspect-cli caches under ${ASPECT__STORAGE_PATH}/caches/{aspect-launcher, | ||
| aspect-cli}) are populated and ready for the warming archive. When | ||
| running on an Aspect Workflows runner, this task also invokes | ||
| /etc/aspect/workflows/bin/warming_archive to upload the populated | ||
| caches to the warming bucket — so the customer's CI workflow only | ||
| needs to call `aspect ci warming`. | ||
| """ | ||
| load("./traits.axl", "BazelTrait") | ||
|
|
||
|
|
||
| WARMING_ARCHIVE_BIN = "/etc/aspect/workflows/bin/warming_archive" | ||
|
|
||
|
|
||
| def _impl(ctx: TaskContext) -> int: | ||
| on_workflows_runner = bool(ctx.std.env.var("ASPECT_WORKFLOWS_RUNNER")) | ||
| mount = ctx.std.env.var("ASPECT__STORAGE_PATH") | ||
| if mount: | ||
| # Match rosetta's pre-warming cleanup. Best-effort: bazel may have | ||
| # left output dirs read-only, so chmod first; spawn errors are | ||
| # tolerated since the dirs may not exist yet on a fresh runner. | ||
| for sub in ["bazel", "output", "caches/repository"]: | ||
| d = mount + "/" + sub | ||
| ctx.std.process.command("find").args([d, "-type", "d", "-exec", "chmod", "u+w", "{}", "+"]).spawn().wait() | ||
| ctx.std.process.command("rm").args(["-rf", d]).spawn().wait() | ||
|
|
||
| bazel_trait = ctx.traits[BazelTrait] | ||
|
|
||
| flags = ["--nobuild"] | ||
| flags.extend(ctx.args.bazel_flags) | ||
| flags.extend(bazel_trait.extra_flags) | ||
| for hook in bazel_trait.task_flags: | ||
| flags.extend(hook(ctx)) | ||
| if bazel_trait.flags: | ||
| flags = bazel_trait.flags(flags) | ||
|
|
||
| startup_flags = list(ctx.args.bazel_startup_flags) | ||
| startup_flags.extend(bazel_trait.extra_startup_flags) | ||
| if ctx.args.output_base: | ||
| startup_flags.insert(0, "--output_base=" + ctx.args.output_base) | ||
| if bazel_trait.startup_flags: | ||
| startup_flags = bazel_trait.startup_flags(startup_flags) | ||
| ctx.bazel.startup_flags.extend(startup_flags) | ||
|
|
||
| invocation = ctx.bazel.build( | ||
| flags = flags, | ||
| *ctx.args.targets, | ||
| ) | ||
| code = invocation.wait().code | ||
| if code != 0: | ||
| return code | ||
|
|
||
| if on_workflows_runner: | ||
| # Upload the populated caches to the warming bucket. Inherits the | ||
| # script's stdout/stderr so the user sees its progress in real time. | ||
| archive = ctx.std.process.command(WARMING_ARCHIVE_BIN).spawn().wait() | ||
| return archive.code | ||
|
|
||
| ctx.std.io.stderr.write( | ||
| "warning: ASPECT_WORKFLOWS_RUNNER is not set; skipping the warming " + | ||
| "archive upload step. The bazel cache populate step ran successfully. " + | ||
| "On an Aspect Workflows runner this task also invokes " + | ||
| WARMING_ARCHIVE_BIN + " to upload the populated caches to the warming " + | ||
| "bucket.\n" | ||
| ) | ||
| return 0 | ||
|
|
||
|
|
||
| warming = task( | ||
| group = ["ci"], | ||
| summary = "Pre-populate Bazel caches on a CI runner.", | ||
| description = "Cleans prior Bazel state under ${ASPECT__STORAGE_PATH}, then runs `bazel build --nobuild` against the given targets so subsequent jobs on the same runner pool start with hot caches. Intended to run on Aspect Workflows warming runners; the populated caches are captured by the warming archive.", | ||
| implementation = _impl, | ||
| traits = [BazelTrait], | ||
| args = { | ||
| "targets": args.positional( | ||
| minimum = 1, | ||
| maximum = 512, | ||
| default = ["..."], | ||
| description = "Bazel target patterns to warm. Defaults to '...' which expands to all rule targets in the package at and beneath the current directory.", | ||
| ), | ||
| "bazel_flags": args.string_list( | ||
| long = "bazel-flag", | ||
| description = "Additional Bazel flags forwarded to the build (e.g. --bazel-flag=--config=ci). Repeat the flag to pass multiple.", | ||
| ), | ||
| "bazel_startup_flags": args.string_list( | ||
| long = "bazel-startup-flag", | ||
| description = "Additional Bazel startup flags. Repeat the flag to pass multiple.", | ||
| ), | ||
| "output_base": args.string( | ||
| default = "", | ||
| description = "Bazel output base path. Use to target a specific Bazel server instance.", | ||
| ), | ||
| }, | ||
| ) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cleanup step reads
ASPECT__STORAGE_PATH, but the runner environment model inlib/environment.axlis keyed offASPECT_WORKFLOWS_RUNNER_STORAGE_PATH(with defaults derived from it). On Workflows runners where only the documentedASPECT_WORKFLOWS_RUNNER_*variables are present,mountis empty, so the pre-warming cleanup is skipped and stale cache contents can be re-archived bywarming_archive, defeating the task’s “clean then repopulate” behavior.Useful? React with 👍 / 👎.