imagecache

package
v0.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package imagecache provides content-hash based GHCR reuse for QA E2E and setup platform images. Unchanged component hashes pull from ghcr.io instead of rebuilding.

Index

Constants

View Source
const (
	ActionReuse = "reuse"
	ActionBuild = "build"

	// ContentHashLabel is stored on the single local :latest image. The next
	// run compares the checkout hash to this label and rebuilds only on a miss.
	ContentHashLabel = "mcp-runtime.e2e-content-hash"
)

Variables

View Source
var Specs = map[string]Spec{
	"operator": {
		Component:  "operator",
		UseMake:    true,
		GoPackage:  "cmd/operator",
		Dockerfile: "Dockerfile.operator",
		HashPaths: []string{
			"Dockerfile.operator",
			"Makefile.operator",
			"go.mod",
			"go.sum",
		},
	},
	"gateway-proxy": {
		Component:  "gateway-proxy",
		GoPackage:  "services/mcp-gateway",
		Dockerfile: "services/mcp-gateway/Dockerfile",
		Context:    ".",
		HashPaths:  goServiceHashPaths("github.com/mcp-runtime/mcp-runtime/services/mcp-gateway"),
	},
	"platform-api": {
		Component:  "platform-api",
		GoPackage:  "services/platform-api",
		Dockerfile: "services/platform-api/Dockerfile",
		Context:    ".",
		HashPaths:  goServiceHashPaths("platform-api"),
	},
	"runtime-api": {
		Component:  "runtime-api",
		GoPackage:  "services/runtime-api",
		Dockerfile: "services/runtime-api/Dockerfile",
		Context:    ".",
		HashPaths:  goServiceHashPaths("runtime-api"),
	},
	"analytics-api": {
		Component:  "analytics-api",
		GoPackage:  "services/analytics-api",
		Dockerfile: "services/analytics-api/Dockerfile",
		Context:    ".",
		HashPaths:  goServiceHashPaths("analytics-api"),
	},
	"ingest": {
		Component:  "ingest",
		GoPackage:  "services/ingest",
		Dockerfile: "services/ingest/Dockerfile",
		Context:    ".",
		HashPaths:  goServiceHashPaths("ingest"),
	},
	"processor": {
		Component:  "processor",
		GoPackage:  "services/processor",
		Dockerfile: "services/processor/Dockerfile",
		Context:    ".",
		HashPaths:  goServiceHashPaths("processor"),
	},
	"ui": {
		Component:  "ui",
		GoPackage:  "services/ui",
		Dockerfile: "services/ui/Dockerfile",
		Context:    ".",
		HashPaths:  append(goServiceHashPaths("ui"), "services/ui/frontend"),
	},
	"doctor-smoke": {
		Component:  "doctor-smoke",
		GoPackage:  "cmd/doctor-smoke",
		Dockerfile: "services/doctor-smoke/Dockerfile",
		Context:    ".",
		HashPaths: []string{
			"services/doctor-smoke/Dockerfile",
			"go.mod",
			"go.sum",
		},
	},
	"e2e-registry": {
		Component:  "e2e-registry",
		Dockerfile: "test/e2e/registry.Dockerfile",
		Context:    ".",
		HashPaths: []string{
			"test/e2e/registry.Dockerfile",
		},
	},
}

Specs maps canonical component names to build/hash inputs. Names align with update.builtImageSpecs plus e2e-registry.

Functions

func CacheRef

func CacheRef(registry, component, hash, platform string) string

CacheRef builds ghcr.io/.../<component>:<hash>-<architecture>.

func ComponentFromLocalImage

func ComponentFromLocalImage(image string) string

ComponentFromLocalImage maps a local docker tag used by qa-e2e/setup to a Spec name.

func ContentHash

func ContentHash(repoRoot, component string) (string, error)

ContentHash returns the target platform's source hash using environment defaults for the platform. Use ContentHashForPlatform when the target is known.

func ContentHashForPlatform

func ContentHashForPlatform(repoRoot, component, platform string) (string, error)

ContentHashForPlatform hashes the source files compiled into a component for the requested platform, plus its Docker and module inputs.

func DefaultRegistry

func DefaultRegistry() string

DefaultRegistry returns ghcr.io/<owner>/mcp-runtime.

func Enabled

func Enabled() bool

Enabled reports whether content-hash GHCR caching is turned on. Opt in with E2E_IMAGE_CACHE=1 or MCP_SETUP_IMAGE_CACHE=1. E2E_IMAGE_CACHE=0 disables even when setup cache is set. E2E_IMAGE_CACHE=local is the VM Docker cache and is not GHCR.

func LocalLatest

func LocalLatest() bool

LocalLatest reports whether reuse compares the checkout hash to the single local Docker image instead of a registry of historical tags.

func PushEnabled

func PushEnabled() bool

PushEnabled reports whether newly built images should be pushed to GHCR.

Types

type Options

type Options struct {
	// Registry is the GHCR prefix without trailing slash, e.g.
	// ghcr.io/mcp-runtime/mcp-runtime. Empty uses DefaultRegistry().
	Registry string
	// Platform is the architecture of the image being built or reused.
	Platform string
	// Push enables pushing newly built images to GHCR.
	Push bool
	// Progress receives human-readable status lines (may be nil).
	Progress func(string)
	// Out receives docker command output (may be nil).
	Out io.Writer

	// Injectable for tests.
	ManifestExists func(ctx context.Context, image string) (bool, error)
	Pull           func(ctx context.Context, image string) error
	Tag            func(ctx context.Context, source, target string) error
	PushImage      func(ctx context.Context, image string) error
	InspectLabel   func(ctx context.Context, image, label string) (value string, found bool, err error)
	StampLabel     func(ctx context.Context, image, label, value string) error
	PruneDangling  func(ctx context.Context) error
}

Options controls GHCR pull/push behavior for EnsureLocalImage.

func OptionsFromEnv

func OptionsFromEnv() Options

OptionsFromEnv fills Registry and Push from environment defaults.

type Result

type Result struct {
	Action     string
	Hash       string
	CacheRef   string
	LocalImage string
}

Result describes whether EnsureLocalImage reused or built.

func EnsureLocalImage

func EnsureLocalImage(ctx context.Context, repoRoot, component, localImage string, opts Options, buildFn func() error) (Result, error)

EnsureLocalImage makes localImage available: on GHCR hash hit pull+retag; otherwise run buildFn then optionally push the hash-tagged ref to GHCR.

func EnsureLocalLatest

func EnsureLocalLatest(ctx context.Context, repoRoot, component, localImage string, opts Options, buildFn func() error) (Result, error)

EnsureLocalLatest reuses localImage when its content-hash label matches this checkout. A miss builds once, stamps that same tag, and drops the previous dangling image. No registry and no historical tags are kept.

type Spec

type Spec struct {
	Component  string
	Dockerfile string // relative to repo root; empty when UseMake
	Context    string // relative to repo root; empty means "."
	UseMake    bool
	// GoPackage is the binary package directory relative to the repo root.
	// Its local transitive imports are hashed for the selected target platform.
	GoPackage string
	// HashPaths cover non-Go build inputs relative to the repo root.
	HashPaths []string
}

Spec describes how to hash and build one platform component image.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL