gantry

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2019 License: Apache-2.0 Imports: 20 Imported by: 0

README

Gantry (Container Crane)

GoDoc Build Status Go Report Card

Gantry is a pipeline management tool using containers for all relevant steps. It supports a basic docker-compose subset allowing docker-compose like deployments with wharfer. If wharfer is not installed docker will be used directly.

Differences between docker-compose and gantry

  • Additional steps which can be used for pipelines as they are sequentially executed as soon as all required prevous steps are executed instead of all at the same time as services in docker-compose. Steps and services can depend on one another. This allows steps to use deployed services. To enable this explicit sequentiality the after relation is introduced in steps.
  • Generating .dot file showing dependencies using gantry dot.

Build/Download

Binary releases are provided here. Alternatively you can build your own release as described in the Building a Release section.

Gantry is go getable through

go get github.com/ad-freiburg/gantry/cmd/gantry

This will result in a binary without a set version.

Building a Release

To build a release version first make sure everything works, then edit the Setup section of this Readme so the download link points to the future version. Only after committing this final change tag the release

git tag -a vX.Y.Z -m <message>

Then build with -ldflags such that the version is added to the binary

go build -ldflags="-X github.com/ad-freiburg/gantry.Version=$(git describe --always --long --dirty)" cmd/gantry/gantry.go

Finally use the GitHub Releases mechanism to release a new version

Installing from source

To install gantry into the users ~/go/bin path it is enough to just run

go install -ldflags="-X github.com/ad-freiburg/gantry.Version=$(git describe --always --long --dirty)" ./...

Setup

# For a build from source
sudo mv gantry /usr/local/bin/
# or for the binary release
cd /tmp
rm gantry_$(uname -m).tar.bz2
wget https://github.com/ad-freiburg/gantry/releases/download/v0.3.0/gantry_$(uname -m).tar.bz2
tar -xavf gantry_$(uname -m).tar.bz2
sudo mv gantry_$(uname -m)/gantry /usr/local/bin/gantry

gantry --version

Documentation

Index

Constants

View Source
const AnsiForegroundColorBlack int = 30

AnsiForegroundColorBlack stores int value for black foreground

View Source
const AnsiForegroundColorBlue int = 34

AnsiForegroundColorBlue stores int value for blue foreground

View Source
const AnsiForegroundColorCyan int = 36

AnsiForegroundColorCyan stores int value for cyan foreground

View Source
const AnsiForegroundColorDarkGray int = 90

AnsiForegroundColorDarkGray stores int value for dark gray foreground

View Source
const AnsiForegroundColorGreen int = 32

AnsiForegroundColorGreen stores int value for green foreground

View Source
const AnsiForegroundColorLightBlue int = 94

AnsiForegroundColorLightBlue stores int value for light blue foreground

View Source
const AnsiForegroundColorLightCyan int = 96

AnsiForegroundColorLightCyan stores int value for light cyan foreground

View Source
const AnsiForegroundColorLightGray int = 37

AnsiForegroundColorLightGray stores int value for light gray foreground

View Source
const AnsiForegroundColorLightGreen int = 92

AnsiForegroundColorLightGreen stores int value for light green foreground

View Source
const AnsiForegroundColorLightMagenta int = 95

AnsiForegroundColorLightMagenta stores int value for light magenta foreground

View Source
const AnsiForegroundColorLightRed int = 91

AnsiForegroundColorLightRed stores int value for light red foreground

View Source
const AnsiForegroundColorLightYellow int = 93

AnsiForegroundColorLightYellow stores int value for light yellow foreground

View Source
const AnsiForegroundColorMagenta int = 35

AnsiForegroundColorMagenta stores int value for magenta foreground

View Source
const AnsiForegroundColorRed int = 31

AnsiForegroundColorRed stores int value for red foreground

View Source
const AnsiForegroundColorWhite int = 97

AnsiForegroundColorWhite stores int value for white foreground

View Source
const AnsiForegroundColorYellow int = 33

AnsiForegroundColorYellow stores int value for yellow foreground

View Source
const AnsiStyleBold int = 1

AnsiStyleBold stores int value for bold style

View Source
const AnsiStyleDim int = 2

AnsiStyleDim stores int value for dim style

View Source
const AnsiStyleItalic int = 3

AnsiStyleItalic stores int value for italic style

View Source
const AnsiStyleNormal int = 0

AnsiStyleNormal stores int value for normal style

View Source
const AnsiStyleStrikethrough int = 9

AnsiStyleStrikethrough stores int value for strikethrough style

View Source
const AnsiStyleUnderline int = 4

AnsiStyleUnderline stores int value for underline style

View Source
const DockerCompose string = "docker-compose.yml"

DockerCompose stores the default name of a docker compose file.

View Source
const GantryDef string = "gantry.def.yml"

GantryDef stores the default name of a gantry definition.

View Source
const GantryEnv string = "gantry.env.yml"

GantryEnv stores the default name of a gantry environment.

View Source
const GenericStringFormat string = "\u001b[%sm%s\u001b[0m"

GenericStringFormat provides formatting for a single string enclodes in ANSI formatting tags.

View Source
const PrefixedWriterFormat string = "%s\u001b[0m %s\u001b[0m"

PrefixedWriterFormat provides formatting for to space separated strings resetting ANSI formatting after each string.

Variables

View Source
var (

	// Version of the program
	Version = "no-version"
	// Verbose is a global verbosity flag
	Verbose = false
	// ProjectName stores the global prefix for networks and containers.
	ProjectName = ""
	// ForceWharfer is a global flag to force the usage of wharfer even
	// if the user could use docker directly.
	ForceWharfer = false
)

Functions

func ApplyAnsiStyle

func ApplyAnsiStyle(text string, style ...int) string

ApplyAnsiStyle applies ansi integer styles to text

func BuildAnsiStyle

func BuildAnsiStyle(parts ...int) string

BuildAnsiStyle combines style integers with ;

func GetNextFriendlyColor

func GetNextFriendlyColor() int

GetNextFriendlyColor returns the next friendly color from the global friendlyColors store.

func NewContainerKiller

func NewContainerKiller(step Step) func() (int, error)

func NewContainerRemover

func NewContainerRemover(step Step) func() error

func NewContainerRunner

func NewContainerRunner(step Step, network string) func() error

func NewImageBuilder

func NewImageBuilder(step Step, pull bool) func() error

func NewImageExistenceChecker

func NewImageExistenceChecker(step Step) func() error

func NewImagePuller

func NewImagePuller(step Step) func() error

func NewNetworkCreator

func NewNetworkCreator(p Pipeline) func() error

func NewNetworkRemover

func NewNetworkRemover(p Pipeline) func() error

Types

type BuildInfo

type BuildInfo struct {
	Context    string                  `json:"context"`
	Dockerfile string                  `json:"dockerfile"`
	Args       types.MappingWithEquals `json:"args"`
}

BuildInfo represents the build-keyword in a docker-compse.yml.

type ColorStore

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

ColorStore provides a synced looping stylelist.

func NewColorStore

func NewColorStore(colors []int) *ColorStore

NewColorStore creates a ColorStore for the provided list of styles.

func (*ColorStore) NextColor

func (c *ColorStore) NextColor() int

NextColor returns the next color. Loops if list is exhausted.

type Executable

type Executable interface {
	Exec() error
	Output() ([]byte, error)
}

type LocalRunner

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

Local host

func NewLocalRunner

func NewLocalRunner(prefix string, stdout io.Writer, stderr io.Writer) *LocalRunner

func (*LocalRunner) Exec

func (r *LocalRunner) Exec() error

func (*LocalRunner) Output

func (r *LocalRunner) Output() ([]byte, error)

func (*LocalRunner) SetCommand

func (r *LocalRunner) SetCommand(name string, args []string)

type LogSettings

type LogSettings struct {
}

type Pipeline

type Pipeline struct {
	Definition  *PipelineDefinition
	Environment *PipelineEnvironment
	NetworkName string
}

Pipeline stores all definitions and settings regarding a deployment.

func NewPipeline

func NewPipeline(definitionPath, environmentPath string, environment types.MappingWithEquals, ignoredSteps types.StringSet, selectedSteps types.StringSet) (*Pipeline, error)

NewPipeline creates a new Pipeline from given files which ignores the existence of steps with names provided in ignoreSteps.

func (Pipeline) BuildImages

func (p Pipeline) BuildImages(force bool) error

BuildImages builds all buildable images of Pipeline p in parallel.

func (Pipeline) Check

func (p Pipeline) Check() error

Check validates Pipeline p, checks if all required information is present.

func (*Pipeline) CleanUp

func (p *Pipeline) CleanUp(signal os.Signal)

CleanUp removes containers and temporary data.

func (Pipeline) CreateNetwork

func (p Pipeline) CreateNetwork() error

CreateNetwork creates a network using the NetworkName of the Pipeline p.

func (Pipeline) ExecuteSteps

func (p Pipeline) ExecuteSteps() error

ExecuteSteps runs all not ignored steps/services in the order defined by there dependencies. Each step/service is run as soon as possible.

func (Pipeline) KillContainers

func (p Pipeline) KillContainers(preRun bool) error

KillContainers kills all running containers of Pipeline p.

func (Pipeline) PullImages

func (p Pipeline) PullImages(force bool) error

PullImages pulls all pullable images of Pipeline p in parallel.

func (Pipeline) RemoveContainers

func (p Pipeline) RemoveContainers(preRun bool) error

RemoveContainers removes all stopped containers of Pipeline p.

func (Pipeline) RemoveNetwork

func (p Pipeline) RemoveNetwork() error

RemoveNetwork removes the network of Pipeline p.

func (Pipeline) RemoveTempDirData

func (p Pipeline) RemoveTempDirData() error

RemoveTempDirData deletes all data stored in temporary directories.

func (Pipeline) Runner

func (p Pipeline) Runner() Runner

Runner returns a runner for the pipeline itself. Currently only localhost.

type PipelineDefinition

type PipelineDefinition struct {
	Version string
	Steps   StepList
	// contains filtered or unexported fields
}

PipelineDefinition stores docker-compose services and gantry steps.

func NewPipelineDefinition

func NewPipelineDefinition(path string, env *PipelineEnvironment) (*PipelineDefinition, error)

func (*PipelineDefinition) Pipelines

func (p *PipelineDefinition) Pipelines() (*Pipelines, error)

Pipelines calculates and verifies dependencies and ordering for steps defined in the PipelineDefinition p.

func (*PipelineDefinition) UnmarshalJSON

func (r *PipelineDefinition) UnmarshalJSON(data []byte) error

UnmarshalJSON loads a PipelineDefinition from json using the pipelineJson struct.

type PipelineEnvironment

type PipelineEnvironment struct {
	Version            string
	LogSettings        LogSettings
	Substitutions      types.MappingWithEquals
	TempDirPath        string
	TempDirNoAutoClean bool
	Steps              ServiceMetaList
	ProjectName        string
	// contains filtered or unexported fields
}

PipelineEnvironment stores additional data for pipelines and steps.

func NewPipelineEnvironment

func NewPipelineEnvironment(path string, substitutions types.MappingWithEquals, ignoredSteps types.StringSet, selectedSteps types.StringSet) (*PipelineEnvironment, error)

NewPipelineEnvironment builds a new environment merging the current environment, the environment given by path and the user provided steps to ignore.

func (*PipelineEnvironment) ApplyTo

func (e *PipelineEnvironment) ApplyTo(rawFile []byte) ([]byte, error)

ApplyTo executes the environment template parser on the provided data.

func (*PipelineEnvironment) CleanUp

func (e *PipelineEnvironment) CleanUp(signal os.Signal)

CleanUp tries to remove all managed temporary files and directories.

func (*PipelineEnvironment) UnmarshalJSON

func (r *PipelineEnvironment) UnmarshalJSON(data []byte) error

UnmarshalJSON loads a PipelineDefinition from json using the pipelineJson struct.

type Pipelines

type Pipelines [][]Step

Pipelines stores parallel and dependent steps/services.

func NewTarjan

func NewTarjan(steps map[string]Step) (*Pipelines, error)

NewTarjan performs tarjans algorithm to convert steps to pipelines.

func (Pipelines) AllSteps

func (p Pipelines) AllSteps() []Step

AllSteps returns all in p defined steps without ordering information.

func (*Pipelines) Check

func (p *Pipelines) Check() error

Check performs checks for cyclic dependencies and requirements fulfillment.

type PrefixedLogger

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

func NewPrefixedLogger

func NewPrefixedLogger(prefix string, logger *log.Logger) *PrefixedLogger

func (*PrefixedLogger) Printf

func (p *PrefixedLogger) Printf(format string, v ...interface{})

func (*PrefixedLogger) Println

func (p *PrefixedLogger) Println(v ...interface{})

func (*PrefixedLogger) Write

func (p *PrefixedLogger) Write(b []byte) (int, error)

type PrefixedWriter

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

func NewPrefixedWriter

func NewPrefixedWriter(prefix string, target io.Writer) *PrefixedWriter

func (*PrefixedWriter) Output

func (p *PrefixedWriter) Output() error

func (*PrefixedWriter) Write

func (p *PrefixedWriter) Write(b []byte) (int, error)

type Runner

type Runner interface {
	Executable
	SetCommand(name string, args []string)
}

type Service

type Service struct {
	BuildInfo   BuildInfo                 `json:"build"`
	Command     types.StringOrStringSlice `json:"command"`
	Entrypoint  types.StringOrStringSlice `json:"entrypoint"`
	Image       string                    `json:"image"`
	Ports       []string                  `json:"ports"`
	Volumes     []string                  `json:"volumes"`
	Environment types.MappingWithEquals   `json:"environment"`
	DependsOn   types.StringSet           `json:"depends_on"`
	Restart     string                    `json:"restart"`
	Name        string
	Meta        ServiceMeta
	// contains filtered or unexported fields
}

Service provides a service definition from docker-compose.

func (Service) ColoredContainerName

func (s Service) ColoredContainerName() string

ColoredContainerName returns the container name of s with color applied.

func (Service) ColoredName

func (s Service) ColoredName() string

ColoredName returns the name of s with color applied.

func (Service) ContainerName

func (s Service) ContainerName() string

ContainerName returns the name for a container of s prefixed with the current project name.

func (Service) ImageName

func (s Service) ImageName() string

ImageName returns the name of the image of s. The name of the step is used if non is specified.

func (*Service) InitColor

func (s *Service) InitColor()

InitColor initializes the color of s.

func (Service) RawContainerName

func (s Service) RawContainerName() string

RawContainerName returns the name for a container of s.

func (Service) Runner

func (s Service) Runner() Runner

Runner returns a Runner which can execute s.

type ServiceKeepAlive

type ServiceKeepAlive int
const (
	KeepAliveYes ServiceKeepAlive = iota
	KeepAliveNo
	KeepAliveReplace
)

func (*ServiceKeepAlive) UnmarshalJSON

func (d *ServiceKeepAlive) UnmarshalJSON(b []byte) error

UnmarshalJSON sets *r to a copy of data.

type ServiceList

type ServiceList map[string]Step

ServiceList stores docker-compose service definitions as steps.

func (*ServiceList) UnmarshalJSON

func (r *ServiceList) UnmarshalJSON(data []byte) error

UnmarshalJSON sets *r to a copy of data.

type ServiceLog

type ServiceLog struct {
	Handler ServiceLogHandler `json:"handler"`
	Path    string            `json:"path"`
	// contains filtered or unexported fields
}

func (*ServiceLog) Close

func (l *ServiceLog) Close()

func (*ServiceLog) Open

func (l *ServiceLog) Open(std *os.File) error

Open handles output initialisation by setting defaults and creating files.

func (ServiceLog) Write

func (l ServiceLog) Write(p []byte) (int, error)

type ServiceLogHandler

type ServiceLogHandler int
const (
	LogHandlerStdout ServiceLogHandler = iota
	LogHandlerFile
	LogHandlerBoth
	LogHandlerDiscard
)

func (*ServiceLogHandler) UnmarshalJSON

func (d *ServiceLogHandler) UnmarshalJSON(b []byte) error

type ServiceMeta

type ServiceMeta struct {
	Ignore        bool             `json:"ignore"`
	IgnoreFailure bool             `json:"ignore_failure"`
	KeepAlive     ServiceKeepAlive `json:"keep_alive"`
	Stdout        ServiceLog       `json:"stdout"`
	Stderr        ServiceLog       `json:"stderr"`
	Selected      bool
	Type          ServiceType
}

func (*ServiceMeta) Close

func (m *ServiceMeta) Close()

func (*ServiceMeta) Open

func (m *ServiceMeta) Open() error

Open handles output initialisation by setting defaults.

type ServiceMetaList

type ServiceMetaList map[string]ServiceMeta

type ServiceType

type ServiceType int
const (
	ServiceTypeService ServiceType = iota
	ServiceTypeStep
)

type Step

type Step struct {
	Service
	Role   string          `json:"role"`
	After  types.StringSet `json:"after"`
	Detach bool            `json:"detach"`
}

Step provides an extended service.

func (Step) BuildCommand

func (s Step) BuildCommand(pull bool) []string

BuildCommand returns the command to build a new image for s.

func (Step) Dependencies

func (s Step) Dependencies() types.StringSet

Dependencies returns all steps needed for running s.

func (Step) PullCommand

func (s Step) PullCommand() []string

PullCommand returns the command to pull the image for step s.

func (Step) RunCommand

func (s Step) RunCommand(network string) []string

RunCommand returns the command to run an instance of step s.

type StepList

type StepList map[string]Step

StepList stores gantry steps as steps.

func (*StepList) UnmarshalJSON

func (r *StepList) UnmarshalJSON(data []byte) error

UnmarshalJSON sets *r to a copy of data.

Directories

Path Synopsis
cmd
Package types implements types which can be unmarshaled from json.
Package types implements types which can be unmarshaled from json.

Jump to

Keyboard shortcuts

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