Skip to content

Reuse local image when already present for pinned tags#339

Merged
gtsiolis merged 2 commits into
mainfrom
pro-323-reuse-local-image-when-already-present-b1ca
Jun 25, 2026
Merged

Reuse local image when already present for pinned tags#339
gtsiolis merged 2 commits into
mainfrom
pro-323-reuse-local-image-when-already-present-b1ca

Conversation

@gtsiolis

@gtsiolis gtsiolis commented Jun 24, 2026

Copy link
Copy Markdown
Member

Summary

lstk start ran docker pull on every start, even when the image was already present locally — rt.PullImage was unconditional. On slow networks this meant repeated multi-minute re-downloads for no benefit.

This adds ImageExists to the Runtime interface (backed by ImageInspect + errdefs.IsNotFound on Docker) and, in pullImages, skips the pull when a pinned-tag image is already local — emitting a Using local image message instead and recording pulled[name]=false so start telemetry (LifecycleStartSuccess.Pulled) doesn't over-count. Stopped-container cleanup (rt.Remove) still runs on both branches, and post-pull license validation is unaffected since the image is present.

A net-new probe is needed because GetImageVersion can't double as one: it errors both when the image is absent and when LOCALSTACK_BUILD_VERSION is missing, conflating the two.

Scope

Skip-if-present applies to pinned tags only. Floating latest/empty still pulls until the pull_policy work lands (PRO-325).

Tests

  • Integration: pre-pull a pinned image, run lstk start, assert Using local image present and Pulling absent.
  • Unit (MockRuntime): ImageExists true → 0 PullImage calls, pulled[name]==false; false → 1 call, pulled[name]==true.
CLI output using local image
Screenshot 2026-06-24 at 20 59 29

lstk ran docker pull on every start, even when the image was already
present locally. On slow networks this meant repeated multi-minute
re-downloads for no benefit.

Add ImageExists to the Runtime interface (backed by ImageInspect +
errdefs.IsNotFound on Docker) and, in pullImages, skip the pull for
pinned tags whose image is already local. Emit a "Using local image"
message and record pulled[name]=false so start telemetry does not
over-count. Floating latest/empty tags still pull until pull_policy
support lands.

Generated with [Linear](https://linear.app/localstack/issue/PRO-323/reuse-local-image-when-already-present#agent-session-e6210615)

Co-authored-by: linear-code[bot] <222613912+linear-code[bot]@users.noreply.github.com>
@gtsiolis gtsiolis self-assigned this Jun 24, 2026
@gtsiolis gtsiolis added semver: patch docs: needed Pull request requires documentation updates labels Jun 24, 2026
@gtsiolis gtsiolis marked this pull request as ready for review June 24, 2026 18:01
@gtsiolis gtsiolis requested a review from a team as a code owner June 24, 2026 18:01
…olated

The previous version started a real LocalStack bound to the shared host
port 4566, which collided with the external-container tests after CI's
sorted-name shard reshuffle and caused a leaked-container cascade.

Tag the lightweight alpine test image under a pinned localstack-pro tag
instead: lstk still skips the pull and emits "Using local image" (the
decision under test, emitted before the container starts), but the
stand-in image exits immediately so start fails fast. A dedicated host
port (4599) keeps it off 4566. No real image pull or auth token needed.

Generated with [Linear](https://linear.app/localstack/issue/PRO-323/reuse-local-image-when-already-present#agent-session-e6210615)

Co-authored-by: linear-code[bot] <222613912+linear-code[bot]@users.noreply.github.com>

@anisaoshafi anisaoshafi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Good improvement, nice thought. No need to pull images that are already downloaded 💯 Thanks!

@gtsiolis gtsiolis merged commit 90daffd into main Jun 25, 2026
13 checks passed
@gtsiolis gtsiolis deleted the pro-323-reuse-local-image-when-already-present-b1ca branch June 25, 2026 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs: needed Pull request requires documentation updates semver: patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants