mage

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2020 License: Apache-2.0 Imports: 18 Imported by: 0

README

Magefile for Cape

This package contains all of the files used to construct the Cape Magefile experience.

Architecture

Package mage

The root of the package (mage) contains the individual components that wrap our different dependencies and workflows. These components that been designed such that they don't contain particulars about our environment, instead, they're generic re-usable components that could be used to create many different workflows.

Many of these components satisfy the mage.Dependency interface which specifies a methods that can be used for managing the lifecycle of things like Go, Docker, Protoc, and others.

In addition to those that implement Dependency there are also helpers like the Artifacts tracker which makes it easy to track the artifacts that could be created during execution of a target.

Our goal is to decouple the core functionality from the specifics of our workflow making it easy and possible to write automated tests for our most critical workflows.

Package mage/targets

All of the targets are specified inside the mage/targets package. This package contains the workflow specific code and documents which artifacts are created by which commands.

Documentation

Overview

Package mage contains re-usable and testable components for building, testing, and releasing Cape using Magefile

Index

Constants

This section is empty.

Variables

View Source
var Dependencies = deps{}

Dependencies contains a list of external dependencies

Functions

func FindImports

func FindImports(file string) ([]string, error)

FindImports returns a list of all imported packages inside of a given file

func Parallel

func Parallel(ctx context.Context, funcs []ParallelFunc) error

func WaitFor

func WaitFor(ctx context.Context, f Checker, timeout time.Duration) error

Types

type Artifacts

type Artifacts struct {
	// contains filtered or unexported fields
}
var Tracker *Artifacts

Tracker is a global tracker of build artifacts

func (Artifacts) Add

func (a Artifacts) Add(path string, f Cleaner) error

func (Artifacts) Clean

func (a Artifacts) Clean(ctx context.Context) error

type Chart

type Chart struct {
	Name             string
	Chart            string
	Version          string // Version of the chart
	Values           string
	AdditionalValues map[string]string
	Atomic           bool
}

type Checker

type Checker func(context.Context) (bool, error)

type Cleaner

type Cleaner func(context.Context) error

func CleanDockerImage

func CleanDockerImage(image *DockerImage) Cleaner

func CleanDockerRegistry

func CleanDockerRegistry(r *Registry) Cleaner

func CleanFile

func CleanFile(path string) Cleaner

func CleanKind

func CleanKind(cluster *Cluster) Cleaner

type Cluster

type Cluster struct {
	Name       string
	ConfigFile string
}

TODO: Configure kubectl/helm/kind to use a _different_ kubectl config path for local development work, or, have them set the context for each command to be the cluster creatd by kind.

func (*Cluster) ContextName

func (c *Cluster) ContextName() string

ContextName returns the name of the kubectl configuration context for the cluster.

The kind binary autosets the context when a cluster is created. This name is also the name of the docker container created by kind that contains the entire cluster.

type Dependency

type Dependency interface {
	// Methods for checking if the required dependency
	Check(context.Context) error
	Name() string

	// Methods for setting up and tearing down anything needed or produced by
	// the dependency
	Setup(context.Context) error
	Clean(context.Context) error
}

Dependency is an interface for an external dependency required for a build function. An example of a dependency is Go, Docker, or Protoc.

type Docker

type Docker struct {
	Version *semver.Version
}

Docker is a dependency check for Docker

func MustDocker

func MustDocker(required string) *Docker

func NewDocker

func NewDocker(required string) (*Docker, error)

func (*Docker) Build

func (d *Docker) Build(ctx context.Context, image *DockerImage) error

func (*Docker) Check

func (d *Docker) Check(_ context.Context) error

Check returns an error if Docker isn't available or the version is incorrect

func (*Docker) Clean

func (d *Docker) Clean(_ context.Context) error

func (*Docker) Connect

func (d *Docker) Connect(ctx context.Context, name, network string) error

func (*Docker) Name

func (d *Docker) Name() string

func (*Docker) Network

func (d *Docker) Network(_ context.Context, label string) (*NetworkSettings, error)

func (*Docker) Push

func (d *Docker) Push(ctx context.Context, tag string) error

func (*Docker) Setup

func (d *Docker) Setup(_ context.Context) error

func (*Docker) Status

func (d *Docker) Status(ctx context.Context, name string) (Status, error)

func (*Docker) Tag

func (d *Docker) Tag(ctx context.Context, image *DockerImage, tag string) error

type DockerImage

type DockerImage struct {
	Name string
	File string
	Tag  string
	Args func(context.Context) (map[string]string, error)
}

func (*DockerImage) String

func (i *DockerImage) String() string

type DockerRegistry

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

Docker Registry represents a dependency for creating a Docker Registry using a Docker container.

Docker must be installed on the system.

func MustDockerRegistry

func MustDockerRegistry(docker *Docker) *DockerRegistry

func NewDockerRegistry

func NewDockerRegistry(docker *Docker) (*DockerRegistry, error)

func (*DockerRegistry) Check

func (d *DockerRegistry) Check(ctx context.Context) error

func (*DockerRegistry) Clean

func (d *DockerRegistry) Clean(_ context.Context) error

func (*DockerRegistry) Connect

func (d *DockerRegistry) Connect(ctx context.Context, r *Registry, network string) error

Connect attempts to connect the given registry to the specified docker network

func (*DockerRegistry) Create

Create starts a docker registry with the given name and port combination. The ip address of the created registry is returned

If the given registry is already running it returns an error.

func (*DockerRegistry) Destroy

func (d *DockerRegistry) Destroy(ctx context.Context, r *Registry) error

func (*DockerRegistry) Name

func (d *DockerRegistry) Name() string

func (*DockerRegistry) Setup

func (d *DockerRegistry) Setup(_ context.Context) error

func (*DockerRegistry) Status

func (d *DockerRegistry) Status(ctx context.Context, r *Registry) (Status, error)

Status returns whether or not the container is currently running

type Env

type Env map[string]string

Env represents a set of environment variables

func (Env) Source

func (e Env) Source()

Source checks the os environment for the current keys. If any are set (e.g. no-zero length string) then the value is overridden.

type Errors

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

Errors is a concurrency safe wrapper around uber's multierr

func NewErrors

func NewErrors() *Errors

func (*Errors) Append

func (e *Errors) Append(err error) bool

Append adds the error into the underlying multierr combining all of the errors together into one error

func (*Errors) Err

func (e *Errors) Err() error

Err returns the underlying error (which can be nil if no non-nil errors were appended)

func (*Errors) Error

func (e *Errors) Error() string

Error completes the error interface

func (*Errors) Errors

func (e *Errors) Errors() []error

Errors returns the underlying slice of errors

type Generator

type Generator interface {
	Generate(_ context.Context) error
}

type Git

type Git struct {
	Version *semver.Version
}

func MustGit

func MustGit(required string) *Git

func NewGit

func NewGit(required string) (*Git, error)

func (*Git) Check

func (g *Git) Check(_ context.Context) error

func (*Git) Clean

func (g *Git) Clean(_ context.Context) error

func (*Git) Name

func (g *Git) Name() string

func (*Git) Porcelain

func (g *Git) Porcelain(_ context.Context, files []string) error

func (*Git) Setup

func (g *Git) Setup(_ context.Context) error

func (*Git) Tag

func (g *Git) Tag(_ context.Context) (*Version, error)

type GoMod

type GoMod struct{}

GoMod represents the `go mod` command and all of the logic associated with managing go modules

func (*GoMod) Clean

func (g *GoMod) Clean(_ context.Context, pkg string) error

func (*GoMod) Setup

func (g *GoMod) Setup(_ context.Context) error

func (*GoMod) Tidy

func (g *GoMod) Tidy(_ context.Context) error

type GoTools

type GoTools struct{}

GoTools represents the external tools that we download, install, and use as a part of our build pipelines.

func (*GoTools) Clean

func (g *GoTools) Clean(ctx context.Context) error

func (*GoTools) List

func (g *GoTools) List() ([]string, error)

func (*GoTools) Setup

func (g *GoTools) Setup(ctx context.Context) error

type Golang

type Golang struct {
	Version *semver.Version
	RootPkg string
	Mod     *GoMod
	Tools   *GoTools
}

Golang is a dependency checker for the Go language

func MustGolang

func MustGolang(rootPkg string, required string) *Golang

func NewGolang

func NewGolang(rootPkg string, required string) (*Golang, error)

func (*Golang) Build

func (g *Golang) Build(ctx context.Context, version *Version, pkg, out string) error

Build provides functionality for building a go binary given the pkg path of its main and a output path for the binary.

func (*Golang) Check

func (g *Golang) Check(_ context.Context) error

Check returns an error if Go isn't available or the version is incorrect.

func (*Golang) Clean

func (g *Golang) Clean(ctx context.Context) error

func (*Golang) Name

func (g *Golang) Name() string

Name returns the internal "name" for the dependency

func (*Golang) Setup

func (g *Golang) Setup(ctx context.Context) error

type GraphQL

type GraphQL struct {
	SchemaDir    string
	ConfigPath   string
	GeneratedDir string
}

func NewGraphQL

func NewGraphQL(schemaDir string, configPath string, generatedDir string) (*GraphQL, error)

func (*GraphQL) Generate

func (g *GraphQL) Generate(_ context.Context) error

Generate is responsible for generating all of the code used by gqlgen

type Helm

type Helm struct {
	Version      *semver.Version
	Repositories map[string]string
}

func MustHelm

func MustHelm(required string, repositories map[string]string) *Helm

func NewHelm

func NewHelm(required string, repositories map[string]string) (*Helm, error)

func (*Helm) Check

func (h *Helm) Check(_ context.Context) error

func (*Helm) Clean

func (h *Helm) Clean(_ context.Context) error

func (*Helm) Deploy

func (h *Helm) Deploy(ctx context.Context, c *Chart) error

func (*Helm) Install

func (h *Helm) Install(ctx context.Context, c *Chart) error

func (*Helm) List

func (h *Helm) List(_ context.Context) ([]*Release, error)

func (*Helm) Name

func (h *Helm) Name() string

func (*Helm) RepoUpdate

func (h *Helm) RepoUpdate(_ context.Context) error

func (*Helm) Setup

func (h *Helm) Setup(ctx context.Context) error

func (*Helm) Update

func (h *Helm) Update(ctx context.Context, c *Chart, current *Release) error

type Kind

type Kind struct {
	Version *semver.Version
	// contains filtered or unexported fields
}

Kind represents a dependency on KinD (Kubernetes in Docker) which is used to create and manage our local clusters.

Kind is installed via go.mod and specified as a dependency inside of tools.go

func MustKind

func MustKind(docker *Docker, kubectl *Kubectl, version string) *Kind

func NewKind

func NewKind(docker *Docker, kubectl *Kubectl, version string) (*Kind, error)

func (*Kind) Check

func (k *Kind) Check(ctx context.Context) error

func (*Kind) Clean

func (k *Kind) Clean(_ context.Context) error

func (*Kind) Create

func (k *Kind) Create(ctx context.Context, cluster *Cluster, registry *Registry) error

Create creates a configured KinD cluster with a local docker registry for making docker files available to the kubernetes cluster.

func (*Kind) Destroy

func (k *Kind) Destroy(ctx context.Context, cluster *Cluster) error

func (*Kind) Name

func (k *Kind) Name() string

func (*Kind) Setup

func (k *Kind) Setup(_ context.Context) error

func (*Kind) Status

func (k *Kind) Status(ctx context.Context, cluster *Cluster) (Status, error)

type Kubectl

type Kubectl struct {
	Version *semver.Version
}

func MustKubectl

func MustKubectl(required string) *Kubectl

func NewKubectl

func NewKubectl(required string) (*Kubectl, error)

func (*Kubectl) Check

func (k *Kubectl) Check(_ context.Context) error

type NetworkSettings

type NetworkSettings struct {
	Networks map[string]struct {
		IPAddress string `json:"IPAddress"`
	} `json:"Networks"`
	IPAddress string `json:"IPAddress"`
}

type ParallelFunc

type ParallelFunc func(context.Context) error

type Registry

type Registry struct {
	Name string
	Port string
	Host string
}

Registry represents a docker registry managed and created by the DockerRegistry struct.

type Release

type Release struct {
	Name       string `json:"name"`
	Namespace  string `json:"namespace"`
	Revision   string `json:"revision"`
	Updated    string `json:"updated"`
	Status     string `json:"status"`
	Chart      string `json:"chart"`
	AppVersion string `json:"app_version"`
}

type RunnerFunc

type RunnerFunc func(d Dependency) error

RunnerFunc is a function that performs an actions on a dependency

type Status

type Status string
var (
	Running    Status = "running"
	Created    Status = "created"
	Restarting Status = "restarting"
	Removing   Status = "removing"
	Paused     Status = "paused"
	Exited     Status = "exited"
	Dead       Status = "dead"
	Unknown    Status = "unknown"
)

func ToStatus

func ToStatus(in string) (Status, error)

func (Status) String

func (s Status) String() string

type Version

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

func NewVersion

func NewVersion(in string) (*Version, error)

func (*Version) BuildDate

func (v *Version) BuildDate() string

func (*Version) Version

func (v *Version) Version() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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