Documentation
¶
Overview ¶
Package docker deploys apps to a Docker engine, local or remote over SSH.
Index ¶
- func SSHHostname(target string) string
- type ContainerInfo
- type ContainerResource
- type DBRunSpec
- type Engine
- func (e *Engine) AppContainers(app string) []string
- func (e *Engine) AppImageTags(app string) []string
- func (e *Engine) AppResourceStats() ([]ContainerResource, error)
- func (e *Engine) AppStates() (map[string]string, error)
- 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) Containers() ([]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) HostPort(name string, containerPort int) (int, error)
- func (e *Engine) ImageExists(tag string) bool
- func (e *Engine) IsRemote() bool
- func (e *Engine) Logs(container string, follow bool, tail string, 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, cmd string) (string, error)
- func (e *Engine) RunTool(network string, env map[string]string, image string, args ...string) (string, error)
- func (e *Engine) RunWorker(s WorkerSpec) error
- func (e *Engine) SkiffContainers() []ContainerInfo
- func (e *Engine) State(container string) string
- 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) WorkerContainers(app string) []string
- type Route
- type RunSpec
- type WorkerSpec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SSHHostname ¶
Types ¶
type ContainerInfo ¶
ContainerInfo is a skiff-managed container's name and creation time.
type ContainerResource ¶
type ContainerResource struct {
App string
Container string
CPUPerc float64 // percent of one core; can exceed 100 on multi-core
MemBytes int64
MemLimit int64
Restarts int
}
ContainerResource is a live CPU/memory sample for one app container, tagged with the skiff.app it belongs to.
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) — network-internal, backed by a named volume, and deliberately unlabeled with skiff=1 so the app reaper leaves it alone.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
func (*Engine) AppContainers ¶
AppContainers lists every container (running or not) for an app, so all stale versions can be retired — not just the one the registry last recorded.
func (*Engine) AppImageTags ¶
AppImageTags lists the retained tags of an app's images (skiff-<app>:*), newest first, excluding :latest and dangling <none>. Docker lists images created-descending by default, which is the order we rely on for pruning.
func (*Engine) AppResourceStats ¶
func (e *Engine) AppResourceStats() ([]ContainerResource, error)
AppResourceStats samples every running app container in a single `docker stats` read, tags each by its skiff.app label, and folds in the container restart count. Returns nil (no error) when nothing is running.
func (*Engine) AppStates ¶
AppStates maps each skiff app to its container state (running, exited, ...). Running wins when an app has more than one container (e.g. mid-rollout).
func (*Engine) BuildFromDockerfile ¶
func (*Engine) ConnectNetwork ¶
ConnectNetwork attaches a running container to an additional network. It's a no-op error (already connected) when the container is already a member.
func (*Engine) Containers ¶
func (*Engine) EnsureNetwork ¶
EnsureNetwork creates a docker network if it doesn't already exist.
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 to a file and pipe a dump back in.
func (*Engine) ImageExists ¶
ImageExists reports whether a tagged image is present locally.
func (*Engine) PullImage ¶
PullImage fetches an image ahead of time so a later run doesn't block on it.
func (*Engine) RemoveImage ¶
RemoveImage deletes a tagged image (best-effort; ignores "in use").
func (*Engine) RemoveVolume ¶
RemoveVolume deletes a named volume (used when tearing down a database).
func (*Engine) Routes ¶
Routes discovers app-to-hostport mappings from skiff.app-labeled containers.
func (*Engine) RunDatabase ¶
RunDatabase (re)creates a managed database container. It returns the published host port when Publish is set (0 otherwise). Recreating with the same name + volume preserves the data.
func (*Engine) RunOnce ¶
func (e *Engine) RunOnce(ctx context.Context, image string, env map[string]string, network, cmd string) (string, error)
RunOnce runs a throwaway container from an image with the given env on a network, executing a shell command. Returns combined output and the exit error — used for release commands (migrations) and scheduled jobs.
func (*Engine) RunTool ¶
func (e *Engine) RunTool(network string, env map[string]string, image string, args ...string) (string, error)
RunTool runs a throwaway container passing args straight to the image's entrypoint (no shell), used for CLI images like minio/mc that have no shell.
func (*Engine) RunWorker ¶
func (e *Engine) RunWorker(s WorkerSpec) error
func (*Engine) SkiffContainers ¶
func (e *Engine) SkiffContainers() []ContainerInfo
SkiffContainers lists all skiff-managed containers with their creation time, for reaping orphans (deleted apps, failed swaps) on startup.
func (*Engine) StreamLogs ¶
func (*Engine) StreamLogsSSE ¶
StreamLogsSSE follows a container's logs and writes them as SSE data frames, flushing after each line.
func (*Engine) Tag ¶
Tag adds an additional name to an existing image, so a build can be retained as a rollback point (e.g. skiff-app:latest -> skiff-app:<deployid>).
func (*Engine) WorkerContainers ¶
WorkerContainers lists an app's worker containers (running or not); all worker containers when app is "".
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)
}
type WorkerSpec ¶
type WorkerSpec struct {
Name string
App string
Image string
Command string // run via sh -c
Env map[string]string
Network string
}
WorkerSpec runs a long-lived background process from an app's image with no published port and no routing labels, so the edge router never targets it.