dockerproxy

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dockerproxy is the per-runner Docker API proxy. It passes every request through (including hijacked attach/exec streams and builds) and only rewrites create calls so that everything a job creates is labelled, placed in the instance cgroup slice and wired to this proxy instead of the real socket.

Index

Constants

View Source
const DefaultMaxBody = 10 << 20

DefaultMaxBody bounds the request bodies the proxy buffers for rewriting.

Variables

This section is empty.

Functions

func Serve added in v0.1.2

func Serve(ctx context.Context, s Spec, o ServeOptions) error

Serve runs the proxy until ctx is done or the runner container is gone, and removes the socket on the way out.

func WriteSpec added in v0.1.2

func WriteSpec(path string, s Spec) error

WriteSpec writes the spec as a 0600 file, atomically.

Types

type Config

type Config struct {
	Socket      string            `json:"socket"`        // unix socket the proxy listens on
	Upstream    string            `json:"upstream"`      // real Docker socket
	Runner      string            `json:"runner"`        // runner name stamped on everything
	Instance    string            `json:"instance"`      // instance stamped on everything
	HostID      string            `json:"host_id"`       // host id stamped on everything
	Slice       string            `json:"slice"`         // HostConfig.CgroupParent for job containers
	OOMScoreAdj int               `json:"oom_score_adj"` // HostConfig.OomScoreAdj for job containers
	CacheBinds  []string          `json:"cache_binds"`   // "host:container[:opts]" appended to job containers
	CacheEnv    map[string]string `json:"cache_env"`     // env appended to job containers
	// AllowedBinds are host paths (and everything under them) a job may
	// bind-mount; anything else outside named volumes is refused.
	AllowedBinds []string `json:"allowed_binds"`
	// PersistentNames are path.Match globs on container names. A container
	// created with a matching ?name= is labelled role=persistent without a
	// runner: it survives runner cleanup and every runner of the instance
	// may use it.
	PersistentNames []string `json:"persistent_names"`
	// PullLock, when set, is the cross-process pull lock file (see package
	// pulllock): image pulls and builds hold it shared so image GC, in the
	// daemon, can exclude them.
	PullLock string       `json:"pull_lock"`
	MaxBody  int64        `json:"max_body"` // 0 = DefaultMaxBody
	Log      *slog.Logger `json:"-"`        // nil = discard
}

Config configures one proxy. The JSON form is the on-disk spec read by the out-of-process proxy (see Spec).

type Gate

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

Gate is a Pause/Resume/InFlight view of a proxy.

func (Gate) InFlight

func (g Gate) InFlight() int

InFlight is the number of pulls in progress.

func (Gate) Pause

func (g Gate) Pause()

Pause stops new image pulls.

func (Gate) Resume

func (g Gate) Resume()

Resume allows image pulls again.

type Proxy

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

Proxy is a running per-runner proxy.

func New

func New(cfg Config) (*Proxy, error)

New starts a proxy listening on cfg.Socket.

func (*Proxy) Close

func (p *Proxy) Close() error

Close stops the proxy, releases blocked pulls and removes the socket.

func (*Proxy) Gate

func (p *Proxy) Gate() Gate

Gate adapts the proxy to the Pause/Resume/InFlight shape used by image GC.

func (*Proxy) InFlightPulls

func (p *Proxy) InFlightPulls() int

InFlightPulls is the number of image pulls currently proxied.

func (*Proxy) Labels

func (p *Proxy) Labels() map[string]string

Labels returns the ownership labels the proxy stamps (role=job).

func (*Proxy) PausePulls

func (p *Proxy) PausePulls()

PausePulls blocks new image pulls (they wait, they do not fail). Calls nest.

func (*Proxy) ResumePulls

func (p *Proxy) ResumePulls()

ResumePulls undoes one PausePulls; pulls proceed when the last is undone.

func (*Proxy) ServeHTTP

func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

func (*Proxy) Socket

func (p *Proxy) Socket() string

Socket returns the proxy's socket path.

type ServeOptions added in v0.1.2

type ServeOptions struct {
	Log *slog.Logger
	// PollEvery is how often the runner container is checked; 0 = 10s.
	PollEvery time.Duration
	// StartGrace is how long the container may stay missing before it was
	// ever seen (the proxy starts before the runner is created); 0 = 5m.
	StartGrace time.Duration
}

ServeOptions are injectable for tests.

type Spec added in v0.1.2

type Spec struct {
	Config Config `json:"config"`
	// RunnerContainer is the runner container's name or ID. The proxy exits
	// once that container no longer exists.
	RunnerContainer string `json:"runner_container"`
	LogLevel        string `json:"log_level,omitempty"`
}

Spec is everything `runner-warden proxy --spec <file>` needs to serve one runner's proxy in its own process (outside the daemon, so it survives a daemon restart).

func ReadSpec added in v0.1.2

func ReadSpec(path string) (Spec, error)

ReadSpec reads a spec written by WriteSpec.

Jump to

Keyboard shortcuts

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