localmode

package
v0.9.0 Latest Latest
Warning

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

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

Documentation

Overview

Package localmode holds the pieces shared by the CLI's dev verb and the control plane's local-instance behavior.

Index

Constants

View Source
const (
	// EnvEnabled turns a control plane into a loopback-only local instance.
	EnvEnabled = "APP_LOCAL_MODE"
	// EnvSupervised tells the control plane a parent will relaunch it after a reset exit.
	EnvSupervised = "APP_RESTART_SUPERVISED"
)
View Source
const (
	// DefaultDashboardPort matches the CLI's default API address.
	DefaultDashboardPort = 8080
)

Variables

View Source
var ErrDockerUnreachable = errors.New("docker is not reachable")

ErrDockerUnreachable is returned when no candidate socket accepts a connection.

Functions

func AdminFilePath

func AdminFilePath(dataDir string) string

AdminFilePath is where the generated admin credential is kept, mode 0600.

func AppURL

func AppURL(host string, httpPort int) string

AppURL is the address of an app served on host by an HTTP ingress listening on httpPort.

func ClearState

func ClearState(dataDir string)

ClearState removes the state file.

func DashboardURL

func DashboardURL(port int) string

DashboardURL is the dashboard address for a loopback port.

func DetectDocker

func DetectDocker(env DockerEnv) (string, error)

DetectDocker returns the first socket that exists and accepts a connection.

func DockerFix

func DockerFix(goos string, tried []string) string

DockerFix is the one-line next step for an operator whose Docker is not reachable.

func DockerSocketCandidates

func DockerSocketCandidates(env DockerEnv) []string

DockerSocketCandidates lists engine sockets in preference order: explicit settings first, then Docker Desktop's per-user sockets, then the system default.

func Enabled

func Enabled(getenv func(string) string) bool

Enabled reports whether getenv says this process is a local instance.

func LoopbackFree

func LoopbackFree(port int) bool

LoopbackFree is the real PortFree: a listen-and-close probe.

func RequestReset

func RequestReset(dataDir string) error

RequestReset drops the reset marker.

func ResetMarkerPath

func ResetMarkerPath(dataDir string) string

ResetMarkerPath is the file whose presence asks the supervisor to wipe the data dir on the next relaunch.

func ResetRequested

func ResetRequested(dataDir string) bool

ResetRequested reports whether a reset marker is present.

func StateFilePath

func StateFilePath(dataDir string) string

StateFilePath is where the running supervisor records its pid and URLs.

func ValidateListenAddr

func ValidateListenAddr(addr string) error

ValidateListenAddr rejects a dashboard listen address that is reachable beyond this machine.

func Wipe

func Wipe(dataDir string) error

Wipe removes everything inside dataDir but keeps the directory itself; it refuses a non-empty directory a local instance did not create.

func WriteState

func WriteState(st State) error

WriteState records st in its data dir.

Types

type Admin

type Admin struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

Admin is the generated sign-in for a local instance.

func LoadOrCreateAdmin

func LoadOrCreateAdmin(dataDir string, random io.Reader) (a Admin, created bool, err error)

LoadOrCreateAdmin reads the stored admin or generates one; created is true only for a new credential.

type DockerEnv

type DockerEnv struct {
	Getenv func(string) string
	Exists func(path string) bool
	Dial   func(socketPath string) error
	GOOS   string
}

DockerEnv is the slice of the process environment socket detection reads.

func RealDockerEnv

func RealDockerEnv(goos string) DockerEnv

RealDockerEnv is DockerEnv backed by the running process.

type PortFree

type PortFree func(port int) bool

PortFree reports whether port can be bound on loopback right now.

type Ports

type Ports struct {
	Dashboard int
	HTTP      int
	HTTPS     int
	Agent     int
}

Ports are the loopback ports a local instance listens on.

func ChoosePorts

func ChoosePorts(requestedDashboard int, free PortFree) (Ports, error)

ChoosePorts picks the dashboard port (fixed when requested, else the first free one from 8080) and ingress ports (80 and 443 when free, else the first free high ports).

type State

type State struct {
	PID       int       `json:"pid"`
	DataDir   string    `json:"data_dir"`
	Dashboard string    `json:"dashboard_url"`
	HTTPPort  int       `json:"http_port"`
	HTTPSPort int       `json:"https_port"`
	Started   time.Time `json:"started"`
}

State is what a running supervisor records so stop and status can find it.

func ReadState

func ReadState(dataDir string) (st State, ok bool, err error)

ReadState loads the state recorded in dataDir; ok is false when none exists.

Jump to

Keyboard shortcuts

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