Skip to content

Auto-pull images on instance creation#147

Merged
sjmiller609 merged 6 commits intomainfrom
hypeship/auto-pull-on-run
Mar 17, 2026
Merged

Auto-pull images on instance creation#147
sjmiller609 merged 6 commits intomainfrom
hypeship/auto-pull-on-run

Conversation

@sjmiller609
Copy link
Collaborator

@sjmiller609 sjmiller609 commented Mar 14, 2026

Summary

  • When CreateInstance is called with an image not found locally, automatically trigger a pull (CreateImage + WaitForReady) instead of returning an error
  • Adds TestCreateInstance_AutoPullImage integration test that creates an instance without pre-pulling the image, verifying the auto-pull path works end-to-end
  • Fixes the recurring bug where hypeman run <image> fails unless hypeman pull is run first

Changes

  • lib/instances/create.go: When GetImage returns ErrNotFound, call CreateImage to trigger a pull, wait for it with WaitForReady, then re-fetch the image
  • cmd/api/api/instances_test.go: New test TestCreateInstance_AutoPullImage that verifies instance creation succeeds without pre-pulling

Test plan

  • TestCreateInstance_AutoPullImage passes on a KVM-enabled host
  • Existing instance creation tests still pass (no regression)
  • Manual: hypeman run alpine:latest works on a fresh host with no pre-pulled images

🤖 Generated with Claude Code


Note

Medium Risk
Changes CreateInstance behavior to trigger background image pulls and introduce a new timeout-based readiness path, which may affect instance creation reliability and error handling under slow registries or large images.

Overview
CreateInstance now auto-pulls an image when GetImage returns images.ErrNotFound, calling CreateImage, waiting up to 5 seconds via WaitForReady, then re-fetching before continuing; if the pull isn’t ready in time it returns ErrImageNotReady advising the caller to retry while the pull continues.

Adds an integration test TestCreateInstance_AutoPullImage that creates an instance without pre-pulling alpine:latest (with KVM/system files prerequisites) to verify the end-to-end auto-pull path and cleanup.

Written by Cursor Bugbot for commit eedfbc0. This will update automatically on new commits. Configure here.

sjmiller609 and others added 5 commits March 14, 2026 22:06
When CreateInstance is called with an image that hasn't been pulled yet,
automatically trigger a pull and wait for it to complete instead of
returning an error. This fixes the recurring issue where `hypeman run
<image>` fails unless `hypeman pull` is run first.

Adds TestCreateInstance_AutoPullImage integration test that verifies
instance creation succeeds without pre-pulling the image.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The original TestCreateInstance_AutoPullImage in cmd/api/api/ required
KVM and skipped in CI/non-KVM environments. Replace it with unit tests
in lib/instances/ that mock the image manager to verify the auto-pull
flow without needing a VM:

- TestCreateInstance_AutoPullImage: verifies GetImage→CreateImage→
  WaitForReady→GetImage flow when image is not found
- TestCreateInstance_AutoPullImage_CreateImageFails: verifies error
  propagation when CreateImage fails
- TestCreateInstance_AutoPullImage_WaitForReadyFails: verifies error
  propagation when WaitForReady fails
- TestCreateInstance_ImageAlreadyReady_NoAutoPull: verifies no pull
  is triggered when image already exists

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Delete lib/instances/auto_pull_test.go (mock-based unit tests) and add
TestCreateInstance_AutoPullImage in cmd/api/api/instances_test.go that
follows the existing integration test patterns. The new test:

- Checks for /dev/kvm, skips if unavailable
- Creates a newTestService
- Does NOT pre-pull the image (tests auto-pull)
- Ensures system files with system.NewManager
- Calls CreateInstance with alpine:latest and networkEnabled: false
- Asserts 201 response
- Cleans up by deleting the instance

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When CreateInstance encounters a missing image, it now starts the pull
and waits up to 5 seconds. If the image isn't ready in time, returns
an image_not_ready error while allowing the pull to continue in the
background so a subsequent run finds it ready.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sjmiller609 sjmiller609 marked this pull request as ready for review March 17, 2026 18:46
Copy link

@masnwilliams masnwilliams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@sjmiller609 sjmiller609 merged commit 4f29634 into main Mar 17, 2026
6 checks passed
@sjmiller609 sjmiller609 deleted the hypeship/auto-pull-on-run branch March 17, 2026 18:59
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.

2 participants