Repository navigation
feat: spawn snapshot create — build EBS snapshot via EBS direct APIs (#147 Part A) - #148
Merged
Merged
Conversation
…147 Part A) Adds `spawn snapshot create --from <raw-image> --size <GiB>` to populate a new EBS snapshot directly from a raw disk/filesystem image using the EBS direct APIs (StartSnapshot → PutSnapshotBlock → CompleteSnapshot) — no EC2 instance, no attached volume. The source is a local path or s3://bucket/key. This is the instance-free build side of #147; it pairs with the --attach-volume read side (#144) so large reference data lives in a re-snapshottable volume instead of a baked AMI. - pkg/aws/snapshot_build.go: planSnapshotBlocks (pure: 512 KiB block split, sparse all-zero skip, final-block zero-pad, per-block base64-SHA256 checksum + linear-aggregation checksum), BuildSnapshotFromReader (the direct-API flow + EC2 SnapshotCompleted waiter), OpenImageSource (local/s3 streaming). - cmd/snapshot.go: the snapshot/create command (text/json output), with --from documented as a RAW image (not an archive — the fs-builder is Part B). - Pure block/checksum logic is unit-tested (substrate doesn't model the EBS direct endpoint); the live upload is deferred to a paid validation. Part B (FSR warming on attach + a directory/tarball→filesystem-image builder) to be planned on the issue.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Part A of #147 (per the agreed scope: ship the instance-free snapshot builder now; plan Part B/FSR separately). The build side that pairs with
--attach-volume(#144, shipped in v0.46.0).What
spawn snapshot create --from <raw-image> --size <GiB>populates a new EBS snapshot directly from a raw disk/filesystem image using the EBS direct APIs — no EC2 instance, no attached volume. Source is a local path ors3://bucket/key.This drops the launch→download→extract→
ami create→terminate bake dance from the data path.How
pkg/aws/snapshot_build.goplanSnapshotBlocks— the pure, fully-tested core: split the image into fixed 512 KiB blocks (the only size the API accepts), skip all-zero blocks (sparse — a snapshot reads unwritten blocks as zero), zero-pad the final short block, compute each block's base64 SHA256 (thePutSnapshotBlockchecksum) and the linear-aggregation checksum (CompleteSnapshot= base64 SHA256 over the concatenated raw per-block digests in index order).BuildSnapshotFromReader—StartSnapshot→PutSnapshotBlock×N →CompleteSnapshot, then the EC2SnapshotCompletedwaiter so the snapshot is immediately attachable. Fits-check against--size; encryption/KMS supported.OpenImageSource— streams the image from a local file or S3 object.cmd/snapshot.go—spawn snapshot create(text/json),--from/--sizerequired,--name/--description/--region/--encrypted/--kms-key.Important scoping: raw image, not an archive
--fromis read verbatim as the block device — it must be a raw filesystem image, not a.tar.gz. The help text says so explicitly and points at building one (truncate+mkfs.ext4 -d). Doing that conversion for the user (a directory/tarball → filesystem image) needs a Linux fs-builder and is Part B — it can't run portably on the macOS host this CLI targets. I'd rather ship the unambiguous primitive than guess a fs layout.Tests
Pure block/checksum logic is unit-tested (short block + padding, sparse-zero skip with preserved indices, all-zero → no blocks, exact multiples, deterministic + independently-recomputed aggregation checksum,
parseS3URI, tags). The EBS direct endpoint isn't modeled by substrate, so the live upload is deferred to a paid validation (below).make checkgreen.Follow-ups (will comment on #147)
--attach-volume/at launch so a wide fan-out doesn't each eat first-touch lazy-load latency. This bills per-AZ-hour while enabled, so it needs an explicit opt-in + auto-disable-on-drain design before implementing — deliberately not in this PR.--from <dir>/tarball → build a filesystem image (Linux-only path).--attach-volumeit, confirm contents + checksum; clean up. Pairs with Attach a pre-populated EBS volume from a snapshot at launch (--attach-volume snap-xxx:/mount:ro) #144's live test.