This repository has been archived by the owner on Oct 2, 2022. It is now read-only.
generated from ContainerSSH/library-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker.go
73 lines (61 loc) · 2.91 KB
/
docker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package docker
import (
"context"
"io"
"github.com/containerssh/log"
)
// dockerClientFactory creates a dockerClient based on a configuration
type dockerClientFactory interface {
// get takes a configuration and returns a docker client if the configuration was populated.
// Returns an error if the configuration is invalid. Returns errDockerClientNotConfigured if the specific client is
// not configured
get(ctx context.Context, config Config, logger log.Logger) (dockerClient, error)
}
// dockerClient is a simplified representation of a docker client.
type dockerClient interface {
// getImageName returns the configured image name
getImageName() string
// hasImage checks if the the configured image exists on the Docker daemon. Returns true if yes, false if no, and an
// error if an error happened while querying the Docker daemon.
hasImage(ctx context.Context) (bool, error)
// pullImage pulls the configured image within the specified ctx and returns an error if the pull failed.
pullImage(ctx context.Context) error
// createContainer creates and starts the configured container. May return a container even if an error happened.
// This container will need to be removed. Passing tty also means that the main console will be prepared for
// attaching.
createContainer(
ctx context.Context,
labels map[string]string,
env map[string]string,
tty *bool,
cmd []string,
) (dockerContainer, error)
}
// dockerContainer is the representation of a created container.
type dockerContainer interface {
// attach attaches to the container on the main console.
attach(ctx context.Context) (dockerExecution, error)
// start starts the container within the given context.
start(ctx context.Context) error
// createExec creates an execution process for the given program with the given parameters. The passed context is
// the start context.
createExec(ctx context.Context, program []string, env map[string]string, tty bool) (dockerExecution, error)
// remove removes the container within the given context.
remove(ctx context.Context) error
}
// dockerExecution is an execution process on either an "exec" process or attached to the main console of a container.
type dockerExecution interface {
// resize resizes the current terminal to the given dimensions.
resize(ctx context.Context, height uint, width uint) error
// signal sends the given signal to the currently running process. Returns an error if the process is not running,
// the signal is not known or permitted, or the process ID is not known.
signal(ctx context.Context, sig string) error
// run runs the process in question.
run(stdin io.Reader, stdout io.Writer, stderr io.Writer, writeClose func() error, onExit func(exitStatus int),)
// done returns a channel that is closed when the program exits.
done() <-chan struct{}
// term sends a TERM signal to the running process.
term(ctx context.Context)
// kill terminates the process immediately.
kill()
}