docker

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2026 License: Apache-2.0, MIT Imports: 12 Imported by: 0

Documentation

Overview

Package docker deploys apps to a Docker engine, local or remote over SSH.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SSHHostname

func SSHHostname(target string) string

Types

type ContainerInfo

type ContainerInfo struct {
	Name    string
	Created time.Time
}

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 For

func For(host string) *Engine

func Local

func Local() *Engine

func Remote

func Remote(sshTarget string) *Engine

func (*Engine) AppContainers

func (e *Engine) AppContainers(app string) []string

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

func (e *Engine) AppImageTags(app string) []string

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

func (e *Engine) AppStates() (map[string]string, error)

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) Available

func (e *Engine) Available() error

func (*Engine) BuildFromDockerfile

func (e *Engine) BuildFromDockerfile(ctx context.Context, tag, dockerfile, contextDir string, out io.Writer) error

func (*Engine) ConnectNetwork

func (e *Engine) ConnectNetwork(network, container string) error

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 (e *Engine) Containers() ([]string, error)

func (*Engine) EnsureNetwork

func (e *Engine) EnsureNetwork(name string) error

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) HostPort

func (e *Engine) HostPort(name string, containerPort int) (int, error)

func (*Engine) ImageExists

func (e *Engine) ImageExists(tag string) bool

ImageExists reports whether a tagged image is present locally.

func (*Engine) IsRemote

func (e *Engine) IsRemote() bool

func (*Engine) Logs

func (e *Engine) Logs(container string, follow bool, tail string, out io.Writer) error

func (*Engine) PullImage

func (e *Engine) PullImage(image string) error

PullImage fetches an image ahead of time so a later run doesn't block on it.

func (*Engine) Remove

func (e *Engine) Remove(name string) error

func (*Engine) RemoveImage

func (e *Engine) RemoveImage(tag string) error

RemoveImage deletes a tagged image (best-effort; ignores "in use").

func (*Engine) RemoveVolume

func (e *Engine) RemoveVolume(name string) error

RemoveVolume deletes a named volume (used when tearing down a database).

func (*Engine) Routes

func (e *Engine) Routes() ([]Route, error)

Routes discovers app-to-hostport mappings from skiff.app-labeled containers.

func (*Engine) Run

func (e *Engine) Run(s RunSpec) (int, error)

func (*Engine) RunDatabase

func (e *Engine) RunDatabase(s DBRunSpec) (int, error)

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) State

func (e *Engine) State(container string) string

func (*Engine) Stop

func (e *Engine) Stop(container string) error

func (*Engine) StreamLogs

func (e *Engine) StreamLogs(ctx context.Context, container string, out io.Writer) error

func (*Engine) StreamLogsSSE

func (e *Engine) StreamLogsSSE(ctx context.Context, container string, w io.Writer, flush func())

StreamLogsSSE follows a container's logs and writes them as SSE data frames, flushing after each line.

func (*Engine) Tag

func (e *Engine) Tag(src, dst string) error

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

func (e *Engine) WorkerContainers(app string) []string

WorkerContainers lists an app's worker containers (running or not); all worker containers when app is "".

type Route

type Route struct {
	App      string
	HostPort int
}

Route is a discovered app-to-hostport mapping (from container labels).

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL