d2sdk

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2021 License: Apache-2.0 Imports: 13 Imported by: 1

README

Divan Docker SDK

Go SDK providing a Docker manager for Divan Docker. Intended for tests and deploy scripts.

go get github.com/a-novel/divan-docker-sdk

Divan Manager

package myPackage

import "github.com/a-novel/divan-docker-sdk"

func main() {
	manager, err := d2sdk.New("/path/to/config.json", nil)
	// Handle error here.
	
	// Run container.
	_ = manager.Start()
}

Manager options

Divan manager can be created with the New function. This function takes a path to a Divan Config file, and an optional *d2sdk.ConfigOptions struct. Available options are:

Key Type Description
Version string Specify a version of Divan Docker to run
ContainerName string Custom name for your container
VolumeName string Name of an existing volume to keep Couchbase data
Env []string A list of Env variables to pass to the container. See a list of supported ENV variables in this section

The New function may return any of the following errors:

  • d2sdk.ErrMissingConfigPath
  • d2sdk.ErrCannotRunDocker

Starting and killing your container

Once you created your manager, you can run your container by using:

manager.Start()

It may return any of the following errors:

  • d2sdk.ErrContainerAlreadyRunning
  • d2sdk.ErrCannotPullImage
  • d2sdk.ErrCannotCreatePortMap
  • d2sdk.ErrCannotCreateContainer
  • d2sdk.ErrCannotRunContainer

You can wait for your configuration to complete with the following method:

manager.WaitForReady(60)

The parameter is a timeout value in seconds.

It may return any of the following errors:

  • d2sdk.ErrExecutionError
  • d2sdk.ErrUnknownExecutionError

You can then delete your container by running:

manager.Clean()

It may return any of the following errors:

  • d2sdk.ErrNoContainerRunning
  • d2sdk.ErrCannotKillContainer
  • d2sdk.ErrCannotRemoveContainer

Updating your container

Once running, update your configuration file and run:

manager.Update()

Then if needed, run again the WaitForReady command.

It may return any of the following errors:

  • d2sdk.ErrNoContainerRunning
  • d2sdk.ErrCannotCreateCommand
  • d2sdk.ErrCannotRunCommand

Supported Env variables

$NAME=$VALUE

Name Values
ENV Any value, production and staging will be recognized, otherwise ignored

License

2021, A-Novel Apache 2.0 License.

Documentation

Index

Constants

View Source
const (
	ErrMissingConfigPath            = "err_missing_config_path"
	ErrCannotRunDocker              = "err_cannot_run_docker"
	ErrCannotPullImage              = "err_cannot_pull_image"
	ErrCannotRunContainer           = "err_cannot_run_container"
	ErrCannotCreateContainer        = "err_cannot_create_container"
	ErrNoContainerRunning           = "err_no_container_running"
	ErrCannotFetchLogs              = "err_cannot_fetch_logs"
	ErrCannotReadLogs               = "err_cannot_read_logs"
	ErrCannotKillContainer          = "err_cannot_kill_container"
	ErrCannotRemoveContainer        = "err_cannot_remove_container"
	ErrCannotCreateCommand          = "err_cannot_create_command"
	ErrCannotRunCommand             = "err_cannot_run_command"
	ErrCannotReadConfigurationError = "err_cannot_read_configuration_error"
	ErrExecutionError               = "err_execution_error"
	ErrCannotReachContainer         = "err_cannot_reach_container"
)
View Source
const (
	StatusContainerProcessing         = "status_container_processing"
	StatusContainerConfigurationError = "status_container_configuration_error"
	StatusContainerReady              = "status_container_ready"
	StatusContainerRunning            = "status_container_running"
)
View Source
const (
	ErrCannotCreatePortMap = utils.ErrCannotCreatePortMap
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigOptions

type ConfigOptions struct {
	// Specify a version of Divan Docker. Leave blank to use latest stable version.
	Version string `json:"version"`
	// Custom name for your container.
	ContainerName string `json:"containerName"`
	// Create a named volume to keep data consistent between shutdowns.
	VolumeName string `json:"volumeName"`
	// Environment variable to pass to the container.
	Env []string
}

type DivanManager

type DivanManager struct {
	ConfigPath    string
	Version       string
	ContainerName string
	VolumeName    string
	Env           []string
	// contains filtered or unexported fields
}

func New

func New(configPath string, options *ConfigOptions) (*DivanManager, *errors.Error)

Create a new manager object.

May return:

  • ErrMissingConfigPath
  • ErrCannotRunDocker

func (*DivanManager) Clean

func (dm *DivanManager) Clean() *errors.Error

Removes the container.

May return:

  • ErrNoContainerRunning
  • ErrCannotKillContainer
  • ErrCannotRemoveContainer

func (*DivanManager) Cli

func (dm *DivanManager) Cli() *client.Client

func (*DivanManager) ClusterStatus added in v0.1.1

func (dm *DivanManager) ClusterStatus(timeout int) (string, error)

func (*DivanManager) Ctx

func (dm *DivanManager) Ctx() context.Context

func (*DivanManager) Exec

func (dm *DivanManager) Exec(cmd string) (*bufio.Reader, *errors.Error)

func (*DivanManager) Init

func (dm *DivanManager) Init() *errors.Error

Setup manager environment.

May return:

  • ErrCannotRunDocker

func (*DivanManager) Logs

func (dm *DivanManager) Logs() (string, *errors.Error)

func (*DivanManager) Remove

func (dm *DivanManager) Remove() *errors.Error

func (*DivanManager) Start

func (dm *DivanManager) Start(timeout int) *errors.Error

Runs the container.

May return:

  • ErrContainerAlreadyRunning
  • ErrCannotPullImage
  • ErrCannotCreatePortMap
  • ErrCannotCreateContainer
  • ErrCannotRunContainer

func (*DivanManager) Stop

func (dm *DivanManager) Stop() *errors.Error

func (*DivanManager) Update

func (dm *DivanManager) Update() *errors.Error

Updates a running container.

May return:

  • ErrNoContainerRunning
  • ErrCannotCreateCommand
  • ErrCannotRunCommand

func (*DivanManager) Verify

func (dm *DivanManager) Verify() *errors.Error

Check if configuration is valid.

May return:

  • ErrMissingConfigPath

func (*DivanManager) WaitForReady

func (dm *DivanManager) WaitForReady(timeout int) *errors.Error

Wait for configuration to complete.

May return:

  • ErrExecutionError
  • ErrUnknownExecutionError

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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