Skip to content

Use catalog API to resolve latest emulator version#101

Open
anisaoshafi wants to merge 3 commits intomainfrom
drg-504
Open

Use catalog API to resolve latest emulator version#101
anisaoshafi wants to merge 3 commits intomainfrom
drg-504

Conversation

@anisaoshafi
Copy link
Contributor

@anisaoshafi anisaoshafi commented Mar 11, 2026

Currently to resolve latest version, we inspect the local Docker image.

This PR changes it so that we rely on the version set in the catalog API response.

If platform API is down or response changes falls back to inspecting the local Docker image.

@anisaoshafi anisaoshafi force-pushed the drg-504 branch 2 times, most recently from 2148708 to 845bbfd Compare March 11, 2026 16:57
@anisaoshafi anisaoshafi marked this pull request as ready for review March 11, 2026 17:02
@coderabbitai
Copy link

coderabbitai bot commented Mar 11, 2026

📝 Walkthrough

Walkthrough

Adds PlatformClient.GetLatestCatalogVersion and its tests, a generated MockPlatformAPI, and container start logic to resolve "latest"/empty image tags via the catalog API with a Docker-inspection fallback; integrates resolved versions into existing license/start flows and updates related tests.

Changes

Cohort / File(s) Summary
Catalog client & tests
internal/api/client.go, internal/api/catalog_version_test.go
Adds GetLatestCatalogVersion(ctx, emulatorType) and catalogVersionResponse; implements HTTP GET to /v1/license/catalog/{emulatorType}/version, JSON decoding, validation, and comprehensive unit tests for success, HTTP errors, missing/empty fields, timeouts, and network failure.
Generated API mocks
internal/api/mock_platform_api.go
Adds GoMock-generated MockPlatformAPI and recorder covering PlatformAPI methods including the new GetLatestCatalogVersion.
Version resolution & start changes
internal/container/start.go, internal/container/start_test.go
Adds EmulatorType to ContainerConfig; introduces resolve flows that replace "latest"/empty tags by querying the catalog (2s timeout) and falling back to Docker image inspection; refactors license/version usage and adds unit tests for resolution and fallback behaviors.
Runtime struct change
internal/runtime/runtime.go
Adds exported EmulatorType string field to ContainerConfig struct.

Sequence Diagram

sequenceDiagram
    participant Client as License Validator
    participant Resolver as resolveVersion()
    participant CatalogAPI as Platform Catalog API
    participant Docker as Docker Runtime

    Client->>Resolver: resolveVersion(ctx, emulatorType, tag)
    alt Pinned tag (non-"latest" & non-empty)
        Resolver-->>Client: return pinned tag
    else tag empty or "latest"
        Resolver->>CatalogAPI: GET /v1/license/catalog/{emulatorType}/version
        alt API returns 200 with valid {emulator_type, version}
            CatalogAPI-->>Resolver: { emulator_type, version }
            Resolver-->>Client: return catalog version
        else API timeout/failure or invalid response
            Resolver->>Docker: inspect local image for version
            alt Docker returns version
                Docker-->>Resolver: local image version
                Resolver-->>Client: return local version
            else Docker failure
                Resolver-->>Client: return error
            end
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • carole-lavillonniere
  • silv-io
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding catalog API integration to resolve the latest emulator version, which aligns with all file changes.
Description check ✅ Passed The pull request description accurately describes the changeset: implementing catalog API-based version resolution with Docker image inspection fallback.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch drg-504

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@internal/api/client.go`:
- Around line 277-279: The code currently only checks for empty fields in
versionResp; change the guard in the function handling catalog responses to also
compare versionResp.EmulatorType with the requested emulatorType and return an
error on mismatch (e.g., "unexpected emulator_type: got=%q want=%q") so a
response for the wrong emulator is rejected; update the test file
catalog_version_test.go to add a regression test that simulates a response with
a non-empty but non-matching versionResp.EmulatorType and asserts that the
function returns an error.

In `@internal/container/start.go`:
- Around line 254-255: The fallback log uses log.Printf and bypasses the output
sink; update resolveVersion to accept an output.Sink parameter (thread the sink
from Start into resolveVersion and any callers like resolveVersion(...)),
replace the log.Printf call with the appropriate typed event (e.g.
output.EmitWarning or output.EmitNote) using the passed sink and include the
error in the message, and add the necessary import of internal/output; ensure
callers are updated to pass the existing sink so the message respects
non‑TTY/sink behavior.
- Line 249: The call to platformClient.GetLatestCatalogVersion incorrectly
passes containerConfig.ProductName (Docker product name) instead of the emulator
key; change the argument to containerConfig.Type so
GetLatestCatalogVersion(apiCtx, containerConfig.Type) is used. Locate the call
to GetLatestCatalogVersion in start.go and replace the ProductName parameter
with Type, keeping the apiCtx and error handling intact; ensure tests that mock
GetLatestCatalogVersion expect the emulator key value (e.g., "aws") rather than
the Docker product name.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 9eeef742-c5ca-47fa-99e1-67552444b31b

📥 Commits

Reviewing files that changed from the base of the PR and between aa93b36 and 845bbfd.

📒 Files selected for processing (5)
  • internal/api/catalog_version_test.go
  • internal/api/client.go
  • internal/api/mock_platform_api.go
  • internal/container/start.go
  • internal/container/start_test.go

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
internal/container/start.go (1)

248-248: ⚠️ Potential issue | 🔴 Critical

Use containerConfig.Type instead of containerConfig.ProductName for the catalog API call.

The GetLatestCatalogVersion method expects an emulator type parameter (e.g., "aws") to construct the URL /v1/license/catalog/{emulatorType}/version. However, ProductName returns the Docker image product name ("localstack-pro"), causing the API call to fail and always fall back to Docker image inspection.

🐛 Proposed fix
-	v, err := platformClient.GetLatestCatalogVersion(apiCtx, containerConfig.ProductName)
+	v, err := platformClient.GetLatestCatalogVersion(apiCtx, containerConfig.Type)

Note: This requires adding a Type field to runtime.ContainerConfig if it doesn't already exist, or passing the type separately to resolveVersion.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/container/start.go` at line 248, The call to
platformClient.GetLatestCatalogVersion in resolveVersion is using
containerConfig.ProductName but the API expects an emulator type; change the
argument to containerConfig.Type (i.e., use the emulator type) when calling
GetLatestCatalogVersion; if runtime.ContainerConfig lacks a Type field, add it
(or pass the type into resolveVersion) and ensure any call sites that construct
ContainerConfig populate Type accordingly so the URL
/v1/license/catalog/{emulatorType}/version is built correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@internal/container/start.go`:
- Line 248: The call to platformClient.GetLatestCatalogVersion in resolveVersion
is using containerConfig.ProductName but the API expects an emulator type;
change the argument to containerConfig.Type (i.e., use the emulator type) when
calling GetLatestCatalogVersion; if runtime.ContainerConfig lacks a Type field,
add it (or pass the type into resolveVersion) and ensure any call sites that
construct ContainerConfig populate Type accordingly so the URL
/v1/license/catalog/{emulatorType}/version is built correctly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: e78c2fc7-dbd7-4fdb-9848-bf5ce33ad31b

📥 Commits

Reviewing files that changed from the base of the PR and between 845bbfd and ea0acd7.

📒 Files selected for processing (1)
  • internal/container/start.go

@anisaoshafi anisaoshafi marked this pull request as draft March 11, 2026 17:29
@anisaoshafi anisaoshafi force-pushed the drg-504 branch 2 times, most recently from 1fcbccc to 0a8f759 Compare March 11, 2026 19:15
@anisaoshafi anisaoshafi marked this pull request as ready for review March 12, 2026 11:09
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