Documentation
¶
Overview ¶
Package docker deploys apps to a Docker engine, local or remote over SSH.
Index ¶
- Constants
- func SSHHostname(target string) string
- type AppImage
- type ContainerInfo
- type ContainerMeta
- type ContainerResource
- type ContainerRuntime
- type DBRunSpec
- type Engine
- func (e *Engine) AppContainerKeys() (map[string]string, error)
- func (e *Engine) AppContainers(app string) []string
- func (e *Engine) AppImageTags(app string) []string
- func (e *Engine) AppImages() ([]AppImage, error)
- func (e *Engine) AppResourceStats() ([]ContainerResource, error)
- func (e *Engine) AppStates() (map[string]string, error)
- func (e *Engine) AppVolumes(app string) []string
- func (e *Engine) Available() error
- func (e *Engine) BuildFromDockerfile(ctx context.Context, tag, dockerfile, contextDir string, out io.Writer) error
- func (e *Engine) ConnectNetwork(network, container string) error
- func (e *Engine) ContainerImages() (map[string]bool, error)
- func (e *Engine) ContainerMeta(name string) (ContainerMeta, error)
- func (e *Engine) Containers() ([]string, error)
- func (e *Engine) DialContainer(ctx context.Context, container, host, port string) (net.Conn, error)
- func (e *Engine) EnsureAppVolume(volume, app, name string) error
- func (e *Engine) EnsureNetwork(name string) error
- func (e *Engine) Exec(ctx context.Context, container string, cmd []string, stdin io.Reader, ...) error
- func (e *Engine) FollowLogs(ctx context.Context, container string, since time.Time, ...) error
- func (e *Engine) HostPort(name string, containerPort int) (int, error)
- func (e *Engine) ImageDigest(image string) string
- func (e *Engine) ImageExists(tag string) bool
- func (e *Engine) ImagePort(image string) int
- func (e *Engine) IsRemote() bool
- func (e *Engine) Logs(container string, follow bool, tail string, out io.Writer) error
- func (e *Engine) PruneBuildCache(olderThan time.Duration) error
- func (e *Engine) PruneDanglingImages() error
- func (e *Engine) Pull(ctx context.Context, image string, auth *RegistryAuth, out io.Writer) error
- func (e *Engine) PullImage(image string) error
- func (e *Engine) Remove(name string) error
- func (e *Engine) RemoveImage(tag string) error
- func (e *Engine) RemoveVolume(name string) error
- func (e *Engine) Routes() ([]Route, error)
- func (e *Engine) Run(s RunSpec) (int, error)
- func (e *Engine) RunDatabase(s DBRunSpec) (int, error)
- func (e *Engine) RunOnce(ctx context.Context, image string, env map[string]string, network string, ...) (string, error)
- func (e *Engine) RunWorker(s WorkerSpec) error
- func (e *Engine) RunningContainers() ([]string, error)
- func (e *Engine) Runtime(name string) (ContainerRuntime, error)
- func (e *Engine) SkiffContainers() []ContainerInfo
- func (e *Engine) Start(container string) error
- func (e *Engine) State(container string) string
- func (e *Engine) StatsFor(appOf map[string]string) ([]ContainerResource, error)
- func (e *Engine) Stop(container string) error
- func (e *Engine) StreamLogs(ctx context.Context, container string, out io.Writer) error
- func (e *Engine) StreamLogsSSE(ctx context.Context, container string, w io.Writer, flush func())
- func (e *Engine) Tag(src, dst string) error
- func (e *Engine) VolumeExists(name string) bool
- func (e *Engine) VolumeSizes() map[string]int64
- func (e *Engine) WatchOOM(ctx context.Context, fn func(app, container string)) error
- func (e *Engine) WorkerContainerKeys() (map[string]string, error)
- func (e *Engine) WorkerContainers(app string) []string
- type Mount
- type RegistryAuth
- type Route
- type RunSpec
- type WorkerSpec
Constants ¶
const SafetyCapPercent = 75
SafetyCapPercent is how much of the server's memory an app with no limit of its own may use: enough for nearly anything, while leaving room for the other apps and for Skiff to keep running if one runs away.
Variables ¶
This section is empty.
Functions ¶
func SSHHostname ¶
Types ¶
type ContainerInfo ¶
type ContainerMeta ¶ added in v0.2.0
type ContainerResource ¶
type ContainerRuntime ¶ added in v0.2.0
type DBRunSpec ¶
type DBRunSpec struct {
Name string
Image string
Network string
Volume string // named volume for persistence
MountAt string // where the volume mounts inside the container
Env map[string]string
Cmd []string // optional command/args after the image
Labels map[string]string // ownership + kind labels
Port int // container port (published on the host when Publish is set)
Publish bool // expose Port on 0.0.0.0 for external access
Entrypoint string // optional --entrypoint override (e.g. "sh" to fix TLS cert perms)
Binds []string // extra bind mounts, "host:container[:ro]" (e.g. the TLS cert dir)
}
DBRunSpec runs a managed resource (a database), deliberately unlabeled with skiff=1 so the app reaper leaves it alone.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
func (*Engine) AppContainerKeys ¶ added in v0.2.0
AppContainerKeys maps each running app container to its app.
func (*Engine) AppContainers ¶
AppContainers lists every container (running or not) for an app, so all stale versions get retired, not just the registry's last-recorded one.
func (*Engine) AppImageTags ¶
AppImageTags lists an app's retained image tags (excluding :latest and <none>), relying on docker's default created-descending order — newest first — for pruning.
func (*Engine) AppImages ¶ added in v0.2.0
AppImages lists every skiff-<app> image tag on the engine.
func (*Engine) AppResourceStats ¶
func (e *Engine) AppResourceStats() ([]ContainerResource, error)
func (*Engine) AppStates ¶
AppStates maps each skiff app to its container state; running wins when an app has more than one container (e.g. mid-rollout).
func (*Engine) AppVolumes ¶ added in v0.5.0
AppVolumes names every volume created for an app.
func (*Engine) BuildFromDockerfile ¶
func (*Engine) ConnectNetwork ¶
ConnectNetwork attaches a container to an additional network; an already-connected container returns a benign error.
func (*Engine) ContainerImages ¶ added in v0.2.0
ContainerImages returns the image of every container, running or not.
func (*Engine) ContainerMeta ¶ added in v0.2.0
func (e *Engine) ContainerMeta(name string) (ContainerMeta, error)
func (*Engine) Containers ¶
func (*Engine) DialContainer ¶ added in v0.5.0
DialContainer opens a connection to an address as seen from inside a container, through `docker exec` and the nc in its image. It reaches services that publish no port, and works where the host can't route to container IPs.
func (*Engine) EnsureAppVolume ¶ added in v0.5.0
EnsureAppVolume creates an app's named volume, labelled with its owner so it can be listed and removed with the app; an existing volume is left as is.
func (*Engine) EnsureNetwork ¶
func (*Engine) Exec ¶
func (e *Engine) Exec(ctx context.Context, container string, cmd []string, stdin io.Reader, stdout io.Writer) error
Exec runs a command inside a container, wiring stdin/stdout to the given streams — used to dump a database and pipe a dump back in.
func (*Engine) FollowLogs ¶ added in v0.3.0
func (e *Engine) FollowLogs(ctx context.Context, container string, since time.Time, line func(ts time.Time, stream, text string)) error
FollowLogs streams a container's output from since onward, calling line for each one with docker's timestamp; it returns when the container stops or ctx ends.
func (*Engine) ImageDigest ¶ added in v0.5.0
ImageDigest is the registry digest a pulled image came from, if it has one.
func (*Engine) ImageExists ¶
func (*Engine) ImagePort ¶ added in v0.5.0
ImagePort is the lowest TCP port the image declares with EXPOSE, or 0 when it declares none.
func (*Engine) PruneBuildCache ¶ added in v0.2.0
func (*Engine) PruneDanglingImages ¶ added in v0.2.0
func (*Engine) Pull ¶ added in v0.5.0
Pull fetches an image, streaming docker's progress to out. With auth, the pull uses a throwaway docker config so the credentials are never written to the user's own.
func (*Engine) RemoveImage ¶
func (*Engine) RemoveVolume ¶
func (*Engine) RunDatabase ¶
RunDatabase (re)creates a managed database container, returning the published host port when Publish is set (0 otherwise); reusing the same name + volume preserves the data.
func (*Engine) RunOnce ¶
func (e *Engine) RunOnce(ctx context.Context, image string, env map[string]string, network string, volumes []Mount, cmd string) (string, error)
RunOnce runs a throwaway container executing a shell command (sh -c), for release commands (migrations) and scheduled jobs.
func (*Engine) RunWorker ¶
func (e *Engine) RunWorker(s WorkerSpec) error
func (*Engine) RunningContainers ¶ added in v0.2.0
RunningContainers names every running container.
func (*Engine) Runtime ¶ added in v0.2.0
func (e *Engine) Runtime(name string) (ContainerRuntime, error)
Runtime reads how a container was started: image, environment, command, networks and volumes.
func (*Engine) SkiffContainers ¶
func (e *Engine) SkiffContainers() []ContainerInfo
func (*Engine) StatsFor ¶ added in v0.2.0
func (e *Engine) StatsFor(appOf map[string]string) ([]ContainerResource, error)
StatsFor samples the named containers once, reporting each under the key it maps to.
func (*Engine) StreamLogs ¶
func (*Engine) StreamLogsSSE ¶
func (*Engine) VolumeExists ¶ added in v0.3.0
func (*Engine) VolumeSizes ¶ added in v0.5.0
VolumeSizes reports how much each volume holds; docker walks every volume to answer, so callers should cache it.
func (*Engine) WatchOOM ¶ added in v0.5.1
WatchOOM calls fn with the app whenever one of its containers is killed for exceeding its memory limit, until ctx ends. It reports an error when events can't be read, and needs the local Docker socket.
func (*Engine) WorkerContainerKeys ¶ added in v0.3.0
WorkerContainerKeys maps each running worker container to its app.
func (*Engine) WorkerContainers ¶
WorkerContainers lists an app's worker containers (running or not); all of them when app is "".
type RegistryAuth ¶ added in v0.5.0
RegistryAuth signs in to the image's registry for a single pull.
type RunSpec ¶
type RunSpec struct {
Name string
App string // app name, for the skiff.app route label
Image string
ContainerPort int
Memory string // optional, e.g. "512m"
CPU string // optional, e.g. "0.5"
Env map[string]string
Public bool // publish on all interfaces instead of 127.0.0.1
Network string // optional docker network to join (for reaching managed resources by name)
Labels map[string]string
Volumes []Mount
}
type WorkerSpec ¶
type WorkerSpec struct {
Name string
App string
Image string
Command string // run via sh -c
Env map[string]string
Network string
Volumes []Mount
Memory string
CPU string
}
WorkerSpec runs a long-lived background process with no published port or routing labels, so the edge router never targets it.