-
Notifications
You must be signed in to change notification settings - Fork 400
feat: Implement new bazel rules for building SEV recovery GuestOS images #10571
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
Open
frankdavid
wants to merge
5
commits into
master
Choose a base branch
from
frankdavid/build-sev-recovery-images
base: master
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.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
baf745e
feat: Implement new bazel rules for building SEV recovery GuestOS images
frankdavid 37e2120
Automatically updated Cargo*.lock
9e13732
Automatically fixing code for linting and formatting issues
7bdff20
Move extract_boot_partition_files into the test loop
frankdavid 3656d95
Address comments
frankdavid 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,96 @@ | ||
| def _download_alternative_guestos_proposal_impl(ctx): | ||
| output = ctx.actions.declare_file(ctx.label.name) | ||
|
|
||
| command = """ | ||
| set -euo pipefail | ||
|
|
||
| proposal_id="$(cat {proposal_id_file})" | ||
|
|
||
| if [[ -z "$proposal_id" ]]; then | ||
| echo "//{package}:{name} requires ALTERNATIVE_GUESTOS_PROPOSAL_ID to be set in the environment before invoking Bazel." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| {tool} download-signed-proposal \ | ||
| --proposal-id "$proposal_id" \ | ||
| --nns-url {nns_url} \ | ||
| --output {output} | ||
| """.format( | ||
| name = ctx.label.name, | ||
| nns_url = ctx.attr.nns_url, | ||
| output = output.path, | ||
| package = ctx.label.package, | ||
| proposal_id_file = ctx.file._proposal_id_file.path, | ||
| tool = ctx.executable._tool.path, | ||
| ) | ||
|
|
||
| ctx.actions.run_shell( | ||
| command = command, | ||
| inputs = [ctx.file._proposal_id_file], | ||
| outputs = [output], | ||
| tools = [ctx.attr._tool.files_to_run], | ||
| mnemonic = "DownloadAlternativeGuestosProposal", | ||
| ) | ||
|
|
||
| return [DefaultInfo(files = depset([output]))] | ||
|
|
||
| download_alternative_guestos_proposal = rule( | ||
| implementation = _download_alternative_guestos_proposal_impl, | ||
| attrs = { | ||
| "nns_url": attr.string(default = "https://ic0.app"), | ||
| "_proposal_id_file": attr.label( | ||
| allow_single_file = True, | ||
| default = Label("//bazel:alternative_guestos_proposal_id.txt"), | ||
| ), | ||
| "_tool": attr.label( | ||
| default = Label("//rs/ic_os/build_tools/alternative_guestos"), | ||
| executable = True, | ||
| cfg = "exec", | ||
| ), | ||
| }, | ||
| ) | ||
|
|
||
| # Creates a tarball containing the bootfs file tree extracted from a released GuestOS. | ||
| def prepare_alternative_guestos_base_bootfs_tree_tar(name, out, tags = None, target_compatible_with = None): | ||
| native.genrule( | ||
| name = name, | ||
| srcs = ["//bazel:alternative_guestos_base_version.txt"], | ||
| outs = [out], | ||
| cmd = """ | ||
| set -euo pipefail | ||
|
|
||
| base_version="$$(cat $<)" | ||
|
|
||
| if [[ -z "$$base_version" ]]; then | ||
| echo "//{package}:{name} requires ALTERNATIVE_GUESTOS_BASE_VERSION to be set in the environment before invoking Bazel." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| tmpdir="$$(mktemp -d)" | ||
| mounted=0 | ||
| cleanup() {{ | ||
| set +e | ||
| if [[ "$$mounted" -eq 1 ]]; then | ||
| fusermount3 -u "$$tmpdir/bootfs" || fusermount -u "$$tmpdir/bootfs" || umount "$$tmpdir/bootfs" | ||
| fi | ||
| rm -rf "$$tmpdir" | ||
| }} | ||
| trap cleanup EXIT | ||
|
|
||
| curl --fail --silent --show-error --location \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should definitely not be downloading via |
||
| "https://download.dfinity.systems/ic/$$base_version/guest-os/update-img/update-img.tar.zst" \ | ||
| | tar --extract --zstd --to-stdout --file - boot.img > "$$tmpdir/boot.img" | ||
|
|
||
| mkdir "$$tmpdir/bootfs" | ||
| $(location //:fuse2fs) -o ro,norecovery,fakeroot "$$tmpdir/boot.img" "$$tmpdir/bootfs" | ||
| mounted=1 | ||
| tar --create --file "$@" --numeric-owner -C "$$tmpdir/bootfs" . | ||
| """.format( | ||
| name = name, | ||
| package = native.package_name(), | ||
| ), | ||
| message = "Downloading alternative GuestOS base boot image and converting it to tar via fuse2fs", | ||
| tags = tags, | ||
| target_compatible_with = target_compatible_with, | ||
| tools = ["//:fuse2fs"], | ||
| ) | ||
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.
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.
My instincts say this is probably not the right way to do it. In practice, when will this be built? And can the targets still be built on a clean checkout with e.g.
bazel build //...? Otherwise it's probably best to run this as abazel run