feat: Add OCI artifact support for runtime configurations sharing #1212
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit implements comprehensive OCI artifact support for exporting and importing
runtime configurations, enabling users to store and share ToolHive configurations
as OCI artifacts in container registries. The implementation follows clean architecture
principles with proper separation of concerns.
Key Features
CLI Enhancements
Extended
thv export
to support both file paths and OCI referencesAutomatic detection of OCI references vs file paths
Maintained backward compatibility with existing file-based exports
Clear messaging: "to file" vs "to OCI registry"
Modified
thv run
to automatically detect OCI runtime configuration artifactsGraceful fallback when OCI references aren't runtime config artifacts
Seamless integration with existing container image and registry workflows
Architecture & Code Organization
Clean Separation of Concerns
pkg/oci/
- General OCI registry operations and utilitiesclient.go
: Generic OCI client with authenticationutils.go
: Reference validation, tag extraction, utilitiespkg/runner/export/
- RunConfig-specific export/import operationsoci.go
: Specialized OCI operations for runtime configurationsKey Components
OCI Client (
pkg/oci/client.go
):CreateRepository()
: Authenticated ORAS repository clientsOCI Utilities (
pkg/oci/utils.go
):ValidateReference()
: OCI reference validationIsOCIReference()
: Smart detection of OCI vs file referencesExtractTag()
: Tag parsing utilitiesRunConfig Exporter (
pkg/runner/export/oci.go
):PushRunConfig()
: Push runtime configurations to registriesPullRunConfig()
: Pull runtime configurations from registriesapplication/vnd.toolhive.runconfig.v1+json
Implementation Details
Registry-Only Architecture
Following ORAS best practices, OCI artifacts are stored exclusively in registries:
Authentication & Security
Error Handling & User Experience
Updated Components
Export Command (
cmd/thv/app/export.go
):oci.ValidateReference()
Run Command (
cmd/thv/app/run.go
):Retriever (
pkg/runner/retriever/retriever.go
):GetMCPServer()
to try OCI artifacts before container imagesRun Flags (
cmd/thv/app/run_flags.go
):BuildRunnerConfig()
to detect OCI runtime configurationsUsage Examples
Dependencies & Technology
oras.land/oras-go/v2
for OCI artifact operationsgithub.com/google/go-containerregistry
for reference validationTesting & Quality
Comprehensive Test Coverage:
Code Quality:
Documentation
thv export
andthv run
commandsdocs/cli/thv_export.md
,docs/cli/thv.md
)Backward Compatibility
This implementation extends ToolHive's capabilities while maintaining its core principles
of simplicity, security, and reliability. The clean architecture ensures the codebase
remains maintainable and extensible for future OCI artifact types.
Signed-off-by: Juan Antonio Osorio ozz@stacklok.com