pipelines

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package pipelines defines the pipeline API.

Index

Constants

View Source
const (
	// Endpoints waits for all the services in the stack to have at least one
	// endpoint ready.
	Endpoints = WaitForResourceKind("endpoints")

	// Pods waits for all the pods in the stack to be ready.
	Pods = WaitForResourceKind("pods")

	// OnePodPerService waits for at least one pod up and running per service.
	OnePodPerService = WaitForResourceKind("onePodPerService")
)

Variables

View Source
var WaitForResourceKinds = []WaitForResourceKind{
	Endpoints,
	Pods,
	OnePodPerService,
}

WaitForResourceKinds contains all the valid resource kinds to wait for.

Functions

This section is empty.

Types

type BaseCommand

type BaseCommand struct {
	// WorkingDir is the working directory where to execute the command,
	// relative to the workspace root (see config.Config.WorkspaceDir).
	// If omitted, the working directory is not changed.
	WorkingDir string `yaml:"workingDir,omitempty"`

	// Command is the command to execute.
	Command []string `yaml:"command" validate:"min=1"`

	// Env is a list of environment variables, specified as "name=value"
	// strings.  The values can be templated.  The template functions
	// allow, e.g., to request service addresses, configuration values,
	// that come from the deployment stage.
	Env []string `yaml:"env"`
}

BaseCommand gives instructions to set up the environment and invoke a command.

type BrowserSync

type BrowserSync struct {
	// Name is the name of the browser-sync configuration.
	Name string `yaml:"name" validate:"required,name"`

	// LocalPort is the local port the website can be accessed to, using a browser.
	LocalPort int `yaml:"localPort" validate:"min=1"`

	// K8sProxy gives the Kubernetes pod to listen to.  browser-sync acts as a proxy
	// between this Kubernetes port and "LocalPort".  This proxy is responsible
	// for injecting custom JavaScript code to enable live reloading.
	K8sProxy BrowserSyncK8sProxy `yaml:"k8sProxy"`

	// Config gives an additional map of configuration options to pass
	// to browser-sync.  See https://www.browsersync.io/docs/options.
	//
	// One important option is reloadDelay.  This option must typically be manually
	// tuned to account for the round trip with a remote server (the local file
	// changes must be sent over the network).
	Config map[string]interface{} `yaml:"config"`

	// Paths is a list of local file paths/path specs that are watched.
	Paths []string `yaml:"paths" validate:"min=1"`
}

BrowserSync is a dev tool to perform live reload in a browser: when the code for a page changes, the page is automatically refreshed. This process saves times and provides for an improved developer experience. BrowserSync only makes sense when it comes with, e.g., Ksync.

BrowserSync is a tiny wrapper on top of the popular https://www.browsersync.io/.

type BrowserSyncK8sProxy

type BrowserSyncK8sProxy struct {
	// Selector is a Kubernetes selector.  The first pod that matches the
	// selector is used for the proxy.
	Selector string `yaml:"selector" validate:"required"`

	// RemotePort is the port on the pod to proxy to.
	RemotePort int `yaml:"remotePort" validate:"min=1"`
}

BrowserSyncK8sProxy configures browser-sync as a proxy to a Kubernetes pod.

type Command

type Command struct {
	BaseCommand `yaml:",inline"`

	// Name is the name of the run configuration.
	Name string `yaml:"name" validate:"required,name"`

	// Description describes the run configuration.
	Description string `yaml:"description,omitempty"`

	// Tags are arbitrary tags associated with the run configuration.
	// They can be used to organize run configurations.
	Tags []string `yaml:"tags" validate:"name"`

	Setup string `yaml:"setup"`
}

Command describes a command configuration. Command configurations are used to spawn processes that can access the stack, with port forwarding and other mechanisms, between the setup and the tear down of the stack.

type CommandHook

type CommandHook struct {
	// Name is an optional name to help identify the hook.
	Name string `yaml:"name,omitempty" validate:"name"`

	// DependsOn lists the name of other command hooks that must be executed
	// successfully before this command hook is executed.  Loops
	// are of course forbidden.
	DependsOn []string `yaml:"dependsOn"`

	// WaitFor indicates that the hook must wait for the resources
	// to be in a certain state.
	WaitFor *WaitForHook `yaml:"waitFor,omitempty"`

	// Run indicates that the hook must execute a command.
	Run *BaseCommand `yaml:"run,omitempty"`

	// HttpGet indicates that the hook must perform an HTTP Get.
	HTTPGet *HTTPGet `yaml:"httpGet,omitempty"`

	// Timeout in seconds after which the hook is considered to have failed.
	// 0 indicates no timeout.
	TimeoutSeconds int `yaml:"timeoutSeconds,omitempty"`
}

CommandHook is a command used as a set-up/tear-down hook.

type Container

type Container struct {
	// Manifest is the path to the container manifest, relative to
	// the workspace root (see config.Config.WorkspaceDir).
	//
	// The container manifest associates image names, as they are
	// referenced in configuration files (such as Kubernetes resources)
	// to actual addresses.
	Manifest string `yaml:"manifest,omitempty"`

	// ParsedManifest is populated by Read and contains the parsed
	// version of the Manifest.
	ParsedManifest ContainerManifest `yaml:"-"`

	// Label gives a list of additional labels to apply to all the
	// images in the manifest.  New images are created with these labels,
	// and pushed to the container registry.
	Label []string `yaml:"label,omitempty"`

	// Push gives an alternative container registry to use for the
	// stack.  The images in the manifest are tagged for this registry,
	// then pushed to this registry.  This is useful, e.g., when
	// wants to put images to a production registry.
	Push string `yaml:"push,omitempty"`
}

Container describes the deployment steps relative to containerization.

type ContainerManifest

type ContainerManifest map[string]ContainerManifestEntry

ContainerManifest associates "shortcut" image names to actual container image reference. A container manifest is typically an output of the build process.

type ContainerManifestEntry

type ContainerManifestEntry struct {
	// Ref is a reference to an actual image in a container registry.
	Ref string `json:"ref"`
}

ContainerManifestEntry is an entry in the container manager.

type Deploy

type Deploy struct {
	// Container describes the deployment steps relative to
	// containerization.
	Container *Container `yaml:"container,omitempty"`

	// Helm describes the Helm chart to use to deploy to
	// a Kubernetes cluster.  If it is omitted,
	// the stack is not deployed to Kubernetes with helm.
	//
	// The Helm step always happens before the Kustomize step.
	Helm *Helm `yaml:"helm,omitempty"`

	// Kustomize describes the Kustomize config to use to
	// deploy to a Kubernetes cluster.  If it is omitted,
	// the stack is not deployed to Kubernetes with kustomize.
	Kustomize *Kustomize `yaml:"kustomize,omitempty"`
}

Deploy describes the deployment steps.

type Dev

type Dev struct {
	// Ksync lists ksync configurations.
	Ksync []Ksync `yaml:"ksync,omitempty" patchStrategy:"merge" patchMergeKey:"names" validate:"dive"`

	// BrowserSync lists browser-sync configurations.
	BrowserSync []BrowserSync `yaml:"browserSync,omitempty" patchStrategy:"merge" patchMergeKey:"names" validate:"dive"`

	// PortForward lists port forwarding configurations.
	PortForward []PortForward `yaml:"portForward,omitempty" patchStrategy:"merge" patchMergeKey:"names" validate:"dive"`
}

Dev describes the dev tools. They are enabled when running a pipeline in dev mode. They can be used interactively, during local development or debugging.

type HTTPGet

type HTTPGet struct {
	// URL to send the GET request to.  The URL is subject to
	// template substitution.
	URL string `yaml:"url" validate:"required"`

	// HTTPHeaders is a list of custom HTTP headers to set in
	// the request.  HTTP allows repeated headers.
	HTTPHeaders []HTTPHeader `yaml:"httpHeaders"`
}

HTTPGet is a hook that waits for a URL to returns a 2xx status.

type HTTPHeader

type HTTPHeader struct {
	// Name of the HTTP header
	Name string `yaml:"name" validate:"required"`

	// Value of the HTTP header.
	Value string `yaml:"value"`
}

HTTPHeader specifies the name and value of an HTTP header.

type Helm added in v0.1.0

type Helm struct {
	// Path to the helm chart, relative to the root given in the
	// warprc.toml configuration.
	Path string `yaml:"path" validate:"required"`

	// Args are additional arguments to pass to the Helm CLI.
	Args []string `yaml:"args"`

	// Selector is a label to use with `kubectl apply` for resource pruning.
	// If not specified, it defaults to `warp.stack=<stack name>`, where
	// `<stack name>` is the name of the stack.
	LabelSelector string `yaml:"labelSelector"`
}

Helm describe the Help config to use to deploy to a Kubernetes cluster.

type Ksync

type Ksync struct {
	// Name is the name of the ksync configuration.
	Name string `yaml:"name" validate:"required,name"`

	// Selector is a Kubernetes selector to select the pods to synchronize.
	Selector string `yaml:"selector" validate:"required"`

	// DeploymentName is the name of the deployment used to create the pods.
	DeploymentName string `yaml:"deploymentName" validate:"required"`

	// Local is the path to the local file or folder to synchronize.
	Local string `yaml:"local" validate:"required"`

	// Remote is the path to the remote file or folder to synchronize.
	// The file or folder lives on the pod's file system.
	Remote string `yaml:"remote" validate:"required"`

	// DisableReloading disables reloading the pod when the files change.
	// Reloading is enabled by default.
	DisableReloading bool `yaml:"disableReloading"`

	// LocalReadOnly sets the local file system as read only.  This means
	// that only changes coming from the local file system will be mirrored
	// to the pod file system.  Changes in the pod file system won't make
	// it back to the local file system.
	LocalReadOnly bool `yaml:"localReadOnly"`

	// RemoteReadOnly sets the pod file system as read only.  This means
	// that only changes coming from the od file system will be mirrored
	// to the local file system.  Changes in the local file system won't make
	// it back to the pod file system.
	RemoteReadOnly bool `yaml:"remoteReadOnly"`
}

Ksync is a dev tool to synchronize local files (such as source files) and the files of Kubernetes pods. ksync is roughly the equivalent, in the context of a multi-node system, of mounting a local volume. It can be used to update pods when the source file changes, without having to build the containers again.

Ksync is a tiny wrapper on top of the popular https://github.com/ksync/ksync.

type Kustomize

type Kustomize struct {
	// Path to the kustomization file, relative to the root given
	// in the warprc.toml configuration.
	Path string `yaml:"path" validate:"required"`

	// DisableNamePrefix Disables prefixing the names of Kubernetes
	// resources with the names of the Stack.
	DisableNamePrefix bool `yaml:"disableNamePrefix"`

	// PatchesStrategicMerge contains additional patches to apply
	// with a strategic merge.  The patches are subject to template
	// expansion.
	PatchesStrategicMerge []string `yaml:"patchesStrategicMerge,omitempty" patchStrategy:"append"`
}

Kustomize describes the Kustomize config to use to deploy to a Kubernetes cluster.

type Lint added in v0.1.0

type Lint struct {
	// DisableHelmKubeScore disables applying kube-score on the
	// Kubernetes resources created by Helm.
	DisableHelmKubeScore bool `yaml:"disableHelmKubeScore"`

	// DisableKustomizeKubeScore disables applying kube-score on
	// the Kubernetes resources created by Kustomize.
	DisableKustomizeKubeScore bool `yaml:"disableKustomizeKubeScore"`
}

Lint describes the linting steps

type Pipeline

type Pipeline struct {
	// Stack gives the identity of the stacks created by the pipeline.
	Stack Stack `yaml:"stack"`

	// Bases contains base files to merge into this pipeline, using
	// strategic merging.  The file names must be relative to the
	// root given in the warprc.toml configuration.
	//
	// Loops in the inheritance chain are forbidden and explicitly
	// controlled for.
	Bases []string `yaml:"bases,omitempty"`

	Lint Lint `yaml:"lint"`

	// Deploy describes the deployment steps.
	Deploy Deploy `yaml:"deploy"`

	Setups Setups `yaml:"setups,omitempty" patchStrategy:"merge" patchMergeKey:"name" validate:"dive"`

	// Command describes the command configurations.  Command configurations
	// are used to spawn processes that can access the stack, with
	// port forwarding and other mechanisms, between the setup and
	// the tear down of the stack.
	Commands []Command `yaml:"commands,omitempty" patchStrategy:"merge" patchMergeKey:"name" validate:"dive"`

	// Path is the absolute path to the pipeline definition.  It is
	// resolved by Read.
	Path string `yaml:"-"`
}

Pipeline defines a deployment and test pipeline. Its scope is everything beyond the build step and unit/integration tests.

func Read

func Read(config *config.Config, path string) (*Pipeline, error)

Read reads a pipeline from a file on the local file system. The path is given relative to the workspace root (see config.Config.WorkspaceDir).

The resulting pipeline is expanded: all the base pipelines that are referenced in the pipeline are merged.

func ReadFs

func ReadFs(config *config.Config, path string, fs afero.Fs) (*Pipeline, error)

ReadFs does the same as Read but on an arbitrary afero file system.

func (*Pipeline) Expand added in v0.1.0

func (pipeline *Pipeline) Expand(cfg *config.Config) error

Expand expands a pipeline definition with its bases it inherits from. The result of the expansion is written in a YAML file given in the config.

type PortForward

type PortForward struct {
	// Name is the name of the PortForward configuration.
	Name string `yaml:"name" validate:"required,name"`

	// Selector is a Kubernetes selector.  The first pod that matches the
	// selector is used for the port forwarding.  This is in accordance
	// with the behavior of `kubectl forward-port`.
	Selector string `yaml:"selector" validate:"required"`

	// LocalPort is the local port to forward to.
	LocalPort int `yaml:"localPort" validate:"min=1"`

	// RemotePort is the remote port to forward from.
	RemotePort int `yaml:"remotePort" validate:"min=1"`
}

PortForward is a dev tool to forward the port on a pod to the local machine.

type Setup added in v0.1.0

type Setup struct {
	// Name is the name of the environment.
	Name string `yaml:"name" validate:"required,name"`

	// Bases contains base files to merge into this pipeline, using
	// strategic merging.  The file names must be relative to the
	// root given in the warprc.toml configuration.
	//
	// Loops in the inheritance chain are forbidden and explicitly
	// controlled for.
	Bases []string `yaml:"bases,omitempty"`

	// Before is a list of command hooks that are executed concurrently
	// before the command itself is actually executed.  If any of the
	// hook fails, the other hooks and the command itself are skipped.
	// The execution is eventually reported as a failure.
	Before []CommandHook `yaml:"before,omitempty" validate:"dive"`

	// Env is a list of environment variables, specified as "name=value"
	// strings.  The values can be templated.  The template functions
	// allow, e.g., to request service addresses, configuration values,
	// that come from the deployment stage.
	Env []string `yaml:"env"`

	// Dev describes the dev tools.  They are enabled when running
	// a pipeline in dev mode.  They can be used interactively,
	// during local development or debugging.
	Dev Dev `yaml:"dev"`
}

Setup defines the resources to set up and tear down around the execution of test or batch commands.

type Setups added in v0.1.0

type Setups []Setup

Setups is a slice of named setups. Within this slice, names are unique.

func (Setups) Get added in v0.1.0

func (setups Setups) Get(name string) (*Setup, error)

Get gets the setup given its name.

func (Setups) MustGet added in v0.5.0

func (setups Setups) MustGet(name string) *Setup

Get gets the setup given its name. Panics if the setup cannot be found.

func (Setups) Names added in v0.1.0

func (setups Setups) Names() []string

Names gets a slice of all the setup names.

type Stack

type Stack struct {
	// Name is the names of the stack.  If it is not given, a names
	// is acquired for Family with the name_manager.  Either Name or
	// Family must be given.
	Name string `yaml:"name,omitempty"`

	// Family for the name_manager.
	Family string `yaml:"family,omitempty"`

	// Variant is the variant of the stack.  Stacks of the same family
	// can indeed be produced by multiple pipelines to share resources.
	// Variant is a way to differentiate between them.
	Variant string `yaml:"variant,omitempty"`
}

Stack gives the identity of the stacks created by the pipeline.

type WaitForHook

type WaitForHook struct {
	// Resources lists the resource kinds to wait for.
	Resources []WaitForResourceKind `yaml:"resources"`
}

WaitForHook is a hook that waits for external resources to be available, running or ready.

type WaitForResourceKind

type WaitForResourceKind string

WaitForResourceKind defines what kind of waiting should be performed.

Jump to

Keyboard shortcuts

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