 Documentation
      ¶
      Documentation
      ¶
    
    
  
    
  
    Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var (
	ForceRebuild = false
)
    Functions ¶
Types ¶
type Client ¶
Client wraps the methods of the docker Client.
func New ¶
New creates a new dockerClient with default Options.
Example ¶
package main
import (
	"fmt"
	containers "github.com/taubyte/go-simple-container"
)
var client *containers.Client
var err error
func main() {
	// create new docker client
	client, err = containers.New()
	if err != nil {
		return
	}
	fmt.Println("success")
}
Output: success
func (*Client) Image ¶
func (c *Client) Image(ctx context.Context, image string, options ...ImageOption) (_image *Image, err error)
Image initializes the given image, and attempts to pull the container from docker hub. If the Build() Option is provided then the given DockerFile tarball is built and returned.
Example ¶
package main
import (
	"bytes"
	"context"
	"fmt"
	containers "github.com/taubyte/go-simple-container"
)
var image *containers.Image
func main() {
	// create new docker client
	client, err := containers.New()
	if err != nil {
		return
	}
	// declare new docker image `node` from docker hub public image `node`
	image, err = client.Image(context.Background(), "node")
	if err != nil {
		return
	}
	dockerFileTarBall := bytes.NewBuffer(nil)
	// Build a custom image using a Dockerfile tarball.
	// This will error because we are sending nil bytes. Refer to README for how to build this tarball.
	image, err = client.Image(context.Background(), "custom/test:version1", containers.Build(dockerFileTarBall))
	if err == nil {
		return
	}
	fmt.Println("success")
}
Output: success
type Container ¶
type Container struct {
	// contains filtered or unexported fields
}
    Container wraps the methods of the docker container.
func (*Container) Run ¶
func (c *Container) Run(ctx context.Context) (*MuxedReadCloser, error)
Run starts the container and waits for the container to exit before returning the container logs.
Example ¶
package main
import (
	"bytes"
	"context"
	"fmt"
	containers "github.com/taubyte/go-simple-container"
)
func main() {
	// create new docker client
	client, err := containers.New()
	if err != nil {
		return
	}
	ctx := context.Background()
	// declare new docker image `node` from docker hub public image `node`
	image, err := client.Image(ctx, "node")
	if err != nil {
		return
	}
	// declare container options to set environment variable, and command to be run by container
	options := []containers.ContainerOption{
		containers.Variable("KEY", "value"),
		containers.Command([]string{"echo", "Hello World"}),
	}
	// create container from the image
	container, err := image.Instantiate(ctx, options...)
	if err != nil {
		return
	}
	// runs the container
	logs, err := container.Run(ctx)
	if err != nil {
		return
	}
	var buf bytes.Buffer
	// read logs from the ran container
	buf.ReadFrom(logs.Combined())
	fmt.Println(buf.String())
}
Output: Hello World
type ContainerOption ¶
ContainerOption is a function to set configuration to the Container object.
func Command ¶
func Command(cmd []string) ContainerOption
Command sets the commands to be run by the container after being built.
func Shell ¶
func Shell(cmd []string) ContainerOption
Shell sets the shell-form of RUN, CMD, ENTRYPOINT
func Variable ¶
func Variable(key, value string) ContainerOption
Variable sets an environment variable in the container.
func Variables ¶
func Variables(vars map[string]string) ContainerOption
Variables sets multiple environment variables in the container.
func Volume ¶
func Volume(sourcePath, containerPath string) ContainerOption
Volume sets local directories to be volumed in the container.
func WorkDir ¶
func WorkDir(workDir string) ContainerOption
WorkDir sets the working directory of the container, where calls will be made.
type Image ¶
type Image struct {
	// contains filtered or unexported fields
}
    Image wraps the methods of the docker image.
func (*Image) Instantiate ¶
Instantiate sets given options and creates the container from the docker image.
Example ¶
package main
import (
	"context"
	"fmt"
	containers "github.com/taubyte/go-simple-container"
)
var container *containers.Container
func main() {
	// create new docker client
	client, err := containers.New()
	if err != nil {
		return
	}
	ctx := context.Background()
	// declare new docker image `node` from docker hub public image `node`
	image, err := client.Image(ctx, "node")
	if err != nil {
		return
	}
	// declare container options to set environment variable, and command to be run by container
	options := []containers.ContainerOption{
		containers.Variable("KEY", "value"),
		containers.Command([]string{"echo", "Hello World"}),
	}
	// create container from the image
	container, err = image.Instantiate(ctx, options...)
	if err != nil {
		return
	}
	fmt.Println("success")
}
Output: success
type ImageOption ¶
ImageOption is a function to set configuration to the Image object.
func Build ¶
func Build(tarball io.Reader) ImageOption
Build returns an ImageOption to build a tarball of a Dockerfile
type MuxedReadCloser ¶
type MuxedReadCloser struct {
	// contains filtered or unexported fields
}
    MuxedReadCloser wraps the Read/Close methods for muxed logs.
func (*MuxedReadCloser) Close ¶
func (mx *MuxedReadCloser) Close() error
func (*MuxedReadCloser) Combined ¶
func (mx *MuxedReadCloser) Combined() io.ReadCloser
Combined returns the Stderr, and Stdout combined container logs.
func (*MuxedReadCloser) Separated ¶
func (mx *MuxedReadCloser) Separated() (stdOut io.ReadCloser, stdErr io.ReadCloser)
Separated returns both the standard Out and Error logs of the container.
func (*MuxedReadCloser) Stderr ¶
func (mx *MuxedReadCloser) Stderr() io.ReadCloser
Stderr returns the standard error of the container logs
func (*MuxedReadCloser) Stdout ¶
func (mx *MuxedReadCloser) Stdout() io.ReadCloser
Stdout returns the standard output of the container logs