Documentation
¶
Overview ¶
Package server exposes the supervisor over HTTP: the JSON API used by the CLI and dashboard, WebSocket streams, the embedded dashboard itself, and a reverse proxy that serves every server at http://<name>.localhost.
Index ¶
- func ConnContext(ctx context.Context, _ net.Conn) context.Context
- func DashboardHostPath(stateDir string) string
- func IsDashboardHost(host string) bool
- func TokenPath(stateDir string) string
- type ConfigInfo
- type ContainerDetails
- type ContainerRef
- type Credentials
- type DiscoverResult
- type EnvVar
- type Health
- type HealthDetails
- type Hello
- type ListenerView
- type MountView
- type NetworkView
- type Options
- type RemoteOverview
- type Server
- type State
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConnContext ¶
ConnContext gives each connection of the daemon's http.Server a place for its owner check (http.Server.ConnContext), so a keep-alive connection is looked up once rather than on every request.
func DashboardHostPath ¶
DashboardHostPath is where the daemon keeps its dashboard's host name.
func IsDashboardHost ¶
IsDashboardHost reports whether host has the form <label>.localhost of a dashboard host.
Types ¶
type ConfigInfo ¶
type ConfigInfo struct {
Path string `json:"path"`
PathDisplay string `json:"pathDisplay"`
Root string `json:"root"`
Error string `json:"error,omitempty"`
Warnings []string `json:"warnings,omitempty"`
StateDir string `json:"stateDir"`
// Revision changes whenever the file's text changes.
Revision string `json:"revision"`
// Notify mirrors the notify setting for clients that notify themselves.
Notify bool `json:"notify"`
}
ConfigInfo describes the loaded configuration file.
type ContainerDetails ¶
type ContainerDetails struct {
Name string `json:"name"`
ID string `json:"id"`
Image string `json:"image"`
Command string `json:"command"`
Created time.Time `json:"created"`
RestartPolicy string `json:"restartPolicy,omitempty"`
Health *HealthDetails `json:"health,omitempty"`
Error string `json:"error,omitempty"`
Env []EnvVar `json:"env"`
Mounts []MountView `json:"mounts"`
Networks []NetworkView `json:"networks"`
ConfigFiles []string `json:"configFiles,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
}
ContainerDetails is what the dashboard shows about one container.
type ContainerRef ¶
type ContainerRef struct {
Name string `json:"name"`
Service string `json:"service,omitempty"`
Server string `json:"server,omitempty"`
}
ContainerRef names a container and the server it belongs to.
type Credentials ¶
Credentials are the daemon's API token and its dashboard's host name.
func LoadCredentials ¶
func LoadCredentials(stateDir, keepHost string) (Credentials, error)
LoadCredentials returns the token, creating it with private permissions, and a dashboard host: keepHost when it is one (an upgrade carries it over), else a new one, written for local clients. A state directory without a dashboard host predates host-bound sessions, when browsers kept the token itself as a cookie for 127.0.0.1; the token is replaced then, so such cookies stop working.
type DiscoverResult ¶
type DiscoverResult struct {
discover.Suggestion
DirDisplay string `json:"dirDisplay"`
DirConfig string `json:"dirConfig"` // how dir would be written to the config
}
DiscoverResult is a suggestion with a free port reserved for it.
type Health ¶
type Health struct {
App string `json:"app"`
Name string `json:"name"`
Version string `json:"version"`
PID int `json:"pid"`
Port int `json:"port"`
StartedAt time.Time `json:"startedAt"`
// SampleIntervalMs is the spacing of cpuHistory/memHistory samples.
SampleIntervalMs int `json:"sampleIntervalMs"`
// IdleSampleIntervalMs is the spacing of usage samples while no client
// shows usage. Its presence tells events clients they may send
// {"usage": bool} to say whether they show usage now.
IdleSampleIntervalMs int `json:"idleSampleIntervalMs"`
}
Health identifies the daemon to clients probing the port.
type HealthDetails ¶
type HealthDetails struct {
Status string `json:"status"`
FailingStreak int `json:"failingStreak"`
Output string `json:"output,omitempty"`
ExitCode int `json:"exitCode"`
}
HealthDetails is the latest health check result.
type Hello ¶
type Hello struct {
App string `json:"app"`
Version string `json:"version"`
Paired bool `json:"paired"`
Servers *remote.Counts `json:"servers,omitempty"` // only when paired
}
Hello is what a device learns before and after pairing.
type ListenerView ¶
type ListenerView struct {
ports.Listener
CwdDisplay string `json:"cwdDisplay,omitempty"`
Server string `json:"server,omitempty"` // configured server owning the port
Managed bool `json:"managed"` // process started by Portside
Via string `json:"via,omitempty"` // "containers" when a runtime publishes a managed compose port
Protected string `json:"protected,omitempty"` // why it may not be killed
// Container is the container whose published port this is.
Container *ContainerRef `json:"container,omitempty"`
}
ListenerView is a listening process annotated with what Portside knows.
type MountView ¶
type MountView struct {
Type string `json:"type"`
Name string `json:"name,omitempty"`
Source string `json:"source"`
Destination string `json:"destination"`
ReadOnly bool `json:"readOnly,omitempty"`
}
MountView is a volume or bind mount.
type NetworkView ¶
type NetworkView struct {
Name string `json:"name"`
IP string `json:"ip,omitempty"`
Aliases []string `json:"aliases,omitempty"`
}
NetworkView is one network the container is attached to.
type Options ¶
type Options struct {
ConfigError string
Supervisor *supervisor.Supervisor
Docker *docker.Monitor
ConfigPath string
StateDir string
Port int
// PortAuto is true when the config set no port at start, so the daemon
// chose Port itself (the default or a fallback port).
PortAuto bool
UI fs.FS // dashboard assets; nil serves a placeholder
// Token authenticates API clients; empty disables authentication.
Token string
// DashboardHost is the dashboard's own host name, <label>.localhost:
// the only host whose requests may authenticate with the session cookie.
DashboardHost string
// Shutdown is called when a client asks the daemon to exit; restart is
// true when the client starts a daemon again right after.
Shutdown func(restart bool)
// Upgrade re-executes the daemon from the binary at exe (its own when
// empty), keeping servers running. It returns only when that did not
// happen.
Upgrade func(exe string) error
// Remote connects to the daemon on another of the owner's devices.
Remote *remote.Manager
Share *share.Manager
}
Options configure a Server.
type RemoteOverview ¶
RemoteOverview is the answer of GET /api/remote.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the daemon's HTTP surface.
func (*Server) Handler ¶
Handler returns the root handler: it routes by Host between the proxy and the dashboard, and rejects unknown hosts to defeat DNS rebinding. The dashboard itself is served only on its own host; loopback addresses serve the API to signed clients and a page on how to open the dashboard.
func (*Server) PeerHandler ¶
PeerHandler serves requests from the owner's other devices, after package share has verified them. It exposes the API and port tunnels, nothing else.
func (*Server) WatchConfig ¶
WatchConfig reloads the configuration when the file changes on disk.
func (*Server) WatchContainerIssues ¶
WatchContainerIssues notifies once per unhealthy or failed transition for attached containers. A reconnect retains the previous observations.
type State ¶
type State struct {
Warnings []string `json:"warnings,omitempty"`
Daemon Health `json:"daemon"`
Config ConfigInfo `json:"config"`
Servers []supervisor.View `json:"servers"`
Groups []string `json:"groups"`
Docker docker.State `json:"docker"`
// Remote is the connection to another device, null when there is none.
Remote *remote.Info `json:"remote"`
// Paired lists the devices paired with this computer and whether each is
// connected; never sent to those devices.
Paired []share.DeviceStatus `json:"paired,omitempty"`
}
State is everything the dashboard renders.