docker

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2021 License: NCSA Imports: 59 Imported by: 0

README

# docker Build Status

Docker uses c3sr/config for configuration. The docker section of the configuration file should be written according to config.go.

Config

docker:
  - time_limit: 1h
  - image: ubuntu
  - memory_limit: 4gb
  - endpoints:
    - /run/docker.sock
    - /var/run/docker.sock
  - env:
    CI: rai
    RAI: true
    RAI_ARCH: linux/amd64
    RAI_USER: root
    RAI_SOURCE_DIR: /src
    RAI_DATA_DIR: /data
    RAI_BUILD_DIR: /build
    SOURCE_DIR: /src 
    DATA_DIR: /data 
    BUILD_DIR: /build 
    PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    TERM: xterm

Documentation

Index

Constants

View Source
const (
	// DefaultDockerfileName is the Default filename with Docker commands, read by docker build
	DefaultDockerfileName string = "Dockerfile"

	// HeaderSize is the size in bytes of a tar header
	HeaderSize = 512
)

Variables

View Source
var (
	Config = &dockerConfig{
		done: make(chan struct{}),
	}
)
View Source
var (
	DefaultContainerEnv = map[string]string{
		"CI":              "rai",
		"RAI":             "true",
		"RAI_ARCH":        filepath.Join(runtime.GOOS, runtime.GOARCH),
		"RAI_USER":        "root",
		"RAI_SOURCE_DIR":  "/src",
		"RAI_DATA_DIR":    "/data",
		"RAI_BUILD_DIR":   "/build",
		"DATA_DIR":        "/dir",
		"SOURCE_DIR":      "/src",
		"BUILD_DIR":       "/build",
		"TERM":            "xterm",
		"PATH":            "/usr/local/cuda/bin:/usr/local/nvidia/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
		"LD_LIBRARY_PATH": "/usr/local/cuda/lib64:/usr/local/nvidia/lib64",
		"SHELL":           "/bin/bash",
		"SHELLOPTS":       "braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor",
	}
)

Functions

func IsArchive

func IsArchive(header []byte) bool

IsArchive checks for the magic bytes of a tar or any supported compression algorithm.

func PeriodicCleanupDeadContainers

func PeriodicCleanupDeadContainers()

cleanup dead containers and volumes frequently

Types

type BuildOption

type BuildOption func(*BuildOptions)

func BuildArchiveReader

func BuildArchiveReader(reader io.Reader) BuildOption

func BuildArguments

func BuildArguments(args map[string]string) BuildOption

func BuildCache

func BuildCache(cache bool) BuildOption

func BuildContext

func BuildContext(ctx context.Context) BuildOption

func BuildDockerFilePath

func BuildDockerFilePath(path string) BuildOption

func BuildId

func BuildId(id string) BuildOption

func BuildLabels

func BuildLabels(labels map[string]string) BuildOption

func BuildQuiet

func BuildQuiet(quiet bool) BuildOption

func BuildTags

func BuildTags(tags []string) BuildOption

type BuildOptions

type BuildOptions struct {
	// contains filtered or unexported fields
}

func NewBuildOptions

func NewBuildOptions(opts ...BuildOption) *BuildOptions

type Client

type Client struct {
	*dc.Client
	// contains filtered or unexported fields
}

func NewClient

func NewClient(paramOpts ...ClientOption) (*Client, error)

func (*Client) Close

func (c *Client) Close() error

func (*Client) HasImage

func (c *Client) HasImage(refName string) bool

func (*Client) ImageBuild

func (c *Client) ImageBuild(iopts ...BuildOption) error

func (*Client) ImageBuildCached

func (c *Client) ImageBuildCached(iopts ...BuildOption) error

func (*Client) ImagePush

func (c *Client) ImagePush(name0 string, pushOpts model.Push) error

func (*Client) ListImages

func (c *Client) ListImages(refName string) ([]types.ImageSummary, error)

func (*Client) PullImage

func (c *Client) PullImage(refName string) error

func (*Client) RemoveImage

func (c *Client) RemoveImage(refName string) error

type ClientOption

type ClientOption func(*ClientOptions)

func APIVersion

func APIVersion(s string) ClientOption

func ClientContext

func ClientContext(ctx context.Context) ClientOption

func Host

func Host(s string) ClientOption

func Stderr

func Stderr(stderr io.Writer) ClientOption

func Stdin

func Stdin(stdin io.Reader) ClientOption

func Stdout

func Stdout(stdout io.Writer) ClientOption

func TLSConfig

func TLSConfig(certPath string, verify bool) ClientOption

type ClientOptions

type ClientOptions struct {
	// contains filtered or unexported fields
}

func NewClientOptions

func NewClientOptions(opts ...ClientOption) *ClientOptions

type Container

type Container struct {
	ID string
	// contains filtered or unexported fields
}

func NewContainer

func NewContainer(client *Client, paramOpts ...ContainerOption) (*Container, error)

func (*Container) Attach

func (c *Container) Attach() error

func (*Container) Close

func (c *Container) Close() error

func (*Container) CopyFromContainer

func (c *Container) CopyFromContainer(sourcePath string) (io.ReadCloser, error)

func (*Container) CopyToContainer

func (c *Container) CopyToContainer(targetPath string, content io.Reader) error

func (*Container) ForwardAllSignals

func (c *Container) ForwardAllSignals() chan os.Signal

func (*Container) Info

func (c *Container) Info() (types.ContainerJSON, error)

func (*Container) MonitorTtySize

func (c *Container) MonitorTtySize() error

func (*Container) Options

func (c *Container) Options() ContainerOptions

func (*Container) Start

func (c *Container) Start() error

func (*Container) Stop

func (c *Container) Stop() error

type ContainerOption

type ContainerOption func(*ContainerOptions)

func AddEnv

func AddEnv(k, v string) ContainerOption

func AddVolume

func AddVolume(dir string) ContainerOption

func CUDADevice

func CUDADevice(n int) ContainerOption

func Cmd

func Cmd(s []string) ContainerOption

func ContainerConfig

func ContainerConfig(h container.Config) ContainerOption

func Entrypoint

func Entrypoint(s []string) ContainerOption

func GPUCount

func GPUCount(cnt int) ContainerOption

func Hostname

func Hostname(h string) ContainerOption

func Image

func Image(s string) ContainerOption

func Memory

func Memory(n int64) ContainerOption

func NetworkDisabled

func NetworkDisabled(b bool) ContainerOption

func NvidiaVolume

func NvidiaVolume(version string) ContainerOption

func OpenStdin

func OpenStdin(b bool) ContainerOption

func ReadonlyRootfs

func ReadonlyRootfs(b bool) ContainerOption

func Runtime

func Runtime(s string) ContainerOption

func Shell

func Shell(s []string) ContainerOption

func Timelimit

func Timelimit(t time.Duration) ContainerOption

func Tty

func Tty(b bool) ContainerOption

func User

func User(u string) ContainerOption

func WorkingDirectory

func WorkingDirectory(dir string) ContainerOption

type ContainerOptions

type ContainerOptions struct {
	// contains filtered or unexported fields
}

func NewContainerOptions

func NewContainerOptions(c *Client, opts ...ContainerOption) *ContainerOptions

type Execution

type Execution struct {

	// Path is the path or name of the command in the container.
	Path string

	// Arguments to the command in the container, excluding the command
	// name as the first argument.
	Args []string

	// Env is environment variables to the command. If Env is nil, Run will use
	// Env specified on Method or pre-built container image.
	Env []string

	// Dir specifies the working directory of the command. If Dir is the empty
	// string, Run uses Dir specified on Method or pre-built container image.
	Dir string

	// Stdin specifies the process's standard input.
	// If Stdin is nil, the process reads from the null device (os.DevNull).
	//
	// Run will not close the underlying handle if the Reader is an *os.File
	// differently than os/exec.
	Stdin io.ReadCloser

	// Stdout and Stderr specify the process's standard output and error.
	// If either is nil, they will be redirected to the null device (os.DevNull).
	//
	// Run will not close the underlying handles if they are *os.File differently
	// than os/exec.
	Stdout io.Writer
	Stderr io.Writer
	// contains filtered or unexported fields
}

func NewExecution

func NewExecution(container *Container, args ...string) (*Execution, error)

func NewExecutionFromString

func NewExecutionFromString(container *Container, shell string) (*Execution, error)

func (*Execution) CombinedOutput

func (e *Execution) CombinedOutput() ([]byte, error)

func (*Execution) MonitorTtySize

func (e *Execution) MonitorTtySize() error

func (*Execution) Output

func (e *Execution) Output() ([]byte, error)

func (*Execution) Run

func (e *Execution) Run() error

func (*Execution) Start

func (e *Execution) Start() error

func (*Execution) StderrPipe

func (e *Execution) StderrPipe() (io.ReadCloser, error)

func (*Execution) StdinPipe

func (e *Execution) StdinPipe() (io.WriteCloser, error)

func (*Execution) StdoutPipe

func (e *Execution) StdoutPipe() (io.ReadCloser, error)

func (*Execution) Wait

func (e *Execution) Wait() error

type ExitError

type ExitError struct {
	// ExitCode holds the non-zero exit code of the container
	ExitCode int

	// Stderr holds the standard error output from the command
	// if it *Cmd executed through Output() and Cmd.Stderr was not
	// set.
	Stderr []byte
}

ExitError reports an unsuccessful exit by a command.

func (*ExitError) Error

func (e *ExitError) Error() string

type GPUUsageState

type GPUUsageState struct {
	*lru.Cache
}
var GPUDeviceUsageState *GPUUsageState

func NewGPUUsageState

func NewGPUUsageState() (*GPUUsageState, error)

type InStream

type InStream struct {
	// contains filtered or unexported fields
}

InStream is an input stream used by the DockerCli to read user input

func NewInStream

func NewInStream(in io.ReadCloser) *InStream

NewInStream returns a new InStream object from a ReadCloser

func (*InStream) CheckTty

func (i *InStream) CheckTty(attachStdin, ttyMode bool) error

CheckTty checks if we are trying to attach to a container tty from a non-tty client input stream, and if so, returns an error.

func (*InStream) Close

func (i *InStream) Close() error

Close implements the Closer interface

func (*InStream) FD

func (i *InStream) FD() uintptr

FD returns the file descriptor number for this stream

func (*InStream) IsTerminal

func (i *InStream) IsTerminal() bool

IsTerminal returns true if this stream is connected to a terminal

func (*InStream) Read

func (i *InStream) Read(p []byte) (int, error)

func (*InStream) RestoreTerminal

func (i *InStream) RestoreTerminal()

RestoreTerminal restores normal mode to the terminal

func (*InStream) SetRawTerminal

func (i *InStream) SetRawTerminal() (err error)

SetRawTerminal sets raw mode on the input terminal

type OutStream

type OutStream struct {
	// contains filtered or unexported fields
}

OutStream is an output stream used by the DockerCli to write normal program output.

func NewOutStream

func NewOutStream(out io.Writer) *OutStream

NewOutStream returns a new OutStream object from a Writer

func (*OutStream) FD

func (o *OutStream) FD() uintptr

FD returns the file descriptor number for this stream

func (*OutStream) GetTtySize

func (o *OutStream) GetTtySize() (uint, uint)

GetTtySize returns the height and width in characters of the tty

func (*OutStream) IsTerminal

func (o *OutStream) IsTerminal() bool

IsTerminal returns true if this stream is connected to a terminal

func (*OutStream) RestoreTerminal

func (o *OutStream) RestoreTerminal()

RestoreTerminal restores normal mode to the terminal

func (*OutStream) SetRawTerminal

func (o *OutStream) SetRawTerminal() (err error)

SetRawTerminal sets raw mode on the output terminal

func (*OutStream) Write

func (o *OutStream) Write(p []byte) (int, error)

type Streams

type Streams interface {
	In() *InStream
	Out() *OutStream
	Err() io.Writer
}

Streams is an interface which exposes the standard input and output streams

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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