Documentation
¶
Overview ¶
Package image builds developer service images and loads them into a target Kubernetes cluster via an in-cluster container registry, so that `runtime: kubernetes` services can run locally-built images. This is devx's skaffold-class "build + load" step, run before `kubectl apply`.
Mechanism (validated against the lima k3s dev cluster, 2026-05-23): devx deploys a registry as a Deployment + NodePort Service in-cluster; images are referenced in manifests as localhost:<NodePort>/<name>:<tag>, which every node pulls via its own NodePort with no per-node Docker configuration (Docker's 127.0.0.0/8 insecure default covers it). devx pushes from the host to a node's reachable address:NodePort over an insecure connection.
Index ¶
- Constants
- func Build(ctx context.Context, rt provider.ContainerRuntime, baseDir string, spec Spec, ...) error
- func BuildAndLoad(ctx context.Context, providerName, baseDir, kubeconfig, kctx string, ...) error
- func Push(ctx context.Context, rt provider.ContainerRuntime, ref string) error
- type LocalRegistry
- type Spec
Constants ¶
const ( // RegistryNamespace is where devx's in-cluster registry lives. RegistryNamespace = "devx-registry" // RegistryNodePort is the fixed NodePort the registry is exposed on, so // manifests can deterministically reference localhost:<RegistryNodePort>/<img>. RegistryNodePort = 30500 )
Variables ¶
This section is empty.
Functions ¶
func Build ¶
func Build(ctx context.Context, rt provider.ContainerRuntime, baseDir string, spec Spec, ref string) error
Build builds spec's image with the given container runtime and tags it as ref. Build context and Dockerfile are resolved relative to baseDir. Build output is streamed to the user's terminal.
func BuildAndLoad ¶
func BuildAndLoad(ctx context.Context, providerName, baseDir, kubeconfig, kctx string, specs []Spec) error
BuildAndLoad ensures the in-cluster registry exists, then builds and pushes each spec's image into it, so that runtime: kubernetes manifests can reference localhost:<NodePort>/<name>:<tag>. providerName selects the container backend to build with (e.g. "lima", "podman"; "" or "auto" auto-detects) — pass devx's resolved provider so multi-backend hosts don't fail to auto-detect. baseDir is the service's working directory (build contexts resolve against it); kubeconfig/kctx target the cluster (kctx may be empty for the current context). It is a no-op when specs is empty.
Types ¶
type LocalRegistry ¶
type LocalRegistry struct {
// PushAddr is the host→registry address for pushing images, e.g.
// "100.98.214.120:30500" (a node's reachable address + the NodePort).
PushAddr string
// RefPrefix is the in-cluster image-reference prefix, e.g. "localhost:30500".
// Built images are pushed as <PushAddr>/<name>:<tag> and referenced in
// manifests as <RefPrefix>/<name>:<tag>.
RefPrefix string
}
LocalRegistry describes a deployed in-cluster registry and the addresses needed to use it.
func EnsureRegistry ¶
func EnsureRegistry(ctx context.Context, kubeconfig, kctx string) (*LocalRegistry, error)
EnsureRegistry idempotently deploys the in-cluster registry to the target cluster, waits for it to become Available, and returns the addresses to push to and reference it. When MinIO is present the registry runs HA (2 replicas on S3); otherwise it falls back to a single-replica PVC deployment. kubeconfig and kctx target the cluster (already resolved by the caller); kctx may be empty to use the current context.
func (*LocalRegistry) PushRef ¶
func (r *LocalRegistry) PushRef(name, tag string) string
PushRef returns the host-side push reference for name:tag.
func (*LocalRegistry) Ref ¶
func (r *LocalRegistry) Ref(name, tag string) string
Ref returns the in-cluster image reference for name:tag (what manifests use).
type Spec ¶
type Spec struct {
Name string // image name (required); becomes <RefPrefix>/<Name>:<Tag>
Context string // build context directory (default ".")
Dockerfile string // Dockerfile path, relative to Context (default "Dockerfile")
Tag string // image tag (default "dev")
Platforms []string // target platforms, e.g. ["linux/amd64","linux/arm64"]; empty = builder default (host arch)
}
Spec declares an image devx builds and loads before applying manifests (runtime: kubernetes, kubernetes.images). The built image is pushed as <registry RefPrefix>/<Name>:<Tag> (e.g. localhost:30500/brms-offer:dev) — reference exactly that in your manifests, with imagePullPolicy: Always so a rebuild of the same tag is re-pulled.
func (Spec) ContextOrDefault ¶
ContextOrDefault returns the build context directory, or "." when unset.
func (Spec) DockerfileOrDefault ¶
DockerfileOrDefault returns the Dockerfile path, or "Dockerfile" when unset.
func (Spec) TagOrDefault ¶
TagOrDefault returns the configured tag, or "dev" when unset.