Skip to content

feat: attach EBS data volume from a snapshot at launch (#144) - #145

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/144-attach-ebs-volume-from-snapshot
Jun 13, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/144-attach-ebs-volume-from-snapshot

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Closes #144. The spawn-side primitive that nf-spawn#45 depends on.

What

spawn launch --attach-volume snap-xxx:/mount/point[:ro|:rw] (repeatable) attaches an additional EBS data volume created from a snapshot, mounted at the given path — read-only by default (the common case for shared reference data). So large reference data (the motivating case: a ~16 GB Kraken2 DB for nf-core/taxprofiler) lives in a re-snapshottable volume on a stock AMI instead of being baked into a custom AMI.

spawn launch --instance-type r7g.2xlarge \
  --attach-volume snap-0abc123:/opt/databases/kraken2:ro

How

  • pkg/aws — new AttachVolumeSpec + LaunchConfig.AttachVolumes. buildBlockDevices appends one snapshot-backed block-device mapping per spec on /dev/sdf, /dev/sdg, … with DeleteOnTermination=true (the per-task copy dies with the ephemeral instance — lifecycle invariant; the snapshot persists) and inheriting EBS encryption/KMS. Exported AttachDeviceName(i) keeps the CLI and BDM sides on the same device-name scheme.
  • pkg/userdata — storage user-data gains an attached-EBS branch:
    • NVMe-aware device resolution — on Nitro the requested /dev/sdf is remapped to an NVMe device in nondeterministic order. spawn_resolve_dev waits for AL2023's ec2-utils /dev/sdf symlink and falls back to scanning ebsnvme-id, so we mount the right device, not a guessed path.
    • ro/rw mount, fstab with nofail (a missing data volume never wedges boot), and never mkfs — a snapshot-backed volume already has a filesystem.
  • cmd/launch — --attach-volume flag; parseAttachVolumes validates the snap- prefix, absolute mount path, and ro/rw mode; wired into both the single-instance and job-array storage user-data paths.

Tests

  • pkg/aws: attached volumes append snapshot BDMs on distinct device names with DeleteOnTermination, size override vs snapshot size, encryption/KMS inheritance; AttachDeviceName mapping.
  • pkg/userdata: ro mount + device resolution + nofail + no reformat; rw variant.
  • cmd: parseAttachVolumes happy paths + rejects (no mount / relative path / non-snapshot id / bad mode / too many parts); attachedVolumesUserData device-name mapping.
  • make check green.

Cost / lifecycle

The attached volume is created from the snapshot at launch with DeleteOnTermination=true, so it's cleaned up with the instance — no leaked volumes. A read-only reference volume fanned out across many task instances is many EBS volumes from one snapshot; that's the expected, intended trade against per-task S3 download / oversized root volumes.

Follow-up

Not in this PR: a live paid validation (launch a stock AL2023 arm64 with --attach-volume <kraken2-snap>:/opt/databases/kraken2:ro, confirm the DB is present read-only at the mount, terminate, leak-check the auto-created volume is gone). Will run that against the taxprofiler demo with the filer once nf-spawn#45 lands on top.

Adds `spawn launch --attach-volume snap-xxx:/mount/point[:ro|:rw]`
(repeatable) so large reference data lives in a re-snapshottable EBS volume on
a stock AMI instead of being baked into a custom AMI.

- pkg/aws: new AttachVolumeSpec + LaunchConfig.AttachVolumes; buildBlockDevices
  appends one snapshot-backed BDM per spec on /dev/sdf, /dev/sdg, … with
  DeleteOnTermination=true (so the per-task copy dies with the instance) and
  inheriting EBS encryption/KMS. Exported AttachDeviceName keeps the CLI and
  block-device side on the same device-name scheme.
- pkg/userdata: storage user-data gains an attached-EBS branch — NVMe-aware
  device resolution (the requested /dev/sdf is remapped on Nitro), ro/rw mount,
  fstab with nofail, and never mkfs (snapshot already has a filesystem).
- cmd/launch: --attach-volume flag, parseAttachVolumes (validates snap- prefix,
  absolute mount, ro/rw mode), wired into both the single-instance and job-array
  storage user-data paths.

Unblocks nf-spawn#45 (per-process ext.volumes).
@codecov

codecov Bot commented Jun 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.92771% with 15 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/launch.go 73.21% 13 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit e9ce747 into main Jun 13, 2026
3 checks passed
@scttfrdmn
scttfrdmn deleted the feat/144-attach-ebs-volume-from-snapshot branch June 13, 2026 22:39
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.

Attach a pre-populated EBS volume from a snapshot at launch (--attach-volume snap-xxx:/mount:ro)

1 participant