runregistry

package
v1.92.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package runregistry persists discovery records for running docker-agent processes that expose a control plane (see run --listen). Records live as per-pid JSON files under <data dir>/runs so external tools can enumerate live runs and connect to them.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoRun = errors.New("no live docker-agent run found; start one with: docker-agent run --listen 127.0.0.1:0")

ErrNoRun is returned when no live run can be found that satisfies the caller's request (empty registry, or no record matches the target).

Functions

This section is empty.

Types

type Record

type Record struct {
	PID       int       `json:"pid"`
	Addr      string    `json:"addr"`
	SessionID string    `json:"session_id"`
	Agent     string    `json:"agent,omitempty"`
	StartedAt time.Time `json:"started_at"`
}

Record describes a running docker-agent that exposes a control plane.

type Registry added in v1.92.0

type Registry struct {
	// contains filtered or unexported fields
}

Registry persists and queries run records stored as per-pid JSON files under a single directory. Construct one with New or Default; methods carry no shared mutable state, so distinct instances (e.g. one per test) are fully independent and safe to use concurrently.

func Default added in v1.92.0

func Default() *Registry

Default returns a Registry rooted at the user's data dir (<data dir>/runs).

func New added in v1.92.0

func New(dir string) *Registry

New returns a Registry that stores records under dir.

func (*Registry) Dir added in v1.92.0

func (r *Registry) Dir() string

Dir is the directory holding run records.

func (*Registry) Find added in v1.92.0

func (r *Registry) Find(target string) (Record, error)

Find resolves a target reference to a single live record.

An empty target returns the most recently started run. A numeric target is matched by PID; a target starting with "http://" or "https://" is matched against record addresses; anything else is matched as a (possibly partial) session ID. PID and address matches are exact. Session-ID matching prefers exact equality and only falls back to substring matching when no record matches exactly; ambiguous substring matches return an error so callers don't act on the wrong session.

func (*Registry) Latest added in v1.92.0

func (r *Registry) Latest() (Record, bool, error)

Latest returns the most recently started live record, or false when none.

func (*Registry) List added in v1.92.0

func (r *Registry) List() ([]Record, error)

List returns every record currently registered. Stale records (whose pid is no longer alive) are skipped and best-effort removed.

func (*Registry) Write added in v1.92.0

func (r *Registry) Write(rec Record) (func(), error)

Write atomically persists a record for the current process and returns a cleanup func that removes it. Cleanup is safe to call more than once.

The registry directory is created with 0o700 so other local users cannot enumerate live PIDs/addresses by listing it. Individual records are still written with 0o600 for the same reason. Writes go through a sibling temp file + rename so concurrent readers never see torn JSON.

Jump to

Keyboard shortcuts

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