Skip to content

feat: spawn snapshot create --from accepts dir/tar/tar.gz (#147 Part B) - #150

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/147-snapshot-from-dir-tar
Jun 13, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/147-snapshot-from-dir-tar

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Part B fs-builder for #147 — the ergonomic front door you asked for: pass a directory, tar, or tar.gz and go, kept fully instance-free.

The decision

Building a populated Linux filesystem normally needs mkfs (Linux-only, not pure-Go-able). A first instinct was a transient builder EC2 instance — but as you put it, if you have to launch an instance, you don't need the EBS-direct path at all. So the only version worth building keeps it instance-free.

go-diskfs's ext4 writer is broken (its Mkdir errors out), but Microsoft's hcsshim/ext4/tar2ext4 does exactly tar→ext4 in pure Go — stdlib only, no cgo, no GOOS constraint. Verified it builds a valid, mountable ext4 image on macOS (ext4 superblock magic 0x53EF present). So:

What

spawn snapshot create --from now accepts:

  • a directory → tarred in-process, converted to an ext4 image
  • a .tar / .tar.gz / .tgz (local or s3://) → (gunzipped and) converted to ext4
  • a raw image → streamed verbatim, exactly as in v0.47.0 (Part A)
spawn snapshot create --from ./kraken2-db/      --size 20 --name kraken2
spawn snapshot create --from ./k2_pluspf.tar.gz --size 20 --name kraken2
spawn snapshot create --from s3://genome-idx/k2_pluspf.tar.gz --size 20

All three requirements met at once: dir/tar ergonomics, instance-free, runs from macOS/Linux/Windows (pure Go). The ext4 fs is built compactly (sized to content, capped at --size) and streamed into the EBS-direct snapshot via the same Part A pipeline.

How

  • pkg/aws/snapshot_image.go: classifySnapshotSource (dir / tar / raw), tarDirectory (walks a dir → tar stream, forward-slash paths, symlinks), transparent gunzip, PrepareSnapshotImage (returns an ext4-image io.ReadCloser + Cleanup for the temp image; raw passes through untouched).
  • cmd/snapshot.go: wired to PrepareSnapshotImage; help/flags updated.

Tests

classifySnapshotSource (incl. s3 by-extension + case-insensitive), isGzipName, tarDirectory round-trip, and end-to-end PrepareSnapshotImage for directory → valid ext4, tar.gz → valid ext4 (assert the superblock magic), and raw passthrough (bytes unaltered). make check green; Tier 0 coverage gate already classifies snapshot.

Still deferred

The fs-builder half of #147, kept instance-free. --from now accepts a
directory or a .tar/.tar.gz/.tgz in addition to a raw image: the contents are
converted to an ext4 filesystem image in-process via hcsshim's tar2ext4 (pure
Go — no mkfs, no builder instance) and streamed into the EBS-direct snapshot.

Building the filesystem on the host (vs a transient EC2 bake box) was the whole
point of the EBS-direct path — an instance would have defeated it. tar2ext4 is
stdlib-only and cross-platform, so this works the same from macOS, Linux, and
Windows. The ext4 image is sized to the data and capped at --size; a raw image
still streams verbatim.

- pkg/aws/snapshot_image.go: classifySnapshotSource, tarDirectory (dir→tar),
  transparent gunzip, PrepareSnapshotImage (→ ext4 image reader + cleanup).
- cmd/snapshot.go: wire PrepareSnapshotImage; updated help/flags.
- Tests: classify, gzip-name, tar-from-dir, and end-to-end dir/tar.gz → valid
  ext4 (superblock magic) + raw passthrough.
@scttfrdmn
scttfrdmn merged commit 41fa85b into main Jun 13, 2026
2 checks passed
@scttfrdmn
scttfrdmn deleted the feat/147-snapshot-from-dir-tar branch June 13, 2026 23:39
@codecov

codecov Bot commented Jun 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 58.77863% with 54 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/aws/snapshot_image.go 60.31% 37 Missing and 13 partials ⚠️
cmd/snapshot.go 20.00% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant