config

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2021 License: Apache-2.0 Imports: 20 Imported by: 22

Documentation

Index

Constants

View Source
const (
	// META is the key used for meta config
	META = "meta"
)

Variables

This section is empty.

Functions

func RegisterResource

func RegisterResource(name string, typeFunc resourceFactory)

RegisterResource registers a config type with a function to unmarshal it from config values.

Types

type AliasConfig

type AliasConfig struct {
	// Tasks The list of tasks
	// type: list of tasks
	Tasks []string `config:"required"`
	Annotations
}

AliasConfig An **alias** resource is a list of other tasks which will be run in the order they are listed. example: An alias that runs three other tasks:

.. code-block:: yaml

alias=test
    tasks: [test-unit, test-integration, test-acceptance]

name: alias

func (*AliasConfig) Dependencies

func (c *AliasConfig) Dependencies() []string

Dependencies returns the list of tasks

func (*AliasConfig) Resolve

func (c *AliasConfig) Resolve(_ Resolver) (Resource, error)

Resolve resolves variables in the resource

func (*AliasConfig) String

func (c *AliasConfig) String() string

func (*AliasConfig) Validate

func (c *AliasConfig) Validate(path pth.Path, config *Config) *pth.Error

Validate the resource

type AnnotationFields

type AnnotationFields struct {
	// Description Description of the resource. Adding a description to a
	// resource makes it visible from “dobi list“.
	Description string
	// Tags Tags can be used to group resources. There can be configured
	// multiple tags per resource. Adding a tag to a resource outputs a
	// grouped list from “dobi list -g“.
	Tags []string
}

AnnotationFields used to annotate a resource

type Annotations

type Annotations struct {
	// Description of a resource
	// Deprecated use Annotations.Description
	Description string `config:"validate"`
	Annotations AnnotationFields
}

Annotations provides a description and tags to a resource

func (*Annotations) CategoryTags

func (a *Annotations) CategoryTags() []string

CategoryTags tags returns the list of tags

func (*Annotations) Describe

func (a *Annotations) Describe() string

Describe returns the resource description

func (*Annotations) ValidateDescription

func (a *Annotations) ValidateDescription() error

ValidateDescription prints a warning if set

type ComposeConfig

type ComposeConfig struct {
	// Files The Compose files to use. This field supports :doc:`variables`.
	// type: list of filenames
	Files []string
	// Project The project name used by Compose. This field supports
	// :doc:`variables`.
	Project string `config:"required"`
	// StopGrace Seconds to wait for containers to stop before killing them.
	// default: “5“
	StopGrace int
	Dependent
	Annotations
}

ComposeConfig A **compose** resource runs “docker-compose“ to create an isolated environment. The **compose** resource keeps containers running until **dobi** exits so the containers can be used by other tasks that depend on the **compose** resource, or are listed after it in an `alias`_.

.. note::

`Docker Compose <https://github.com/docker/compose>`_ must be installed
and available in ``$PATH`` to use this resource.

name: compose example: Start a Compose environment setting the project name to “web-devenv“ and using two Compose files.

.. code-block:: yaml

compose=devenv:
    files: [docker-compose.yml, docker-compose-dev.yml]
    project: 'web-devenv'

func (*ComposeConfig) Resolve

func (c *ComposeConfig) Resolve(resolver Resolver) (Resource, error)

Resolve resolves variables in the resource

func (*ComposeConfig) StopGraceString

func (c *ComposeConfig) StopGraceString() string

StopGraceString returns StopGrace as a string

func (*ComposeConfig) String

func (c *ComposeConfig) String() string

func (*ComposeConfig) Validate

func (c *ComposeConfig) Validate(path pth.Path, config *Config) *pth.Error

Validate the resource

type Config

type Config struct {
	FilePath   string
	Meta       *MetaConfig
	Resources  map[string]Resource
	WorkingDir string
}

Config is a data object for a full config file

func Load

func Load(filename string) (*Config, error)

Load a configuration from a filename

func LoadFromBytes

func LoadFromBytes(data []byte) (*Config, error)

LoadFromBytes loads a configuration from a bytes slice

func NewConfig

func NewConfig() *Config

NewConfig returns a new Config object

func (*Config) Sorted

func (c *Config) Sorted() []string

Sorted returns the list of resource names in alphabetical sort order

func (*Config) UnmarshalYAML

func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML unmarshals a config

type Dependent

type Dependent struct {
	// Depends The list of task dependencies.
	// type: list of tasks
	Depends []string
}

Dependent can be used to provide part of the Resource interface

func (*Dependent) Dependencies

func (d *Dependent) Dependencies() []string

Dependencies returns the list of tasks

type Device

type Device struct {
	Host        string
	Container   string
	Permissions string
}

Device is the defined structure to attach host devices to containers

type EnvConfig

type EnvConfig struct {
	// Files List of files which contain environment variables
	// type: list of filenames
	Files []string
	// Variables List of environment variable “key=value“ pairs
	// type: list of environment variables
	Variables []string
	Annotations
}

EnvConfig An **env** resource provides environment variables to **job** and **compose** resources.

example: Define some variables for a “job“

.. code-block:: yaml

env=settings:
    files: [local.env]
    variables: [PORT=3838, HOST=stage]

name: env

func (*EnvConfig) Dependencies

func (c *EnvConfig) Dependencies() []string

Dependencies returns the list of job dependencies

func (*EnvConfig) Resolve

func (c *EnvConfig) Resolve(resolver Resolver) (Resource, error)

Resolve resolves variables in the config

func (*EnvConfig) String

func (c *EnvConfig) String() string

func (*EnvConfig) Validate

func (c *EnvConfig) Validate(pth.Path, *Config) *pth.Error

Validate runs config validation

type ImageConfig

type ImageConfig struct {
	// Image The name of the **image** without a tag. Tags must be specified
	// in the **tags** field. This field supports :doc:`variables`.
	Image string `config:"required,validate"`
	// Dockerfile The path to the “Dockerfile“ used to build the image. This
	// path is relative to “context“. Can not be used with “steps“
	Dockerfile string
	// Steps An inline Dockerfile used to build  the image. “steps“ can not
	// be used with the “dockerfile“ field.
	Steps string
	// Context The build context used to build the image.
	// default: “.“
	Context string
	// Args Build args used to build the image. Values in the mapping support
	// :doc:`variables`.
	// type: mapping “key: value“
	Args map[string]string
	// Target The target stage to build in a multi-stage Dockerfile. Defaults to
	// the last stage.
	Target string
	// PullBaseImageOnBuild If **true** the base image used in the
	// “Dockerfile“ will be pulled before building the image.
	PullBaseImageOnBuild bool
	// Pull Pull an image instead of building it. The value may be one of:
	// * “once“ - only pull if the image:tag does not exist
	// * “always“ - always pull the image
	// * “never“ - don't pull or build the image. Use one that is already present locally
	// * “<duration>“ - pull if the image hasn't been pulled in at least
	//   “duration“. The format of duration is a number followed by a single
	//   character time unit (ex: “40s“, “2h“, “30min“)
	// type: string
	// default: “always“
	Pull pull
	// Tags The image tags applied to the image before pushing the image to a
	// registry.  The first tag in the list is used when the image is built.
	// Each item in the list supports :doc:`variables`.
	// default: “['{unique}']“
	// type: list of tags
	Tags []string `config:"validate"`
	// NetworkMode The network mode to use for each step in the Dockerfile.
	NetworkMode string
	// CacheFrom A list of images to use as the cache for a build.
	CacheFrom []string
	Dependent
	Annotations
}

ImageConfig An **image** resource provides actions for working with a Docker image. If an image is buildable it is considered up-to-date if all files in the build context have a modified time older than the created time of the image. If using inline Dockerfile, the **dobi.yaml** file will be considered as a part of the build context. name: image example: An image with build args:

.. code-block:: yaml

image=project-dev:
    image: myproject-dev
    context: .
    args:
      version: '3.1.4'
      url: http://example.com/foo

func NewImageConfig

func NewImageConfig() *ImageConfig

NewImageConfig creates a new ImageConfig with default values

func (*ImageConfig) IsBuildable

func (c *ImageConfig) IsBuildable() bool

IsBuildable returns true if the config has the minimum required fields to build an image

func (*ImageConfig) Resolve

func (c *ImageConfig) Resolve(resolver Resolver) (Resource, error)

Resolve resolves variables in the resource

func (*ImageConfig) String

func (c *ImageConfig) String() string

func (*ImageConfig) Validate

func (c *ImageConfig) Validate(path pth.Path, config *Config) *pth.Error

Validate checks that all fields have acceptable values

func (*ImageConfig) ValidateImage

func (c *ImageConfig) ValidateImage() error

ValidateImage validates the image field does not include a tag

func (*ImageConfig) ValidateTags

func (c *ImageConfig) ValidateTags() error

ValidateTags to ensure the first tag is a basic tag without an image name.

type JobConfig

type JobConfig struct {
	// Use The name of an `image`_ resource. The referenced image is used
	// to created the container for the **job**.
	Use string `config:"required"`
	// Artifact File paths or globs identifying the files created by the **job**.
	// Paths to directories must end with a path separator (“/“).
	// Paths are relative to the “dobi.yaml“
	// type: list of file paths or glob patterns
	Artifact PathGlobs
	// Command The command to run in the container.
	// type: shell quoted string
	// example: “"bash -c 'echo something'"“
	Command ShlexSlice
	// Entrypoint Override the image entrypoint
	// type: shell quoted string
	Entrypoint ShlexSlice
	// Sources File paths or globs of the files used to create the
	// artifact. The modified time of these files are compared to the modified time
	// of the artifact to determine if the **job** is stale. If the **sources**
	// list is defined the modified time of **mounts** and the **use** image are
	// ignored.
	// type: list of file paths or glob patterns
	Sources PathGlobs
	// Mounts A list of `mount`_ resources to use when creating the container.
	// type: list of mount resources
	Mounts []string
	// Privileged Gives extended privileges to the container
	Privileged bool
	// Interactive Makes the container interative and enables a tty.
	Interactive bool
	// Env Environment variables to pass to the container. This field
	// supports :doc:`variables`.
	// type: list of “key=value“ strings
	Env []string
	// ProvideDocker Exposes the docker engine to the container by either
	// mounting the unix socket or setting the “DOCKER_HOST“ environment
	// variable. All environment variables with a  “DOCKER_“ prefix in the
	// environment are set on the container.
	ProvideDocker bool
	// NetMode The network mode to use. This field supports :doc:`variables`.
	NetMode string
	// WorkingDir The directory to set as the active working directory in the
	// container. This field supports :doc:`variables`.
	WorkingDir string
	// User Username or UID to use in the container. Format “user[:group]“.
	User string
	// Ports Publish ports to the host
	// type: list of 'host_port:container_port'
	Ports []string
	// Devices Maps the host devices you want to connect to a container
	// type: list of device specs
	// example: “{Host: /dev/fb0, Container: /dev/fb0, Permissions: rwm}“
	Devices []Device
	// Labels sets the labels of the running job container
	// type: map of string keys to string values
	Labels map[string]string
	Dependent
	Annotations
}

JobConfig A **job** resource uses an `image`_ to run a job in a container.

A **job** resource that doesn't have an “artifact“ is never considered up-to-date and will always run. If a job resource has an “artifact“ the job will be skipped if the artifact is newer than the source. The last modified time of the “artifact“ files is compared against the last modified time of the files in “sources“, or if “sources“ is left unset, the last modified time of the “use“ image and all the files in the “mounts“.

“mounts“ are provided to the container as bind mounts. If the “DOBI_NO_BIND_MOUNT“ environment variable, or `--no-bind-mount` flag is set, then “mounts“ will be copied into the container, and all artifacts will be copied out of the container to the host after the job is complete.

The `image`_ specified in “use“ and any `mount`_ resources listed in “mounts“ are automatically added as dependencies and will always be created first.

name: job example: Run a container using the “builder“ image to compile some source code to “./dist/app-binary“.

.. code-block:: yaml

job=compile:
    use: builder
    mounts: [source, dist]
    artifact: dist/app-binary

func (*JobConfig) Dependencies

func (c *JobConfig) Dependencies() []string

Dependencies returns the list of implicit and explicit dependencies

func (*JobConfig) Resolve

func (c *JobConfig) Resolve(resolver Resolver) (Resource, error)

Resolve resolves variables in the resource

func (*JobConfig) String

func (c *JobConfig) String() string

func (*JobConfig) Validate

func (c *JobConfig) Validate(path pth.Path, config *Config) *pth.Error

Validate checks that all fields have acceptable values

type MetaConfig

type MetaConfig struct {
	// Default The name of a task from the “dobi.yml“ to run when no
	// task name is specified on the command line.
	Default string

	// Project The name of the project. Used to create unique identifiers for
	// image tags and container names.
	// default: *basename of “dobi.yml“*
	Project string

	// Include A list of dobi configuration files to include. Paths are
	// relative to the current working directory. Includs can be partial
	// configs that depend on resources in any of the other included files.
	// type: list of file paths or glob patterns
	Include PathGlobs

	// ExecID A template value used as part of unique identifiers for image tags
	// and container names. This field supports :doc:`variables`. This value can
	// be overridden with the “$DOBI_EXEC_ID“ environment variable.
	// default: “{user.name}“
	ExecID string `config:"exec-id"`
}

MetaConfig Configure **dobi** and include other config files. name: meta example: Set the the project name to “mywebapp“ and run the “all“ task by default.

.. code-block:: yaml

meta:
    project: mywebapp
    default: all

func NewMetaConfig

func NewMetaConfig(name string, values map[string]interface{}) (*MetaConfig, error)

NewMetaConfig returns a new MetaConfig from config values

func (*MetaConfig) IsZero

func (m *MetaConfig) IsZero() bool

IsZero returns true if the struct contains only zero values, except for Includes which is ignored

func (*MetaConfig) Validate

func (m *MetaConfig) Validate(config *Config) error

Validate the MetaConfig

type MountConfig

type MountConfig struct {
	// Bind The host path to create and mount. This field supports expansion of
	// `~` to the current users home directory.
	Bind string
	// Path The container path of the mount
	Path string `config:"required"`
	// Name The name of a named volume
	Name string
	// ReadOnly Set the mount to be read-only
	ReadOnly bool
	// File When true create an empty file instead of a directory
	File bool
	// Mode The file mode to set on the host file or directory when it is
	// created.
	// default: “0755“ *(for directories)*, “0644“ *(for files)*
	Mode int `config:"validate"`
	Annotations
}

MountConfig A **mount** resource creates a host bind mount or named volume mount. name: mount example: A mount named “source“ that mounts the current host directory as “/app/code“ in the container.

.. code-block:: yaml

mount=source:
    bind: .
    path: /app/code

mount=named:
    name: app-data
    path: /data

func (*MountConfig) Dependencies

func (c *MountConfig) Dependencies() []string

Dependencies returns an empty list, Mount resources have no dependencies

func (*MountConfig) IsBind

func (c *MountConfig) IsBind() bool

IsBind returns true if the mount is a bind mount to a host directory

func (*MountConfig) Resolve

func (c *MountConfig) Resolve(resolver Resolver) (Resource, error)

Resolve resolves variables in the resource

func (*MountConfig) String

func (c *MountConfig) String() string

func (*MountConfig) Validate

func (c *MountConfig) Validate(path pth.Path, config *Config) *pth.Error

Validate checks that all fields have acceptable values

func (*MountConfig) ValidateMode

func (c *MountConfig) ValidateMode() error

ValidateMode validates Mode and sets a default

type PathGlobs

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

PathGlobs is a list of path globs

func (*PathGlobs) Empty

func (p *PathGlobs) Empty() bool

Empty returns true if there are no globs

func (*PathGlobs) Globs

func (p *PathGlobs) Globs() []string

Globs returns the raw list of path globs

func (*PathGlobs) NoMatches

func (p *PathGlobs) NoMatches() bool

NoMatches returns true if there are globs defined, but none are valid paths

func (*PathGlobs) Paths

func (p *PathGlobs) Paths() []string

Paths returns all the paths matched by the glob

func (*PathGlobs) String

func (p *PathGlobs) String() string

func (*PathGlobs) TransformConfig

func (p *PathGlobs) TransformConfig(raw reflect.Value) error

TransformConfig from raw value to paths

func (*PathGlobs) Validate

func (p *PathGlobs) Validate() error

Validate the globs

type Resolver

type Resolver interface {
	Resolve(tmpl string) (string, error)
	ResolveSlice(tmpls []string) ([]string, error)
}

Resolver is an interface for a type that returns values for variables

type Resource

type Resource interface {
	Dependencies() []string
	Validate(pth.Path, *Config) *pth.Error
	Resolve(Resolver) (Resource, error)
	Describe() string
	CategoryTags() []string
	String() string
}

Resource is an interface for each configurable type

type ShlexSlice

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

ShlexSlice is a type used for config transforming a string into a []string using shelx.

func (*ShlexSlice) Empty

func (s *ShlexSlice) Empty() bool

Empty returns true if the instance contains the zero value

func (*ShlexSlice) String

func (s *ShlexSlice) String() string

func (*ShlexSlice) TransformConfig

func (s *ShlexSlice) TransformConfig(raw reflect.Value) error

TransformConfig is used to transform a string from a config file into a sliced value, using shlex.

func (*ShlexSlice) Value

func (s *ShlexSlice) Value() []string

Value returns the slice value

Jump to

Keyboard shortcuts

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