Documentation
¶
Overview ¶
Package localmode holds the pieces shared by the CLI's dev verb and the control plane's local-instance behavior.
Index ¶
- Constants
- Variables
- func AdminFilePath(dataDir string) string
- func AppURL(host string, httpPort int) string
- func ClearPortExchange(dataDir string)
- func ClearState(dataDir string)
- func DashboardURL(port int) string
- func DetectDocker(env DockerEnv) (string, error)
- func DockerFix(goos string, tried []string) string
- func DockerSocketCandidates(env DockerEnv) []string
- func Enabled(getenv func(string) string) bool
- func LoopbackFree(port int) bool
- func PortsFilePath(dataDir string) string
- func PublicHTTPPort(getenv func(string) string) int
- func RequestReset(dataDir string) error
- func ResetMarkerPath(dataDir string) string
- func ResetRequested(dataDir string) bool
- func RoleLabel(role string) string
- func SavePorts(dataDir string, p Ports) error
- func StateFilePath(dataDir string) string
- func ValidateListenAddr(addr string) error
- func Wipe(dataDir string) error
- func WithdrawPortRequest(dataDir string) bool
- func WritePortRequest(dataDir string, r PortRequest) error
- func WritePortResult(dataDir string, r PortResult) error
- func WriteState(st State) error
- type Admin
- type DockerEnv
- type PortEnv
- type PortFree
- type PortPrefs
- type PortRequest
- type PortResult
- type PortState
- type Ports
- type RoleReport
- type RoleSpec
- type State
Constants ¶
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" )
const ( EnvDashboardPort = "APP_LOCAL_DASHBOARD_PORT" EnvHTTPPort = "APP_LOCAL_HTTP_PORT" EnvHTTPSPort = "APP_LOCAL_HTTPS_PORT" EnvAgentPort = "APP_LOCAL_AGENT_PORT" EnvHTTPFallbackPort = "APP_LOCAL_HTTP_FALLBACK_PORT" EnvHTTPSFallbackPort = "APP_LOCAL_HTTPS_FALLBACK_PORT" EnvPortScan = "APP_LOCAL_PORT_SCAN" // EnvPublicHTTPPort is the port browsers use for apps when a forward sits in front of the ingress. EnvPublicHTTPPort = "APP_LOCAL_PUBLIC_HTTP_PORT" )
Env names. They seed a first start; ports saved afterwards win.
const ( // DefaultDashboardPort matches the CLI's default API address. DefaultDashboardPort = 8080 // MaxPort is the highest TCP port. MaxPort = 65535 )
const ( RoleDashboard = "dashboard" RoleHTTP = "app_http" RoleHTTPS = "app_https" RoleAgent = "agent" )
Port roles.
Variables ¶
var ErrDockerUnreachable = errors.New("docker is not reachable")
ErrDockerUnreachable is returned when no candidate socket accepts a connection.
Functions ¶
func AdminFilePath ¶
AdminFilePath is where the generated admin credential is kept, mode 0600.
func AppURL ¶
AppURL is the address of an app served on host by an HTTP ingress listening on httpPort.
func ClearPortExchange ¶
func ClearPortExchange(dataDir string)
ClearPortExchange drops requests and results left by an earlier run.
func DashboardURL ¶
DashboardURL is the dashboard address for a loopback port.
func DetectDocker ¶
DetectDocker returns the first socket that exists and accepts a connection.
func DockerSocketCandidates ¶
DockerSocketCandidates lists engine sockets in preference order: explicit settings first, then Docker Desktop's per-user sockets, then the system default.
func LoopbackFree ¶
LoopbackFree is the real PortFree: a listen-and-close probe.
func PortsFilePath ¶
PortsFilePath is where a local instance keeps its chosen ports.
func PublicHTTPPort ¶
PublicHTTPPort is the forwarded app port from EnvPublicHTTPPort, or 0 when unset or invalid.
func ResetMarkerPath ¶
ResetMarkerPath is the file whose presence asks the supervisor to wipe the data dir on the next relaunch.
func ResetRequested ¶
ResetRequested reports whether a reset marker is present.
func StateFilePath ¶
StateFilePath is where the running supervisor records its pid and URLs.
func ValidateListenAddr ¶
ValidateListenAddr rejects a dashboard listen address that is reachable beyond this machine.
func Wipe ¶
Wipe removes everything inside dataDir but keeps the directory itself; it refuses a non-empty directory a local instance did not create.
func WithdrawPortRequest ¶
WithdrawPortRequest removes a request nobody picked up and reports whether it was still there.
func WritePortRequest ¶
func WritePortRequest(dataDir string, r PortRequest) error
WritePortRequest leaves a request for the supervisor of dataDir.
func WritePortResult ¶
func WritePortResult(dataDir string, r PortResult) error
WritePortResult records the outcome of a request.
Types ¶
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 ¶
RealDockerEnv is DockerEnv backed by the running process.
type PortEnv ¶
type PortEnv struct {
Probe func(ctx context.Context, port int) PortState
Holder func(ctx context.Context, port int) string
// Owned are ports the instance being changed holds now; a restart releases them.
Owned map[int]bool
// Min is the lowest port the runtime uses.
Min int
Scan int
}
PortEnv is what planning reads from the machine.
type PortPrefs ¶
PortPrefs are the ports a first start asks for and where it searches next.
func PortPrefsFromEnv ¶
PortPrefsFromEnv layers the seed env values over the defaults.
type PortRequest ¶
PortRequest asks a running supervisor to move to other ports.
func TakePortRequest ¶
func TakePortRequest(dataDir string) (PortRequest, bool)
TakePortRequest consumes a waiting request.
type PortResult ¶
type PortResult struct {
ID string `json:"id"`
Applied bool `json:"applied"`
Restored bool `json:"restored"`
Healthy bool `json:"healthy"`
Reason string `json:"reason,omitempty"`
Ports Ports `json:"ports"`
}
PortResult is the supervisor's answer. Healthy false means nothing is running.
func ReadPortResult ¶
func ReadPortResult(dataDir, id string) (PortResult, bool)
ReadPortResult returns the outcome of the request with id, once it exists.
type PortState ¶
type PortState string
PortState is what probing one port found.
const ( PortFreeState PortState = "free" PortInUse PortState = "in_use" // PortDenied means this account may not listen there. PortDenied PortState = "denied" // PortTooLow means the runtime itself does not use ports that low. PortTooLow PortState = "too_low" // PortOwned means the instance being changed already holds it. PortOwned PortState = "yours" )
Port states.
type Ports ¶
type Ports struct {
Dashboard int `json:"dashboard"`
HTTP int `json:"http"`
HTTPS int `json:"https"`
Agent int `json:"agent"`
}
Ports are the loopback ports a local instance listens on.
type RoleReport ¶
type RoleReport struct {
Role string `json:"role"`
Label string `json:"label"`
Requested int `json:"requested"`
State PortState `json:"state"`
Holder string `json:"holder,omitempty"`
Recommended int `json:"recommended"`
Reason string `json:"reason"`
}
RoleReport is the finding for one role.
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"`
// PortChange marks a supervisor that can move ports while running.
PortChange bool `json:"port_change,omitempty"`
}
State is what a running supervisor records so stop and status can find it.