Skip to content

feat(task): run the command inside spec.container (spawn#386 increment 3) - #408

Merged
scttfrdmn merged 2 commits into
mainfrom
feat/386-task-container
Jul 19, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
feat/386-task-container

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Summary

spawn#386 increment 3 — container execution for spawn task run. A TaskSpec with a container image now runs the command inside that image instead of erroring (increment 2 deferred this). This is what makes task run useful to the container-first workflow adapters #386 exists to serve (biocontainers, nf-core).

How it works

GenerateWrapper (pkg/taskproto/wrapper.go) branches on spec.Container:

  • Host (unchanged): ( argv ); rc=$?
  • Container: install Docker on demand (stock AL2023 AMI has none) → docker pull → docker run --rm [--gpus all] -v <dir>:<dir> ... <image> <argv>; rc=$?

Design points:

  • Bind-mount host stage dirs — stage-in/out stay on the host (unchanged), the container runs with the manifest dirs mounted (identity mounts, so in-container paths == the paths the spec author wrote). The image needs no AWS CLI.
  • Private ECR (ecrImageAccount != "") → docker login to the registry host + a scoped ecr:ReadOnly grant on the task's instance profile (taskExtraPolicies). Public images pull anonymously, no grant.
  • GPU — resources.gpus > 0 → --gpus all (mirrors cmd/app.go's container path).
  • Stage-in/out, completion record, .exitcode, SPAWN_COMPLETE, self-terminate — all unchanged. The container only replaces the "run" step.
  • GenerateWrapper gained a region param (for the ECR login region).

The flagship examples/task-spec.json (a biocontainers image) now runs end-to-end.

Testing

  • Unit (no Docker/AWS): public vs private-ECR vs host wrappers (host emits ( argv ) and NO docker/ecr); GPU flag; containerMountDirs dedup/sort; taskExtraPolicies (ecr grant only for private ECR); container dry-run preview. The generated container wrapper passes shellcheck (only pre-existing SC2034 info warnings).
  • TestFlagConventions/TestTier0 pass; docs-gen regenerated; Semgrep clean on changed files. Only the pre-existing TestCatalogValid fails in cmd (unrelated).
  • No billable EC2 in this PR. A real end-to-end container smoke test (docker install → pull → in-container run → stage-out → self-terminate) is a gated follow-up — I'll propose the exact spec + TTL for approval before launching, per the increment-2 lesson (container-specific paths only prove out on a real launch).

Refs #386 (increment 3; adapter migration + stubbed retry classes remain)

…t 3)

A TaskSpec with a container image now runs the command inside it instead of
being rejected. The generated wrapper (pkg/taskproto/wrapper.go) branches on
spec.Container: install Docker on demand (stock AL2023 AMI has none), pull the
image, and 'docker run' the argv with the input/output manifest dirs bind-mounted
(identity mounts, so in-container paths match the spec). Stage-in/out stay on the
host, so the image needs no aws CLI.

Private-ECR images (ecrImageAccount != '') get a docker login to their registry
host and a scoped ecr:ReadOnly grant on the task instance profile
(taskExtraPolicies); public images pull anonymously. resources.gpus>0 passes
--gpus all (mirrors cmd/app.go's container path). GenerateWrapper gained a region
param for the ECR login.

Unit-tested: public vs private-ECR vs host wrappers, GPU flag, mount-dir dedup,
ecr grant selection, container dry-run preview. Generated wrapper passes
shellcheck. Real-AWS end-to-end smoke is a gated follow-up (needs a TTL +
approval per cost-safety).

Refs #386
@codecov

codecov Bot commented Jul 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.69892% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/task.go 82.35% 3 Missing ⚠️
pkg/taskproto/wrapper.go 98.68% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Real-AWS smoke test of the container path found it hung at 'installing
docker...': the command script runs as the unprivileged instance user (bootstrap
runs it via 'su - <user>'), but dnf install / systemctl / the docker socket all
need root. The install failed silently as non-root, then docker calls hung.

Sudo every privileged step in the container branch (AL2023's default user has
passwordless sudo), and add a bounded 'sudo docker info' wait loop so we never
issue a pull/run against a daemon that isn't up yet. The host path is unchanged
(no root needed). Re-verified end-to-end on real AWS: busybox container task
installed docker, pulled, ran in-container, staged /work/out.txt to S3, wrote
completion.json (exit 0), and self-terminated ~4min in; leak-check clean.

Refs #386
@scttfrdmn
scttfrdmn merged commit 32fdd6a into main Jul 19, 2026
7 checks passed
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