Documentation
¶
Overview ¶
Package runtime runs servers as Docker containers: one hardened container and one named volume per server. The volume holds the server's data and outlives the container; only deleting the server removes it.
Index ¶
- Constants
- Variables
- func ContainerName(serverID string) string
- func PingAddress(inst Instance, spec Spec, publishedHost string) (string, error)
- func PluginFile(sha256 []byte) string
- func VolumeName(serverID string) string
- type Instance
- type Plugin
- type Port
- type Runtime
- func (r *Runtime) Ensure(ctx context.Context, spec Spec) (created, pending bool, err error)
- func (r *Runtime) Inspect(ctx context.Context, serverID string) (Instance, bool, error)
- func (r *Runtime) Logs(ctx context.Context, serverID string, tail int) (io.ReadCloser, error)
- func (r *Runtime) Managed(ctx context.Context) ([]string, error)
- func (r *Runtime) Remove(ctx context.Context, serverID string, stopTimeout time.Duration) error
- func (r *Runtime) SendCommand(ctx context.Context, serverID, line string) error
- func (r *Runtime) Setup(ctx context.Context, self string) error
- func (r *Runtime) Start(ctx context.Context, serverID string) error
- func (r *Runtime) Stop(ctx context.Context, serverID string, timeout time.Duration) error
- func (r *Runtime) Usage(ctx context.Context, serverID string) (cpu time.Duration, memoryBytes int64, err error)
- func (r *Runtime) Version(ctx context.Context) (string, error)
- type Spec
Constants ¶
const ( // Network is shared by server containers and the Agent, which checks // servers by their address on it. Network = "shardkeep-servers" LabelManaged = "gg.shardkeep.managed" LabelServer = "gg.shardkeep.server-id" LabelHash = "gg.shardkeep.config-hash" // LabelHashNow covers the configuration that must apply at once: // everything except the software and plugins, which a running server // takes on at its next start. LabelHashNow = "gg.shardkeep.config-hash-now" // LabelInstance marks the containers of a test Agent sharing its // engine with others (see instance); real Agents skip them. LabelInstance = "gg.shardkeep.e2e-instance" )
const PluginsDir = ".shardkeep/plugins"
PluginsDir is where managed plugin jars are installed, relative to the server's data directory; the file manager cannot change it.
Variables ¶
var ErrNoAddress = errors.New("the server has no address on the server network")
ErrNoAddress is returned when a running server has no address to ping.
Functions ¶
func ContainerName ¶
ContainerName and VolumeName name a server's resources.
func PingAddress ¶
PingAddress returns where to ping a server: its address on the server network, or, when publishedHost is set, its published game port on that host (used where the Agent cannot reach the server network, as in tests against a remote Docker engine).
func PluginFile ¶ added in v1.14.0
PluginFile is a managed plugin jar's name in PluginsDir.
func VolumeName ¶
VolumeName is the server's persistent data volume.
Types ¶
type Instance ¶
type Instance struct {
ContainerID string
Running bool
ExitCode int
OOMKilled bool
StartedAt time.Time
FinishedAt time.Time
// IP is the container's address on Network.
IP string
ConfigHash string
// ConfigHashNow is LabelHashNow; empty for containers created before
// it existed.
ConfigHashNow string
}
Instance is a server's container as Docker reports it.
type Plugin ¶ added in v1.14.0
type Plugin struct {
// Path is the verified jar in the Agent's artifact cache.
Path string
SHA256 []byte
}
Plugin is one managed plugin jar.
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime manages server containers.
func (*Runtime) Ensure ¶
Ensure makes the server's volume and container match spec, creating the container, or replacing it when its configuration changed. The volume is kept. A running server whose software or plugins changed, and nothing else, is left running: the change is pending until it next starts. It reports whether a container was created and whether a change is pending.
func (*Runtime) Logs ¶ added in v1.12.0
Logs streams a server's console output: the last tail lines, then new output until ctx ends or the server stops.
func (*Runtime) SendCommand ¶ added in v1.12.0
SendCommand types one line into a running server's console.
func (*Runtime) Setup ¶
Setup creates the server network and attaches self (the Agent's own container, when it runs in one) so the Agent can reach servers.
type Spec ¶
type Spec struct {
ServerID string
Template templates.Template
CPUMillis int64
MemoryBytes int64
Ports []Port
// JavaVersion selects the template's runtime image.
JavaVersion int
// Artifact is the path of the verified software to install, or empty.
Artifact string
ArtifactSHA256 []byte
// EULAAccepted writes eula.txt, which Minecraft servers require.
EULAAccepted bool
// Plugins are the verified plugin jars to install and load.
Plugins []Plugin
// Env is added to the template's environment (the proxy's forwarding
// secret). It is part of the configuration hash, never of a label.
Env []string
}
Spec is what the runtime needs to run one server.