forge

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2022 License: MIT Imports: 15 Imported by: 0

README

forge CI

Forge is a library and CLI for running reusable steps from various proprietary CI systems using a pluggable container runtime. This, for example, makes the functionality provided to GitHub Actions easily consumable (or testable) by users of other CI systems.

Forge currently exposes running GitHub Actions (e.g. actions/setup-go) and Concourse Resources (e.g. concourse/git-resource).

install

macOS
brew install frantjc/tap/forge

usage

GitHub Actions

For GitHub Actions, Forge will try to source the GitHub Actions variables from the working directory's Git configuration as well as GitHub's default environment variables.

forge use actions/setup-go@v3 -w go-version=1.19

Forge mounts the current working directory to the Action's GITHUB_WORKSPACE as well as cache directories respecting the XDG Base Directory Specification to the Action's RUNNER_TOOLCACHE and RUNNER_TEMP.

That is to say, after running the above command, go should be installed to $XDG_CACHE_HOME/.forge/runner/toolcache.

You can also use local GitHub Actions by starting the reference with "/" or "./" to signify that it is an absolute or relative local filepath, respectively.

forge use ./testdata/actions/mock
Concourse Resources

For Concourse Resources, Forge will source resource_types and resources from the working directory's forge.yml.

forge get mock -i version=v0.0.0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultDetachKeys are the default key combinations
	// to use when detaching from a Container that has
	// been attached to.
	DefaultDetachKeys = "ctrl-d"
)
View Source
var File_container_config_proto protoreflect.FileDescriptor
View Source
var File_metal_proto protoreflect.FileDescriptor
View Source
var File_mount_proto protoreflect.FileDescriptor
View Source
var (
	// Semver is the semantic version of forge.
	// Meant to be be overridden at build time.
	Semver = "0.0.0"
)

Functions

func GetSemver added in v0.1.0

func GetSemver() string

GetSemver returns the semantic version of Forge as built from Semver and debug build info.

func WithLogger

func WithLogger(ctx context.Context, logger Logger) context.Context

WithLogger returns a Context from the parent Context with the given Logger inside of it.

Types

type Container

Container represents a container created by a ContainerRuntime.

type ContainerConfig

type ContainerConfig struct {
	Entrypoint []string `protobuf:"bytes,1,rep,name=entrypoint,proto3" json:"entrypoint,omitempty"`
	Cmd        []string `protobuf:"bytes,2,rep,name=cmd,proto3" json:"cmd,omitempty"`
	WorkingDir string   `protobuf:"bytes,3,opt,name=working_dir,json=workingDir,proto3" json:"working_dir,omitempty"`
	Env        []string `protobuf:"bytes,4,rep,name=env,proto3" json:"env,omitempty"`
	User       string   `protobuf:"bytes,5,opt,name=user,proto3" json:"user,omitempty"`
	Privileged bool     `protobuf:"varint,6,opt,name=privileged,proto3" json:"privileged,omitempty"`
	Mounts     []*Mount `protobuf:"bytes,7,rep,name=mounts,proto3" json:"mounts,omitempty"`
	// contains filtered or unexported fields
}

func (*ContainerConfig) Descriptor deprecated

func (*ContainerConfig) Descriptor() ([]byte, []int)

Deprecated: Use ContainerConfig.ProtoReflect.Descriptor instead.

func (*ContainerConfig) GetCmd

func (x *ContainerConfig) GetCmd() []string

func (*ContainerConfig) GetEntrypoint

func (x *ContainerConfig) GetEntrypoint() []string

func (*ContainerConfig) GetEnv

func (x *ContainerConfig) GetEnv() []string

func (*ContainerConfig) GetMounts

func (x *ContainerConfig) GetMounts() []*Mount

func (*ContainerConfig) GetPrivileged

func (x *ContainerConfig) GetPrivileged() bool

func (*ContainerConfig) GetUser

func (x *ContainerConfig) GetUser() string

func (*ContainerConfig) GetWorkingDir

func (x *ContainerConfig) GetWorkingDir() string

func (*ContainerConfig) ProtoMessage

func (*ContainerConfig) ProtoMessage()

func (*ContainerConfig) ProtoReflect

func (x *ContainerConfig) ProtoReflect() protoreflect.Message

func (*ContainerConfig) Reset

func (x *ContainerConfig) Reset()

func (*ContainerConfig) String

func (x *ContainerConfig) String() string

type ContainerRuntime

type ContainerRuntime interface {
	GetContainer(context.Context, string) (Container, error)
	CreateContainer(context.Context, Image, *ContainerConfig) (Container, error)
	PullImage(context.Context, string) (Image, error)
	CreateVolume(context.Context, string) (Volume, error)
	Close() error
}

type Drains

type Drains struct {
	Out, Err io.Writer
	Tty      bool
}

Drains represents only outward streams from an Ore, namely stdout and stderr.

func StdDrains

func StdDrains() *Drains

StdDrains returns a Drains draining to os.Stdout and os.Stderr.

func (*Drains) GoString

func (d *Drains) GoString() string

GoString implements fmt.GoStringer.

func (*Drains) ToStreams

func (d *Drains) ToStreams(in io.Reader) *Streams

ToStreams turns a Drains to a Streams for use by Ores to pass to a Container.

type FileDescriptor

type FileDescriptor interface {
	Fd() uintptr
}

FileDescriptor is an interface to check io.Readers and io.Writers against to inspect if they are terminals.

type Foundry

type Foundry struct {
	ContainerRuntime
}

Foundry is a wrapper around a ContainerRuntime for processing Ores.

func NewFoundry

func NewFoundry(containerRuntime ContainerRuntime) *Foundry

NewFoundry returns a Foundry.

func (*Foundry) GoString

func (f *Foundry) GoString() string

GoString implements fmt.GoStringer.

func (*Foundry) Process

func (f *Foundry) Process(ctx context.Context, ore Ore, drains *Drains) (*Metal, error)

Process checks if its Basin already has the result of an Ore. If so, it returns the Metal from the Depoist. Otherwise, it Liquifies the Ore, caches the Metal and returns it.

type Image

type Image interface {
	Manifest() (*imagespecsv1.Manifest, error)
	Digest() (digest.Digest, error)
	Blob() io.Reader
	Name() string
}

Image represents a image pulled by a ContainerRuntime. Used to create Containers from.

type Logger

type Logger = logr.Logger

Logger is an alias to logr.Logger in case the logging library is desired to be swapped out.

func LoggerFrom

func LoggerFrom(ctx context.Context) Logger

LoggerFrom returns a Logger embedded within the given Context or a no-op Logger if no such Logger exists.

func NewLogger

func NewLogger() Logger

NewLogger creates a new Logger.

type Metal

type Metal struct {
	ExitCode int64 `protobuf:"varint,1,opt,name=exit_code,json=exitCode,proto3" json:"exit_code,omitempty"`
	// contains filtered or unexported fields
}

func (*Metal) Descriptor deprecated

func (*Metal) Descriptor() ([]byte, []int)

Deprecated: Use Metal.ProtoReflect.Descriptor instead.

func (*Metal) GetExitCode

func (x *Metal) GetExitCode() int64

func (*Metal) ProtoMessage

func (*Metal) ProtoMessage()

func (*Metal) ProtoReflect

func (x *Metal) ProtoReflect() protoreflect.Message

func (*Metal) Reset

func (x *Metal) Reset()

func (*Metal) String

func (x *Metal) String() string

type Mount

type Mount struct {
	Source      string `protobuf:"bytes,1,opt,name=source,proto3" json:"source,omitempty"`
	Destination string `protobuf:"bytes,2,opt,name=destination,proto3" json:"destination,omitempty"`
	// contains filtered or unexported fields
}

func (*Mount) Descriptor deprecated

func (*Mount) Descriptor() ([]byte, []int)

Deprecated: Use Mount.ProtoReflect.Descriptor instead.

func (*Mount) GetDestination

func (x *Mount) GetDestination() string

func (*Mount) GetSource

func (x *Mount) GetSource() string

func (*Mount) ProtoMessage

func (*Mount) ProtoMessage()

func (*Mount) ProtoReflect

func (x *Mount) ProtoReflect() protoreflect.Message

func (*Mount) Reset

func (x *Mount) Reset()

func (*Mount) String

func (x *Mount) String() string

type Ore

type Ore interface {
	Liquify(context.Context, ContainerRuntime, *Drains) (*Metal, error)
}

Ore represents one or more sequential containerized commands. Ores are meant to represent the entire input to said commands, so that if two Ore's digests match, their resulting Metals should be the same. Because of this, Ores can be cached, using said Digest as the key.

type Streams

type Streams struct {
	*Drains
	In         io.Reader
	DetachKeys string
}

Streams represents streams to and from a process inside of a Container.

func StdStreams

func StdStreams() *Streams

StdStreams returns a Streams consisting of os.Stdin, os.Stdout and os.Stderr.

func StdTerminalStreams

func StdTerminalStreams() (*Streams, func() error)

StdTerminalStreams creates a Streams with os.Stdin, os.Stdout and os.Stderr made raw and a restore function to return them to their previous state. For use with attaching to a shell inside of a Container.

func TerminalStreams

func TerminalStreams(stdin io.Reader, stdout, stderr io.Writer) (*Streams, func() error, error)

TerminalStreams creates a Streams with each of the given streams that is a terminal made raw and a restore function to return them to their previous states. For use with attaching to a shell inside of a Container.

type Volume

type Volume interface {
	GetId() string
	Remove(context.Context) error
}

Volume represents a volume created by a ContainerRuntime which can be attached to a Container via its ContainerConfig.Mounts.

Directories

Path Synopsis
cmd
internal
bin
contaminate
package contaminate contains ways for forge to internally pass state between ores, such as to make sequential ores share a filesystem.
package contaminate contains ways for forge to internally pass state between ores, such as to make sequential ores share a filesystem.
pkg
fn
ore

Jump to

Keyboard shortcuts

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