docker

package
v0.0.0-...-938295d Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BusyBoxImage is the image to use for BusyBox, this is used as the smallest Docker image that we can create a container from.
	// We cannot use scratch unless we build our own blank image from scratch, which adds more complexity.
	BusyBoxImage = "docker.io/library/busybox:1.33.1"
)

Variables

This section is empty.

Functions

func StrPtr

func StrPtr(str string) *string

StrPtr returns a pointer to a string.

Types

type BuildOpts

type BuildOpts struct {
	Dockerfile string
	BuildArgs  map[string]*string
	Tags       []string
}

BuildOpts abstracts the Docker API from the end-user for building Docker images.

type Client

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

Client abstracts the docker client into useful functions.

func MustClient

func MustClient() *Client

MustClient returns a new docker client, fatally logging any errors.

func (*Client) Build

func (c *Client) Build(opts *BuildOpts) error

Build builds a docker image with the given options.

func (*Client) EnsureImage

func (c *Client) EnsureImage(image string) error

EnsureImage ensures that the given image exists locally in Docker and can be used for creating containers by checking if the given image exists, pulling it if not.

func (*Client) GetFileFromVolume

func (c *Client) GetFileFromVolume(volume operatingsystem.Volume, volumeMnt string, path string) (io.Reader, error)

GetFileFromVolume returns a reader for the contents of a file in the given volume and path. TODO: split into smaller functions

func (*Client) MustCreateVolume

func (c *Client) MustCreateVolume() operatingsystem.Volume

MustCreateVolume creates a new docker volume and returns its name, fatally logging any errors.

func (*Client) MustRemoveVolumes

func (c *Client) MustRemoveVolumes(volumeNames ...operatingsystem.Volume)

MustRemoveVolumes removes the given volumes, fatally logging any errors.

func (*Client) Run

func (c *Client) Run(opts *RunOpts) (containerOut string, err error)

Run runs the given docker image, returning its output as a string. TODO: break down into smaller functions

func (*Client) WriteFileToVolume

func (c *Client) WriteFileToVolume(volume operatingsystem.Volume, volumeMnt string, path string, contents string) error

WriteFileToVolume writes the given contents to the given path with the given volume and its mount point. TODO: split into smaller functions

type RunOpts

type RunOpts struct {
	Image      string
	Entrypoint []string
	Cmd        []string
	// Volumes are volumes to mount to the container in the format <volume name>:<mount path>.
	Volumes    map[operatingsystem.Volume]string
	WorkingDir string
	Env        map[string]string
}

RunOpts abstracts the Docker API away from the end-user.

Jump to

Keyboard shortcuts

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