forge

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2025 License: MIT Imports: 27 Imported by: 0

README

forge CI godoc goreportcard

Have you ever had to swap to using a new CI system? Twice? Three times? Done with searching for a replacement for each Action, CloudBuilder or resource that you were using in your old one? Tired of waiting minutes for feedback on each iteration of figuring out the quirks of your new one?

Forge is here to help.

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.

Learn more.

Documentation

Index

Constants

View Source
const (
	DefaultNode10ImageReference = "docker.io/library/node:10"
	DefaultNode12ImageReference = "docker.io/library/node:12"
	DefaultNode16ImageReference = "docker.io/library/node:16"
	DefaultNode20ImageReference = "docker.io/library/node:20"
	DefaultNodeImageReference   = DefaultNode16ImageReference
)
View Source
const DefaultDetachKeys = "ctrl-d"

DefaultDetachKeys are the default key combinations to use when detaching from a Container that has been attached to.

Variables

View Source
var (
	ShimName   = "shim"
	ScriptName = "script"
)
View Source
var (
	// ErrContainerExecutedWithNonzeroExitCode is returned when a container
	// returns an unexpected nonzero exit code. Used with errors.Is to avoid
	// printing this error's text so that os.Exit doesn't double-inform a user
	// of the same nonzero exit code.
	ErrContainerExitedWithNonzeroExitCode = errors.New("container exited with nonzero exit code")
	// ErrCannotBuildDockerfile will be returned when a forge.ContainerRuntime
	// does not implement ImageBuilder.
	ErrCannotBuildDockerfile = errors.New("runtime cannot build Dockerfile")
)
View Source
var (
	Node10ImageReference = DefaultNode10ImageReference
	Node12ImageReference = DefaultNode12ImageReference
	Node16ImageReference = DefaultNode16ImageReference
	Node20ImageReference = DefaultNode20ImageReference
	NodeImageReference   = DefaultNodeImageReference
)
View Source
var HookContainerStarted = new(Hook[Container])

Functions

func AzureDevOpsTaskWorkingDir added in v1.0.0

func AzureDevOpsTaskWorkingDir(workingDir string) string

func CloudBuildWorkingDir added in v1.0.0

func CloudBuildWorkingDir(workingDir string) string

func ConcourseResourceWorkingDir added in v1.0.0

func ConcourseResourceWorkingDir(workingDir string) string

func GitHubActionPath added in v1.0.0

func GitHubActionPath(workingDir string) string

func GitHubEnv added in v1.0.0

func GitHubEnv(workingDir string) string

func GitHubOutput added in v1.0.0

func GitHubOutput(workingDir string) string

func GitHubPath added in v1.0.0

func GitHubPath(workingDir string) string

func GitHubRunnerTmp added in v1.0.0

func GitHubRunnerTmp(workingDir string) string

func GitHubRunnerToolCache added in v1.0.0

func GitHubRunnerToolCache(workingDir string) string

func GitHubState added in v1.0.0

func GitHubState(workingDir string) string

func GitHubWorkspace added in v1.0.0

func GitHubWorkspace(workingDir string) string

func InterceptingDockerSock added in v1.0.0

func InterceptingDockerSock(workingDir string) string

Types

type Action added in v1.0.0

type Action struct {
	ID            string
	Uses          string
	With          map[string]string
	Env           map[string]string
	GlobalContext *githubactions.GlobalContext
}

func (*Action) Run added in v1.0.0

func (o *Action) Run(ctx context.Context, containerRuntime ContainerRuntime, opts ...RunOpt) error

type CloudBuild added in v1.0.0

type CloudBuild struct {
	cloudbuild.Step
}

func (*CloudBuild) Run added in v1.0.0

func (o *CloudBuild) Run(ctx context.Context, containerRuntime ContainerRuntime, opts ...RunOpt) error

type Container

Container represents a container created by a ContainerRuntime.

type ContainerConfig

type ContainerConfig struct {
	Entrypoint []string
	Cmd        []string
	WorkingDir string
	Env        []string
	User       string
	Privileged bool
	Mounts     []Mount
}

ContainerConfig is the configuration that is used to create a container or an exec in a running container.

type ContainerRuntime

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

ContainerRuntime represents the functionality needed by Runnables to pull OCI images and run containers when being processed.

type Hook added in v1.0.0

type Hook[T any] struct {
	Listeners []func(context.Context, T)
	sync.Mutex
}

func (*Hook[T]) Dispatch added in v1.0.0

func (h *Hook[T]) Dispatch(ctx context.Context, t T)

func (*Hook[T]) Listen added in v1.0.0

func (h *Hook[T]) Listen(f ...func(context.Context, T))

type Image

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

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

type ImageBuilder added in v1.0.0

type ImageBuilder interface {
	BuildDockerfile(context.Context, string, string) (Image, error)
}

ImageBuilder is for a ContainerRuntime to implement building a Dockerfile. Because building an OCI image is not ubiquitous, forge.ContainerRuntimes are not required to implement this, but they may. The default runtime (Docker) happens to so as to support GitHub Actions that run using "docker".

type Mount

type Mount struct {
	Source      string `json:"source,omitempty"`
	Destination string `json:"destination,omitempty"`
}

type Pipe added in v1.0.0

type Pipe struct {
	From Runnable
	To   Runnable
}

func (*Pipe) Run added in v1.0.0

func (o *Pipe) Run(ctx context.Context, containerRuntime ContainerRuntime, opts ...RunOpt) (err error)

type Pure added in v1.0.0

type Pure struct {
	Image      string
	Entrypoint []string
	Cmd        []string
	Env        []string
}

func (*Pure) Run added in v1.0.0

func (o *Pure) Run(ctx context.Context, containerRuntime ContainerRuntime, opts ...RunOpt) error

type Resource added in v1.0.0

type Resource struct {
	Method       string
	Version      map[string]any
	Params       map[string]any
	Resource     *concourse.Resource
	ResourceType *concourse.ResourceType
}

func (*Resource) Run added in v1.0.0

func (o *Resource) Run(ctx context.Context, containerRuntime ContainerRuntime, opts ...RunOpt) error

type RunOpt added in v1.0.0

type RunOpt interface {
	Apply(*RunOpts)
}

func WithStdStreams added in v1.0.0

func WithStdStreams() RunOpt

func WithStreams added in v1.0.0

func WithStreams(streams *Streams) RunOpt

type RunOpts added in v1.0.0

type RunOpts struct {
	Streams             *Streams
	Mounts              []Mount
	InterceptDockerSock bool
	WorkingDir          string
}

func (*RunOpts) Apply added in v1.0.0

func (o *RunOpts) Apply(opts *RunOpts)

type Runnable added in v1.0.0

type Runnable interface {
	Run(context.Context, ContainerRuntime, ...RunOpt) error
}

type SleepingShimContainer added in v1.0.0

type SleepingShimContainer struct {
	Container
	WorkingDir          string
	InterceptDockerSock bool
}

func (*SleepingShimContainer) Exec added in v1.0.0

type Streams

type Streams struct {
	In         io.Reader
	Out        io.Writer
	Err        io.Writer
	Tty        bool
	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 Task added in v1.0.0

type Task struct {
	Task      string
	Inputs    map[string]string
	Execution string
}

func (*Task) Run added in v1.0.0

func (o *Task) Run(ctx context.Context, containerRuntime ContainerRuntime, opts ...RunOpt) error

Directories

Path Synopsis
package cloudbuild contains types compatible with the data structures in Google CloudBuild build config file schema as well as commonly used filepaths and environment variables.
package cloudbuild contains types compatible with the data structures in Google CloudBuild build config file schema as well as commonly used filepaths and environment variables.
cmd
package command exports functions that return (*github.com/spf13/cobra.Command)s which act as the entrypoint to `forge` and its subcommands.
package command exports functions that return (*github.com/spf13/cobra.Command)s which act as the entrypoint to `forge` and its subcommands.
package concourse contains types compatible with the data structures in Concourse such as its pipeline schema and the inputs and outputs to and from Concourse Resources.
package concourse contains types compatible with the data structures in Concourse such as its pipeline schema and the inputs and outputs to and from Concourse Resources.
package envconv contains functionality for converting between data types commonly used to represent environment variables i.e.
package envconv contains functionality for converting between data types commonly used to represent environment variables i.e.
package githubactions contains types compatible with the data structures in GitHub Actions such as a GitHub Actions Workflow Step; common environment variables; parsing of $GITHUB_PATH files, $GITHUB_ENV files, and GitHub Actions Workflow commands; downloading GitHub Actions, and more.
package githubactions contains types compatible with the data structures in GitHub Actions such as a GitHub Actions Workflow Step; common environment variables; parsing of $GITHUB_PATH files, $GITHUB_ENV files, and GitHub Actions Workflow commands; downloading GitHub Actions, and more.
internal
bin
package rangemap provides functions to range over a map in an order sorted by its orderable keys.
package rangemap provides functions to range over a map in an order sorted by its orderable keys.
runtime
docker
package docker provides an implementation of github.com/frantjc/forge.ContainerRuntime by interacting with a Docker daemon via a *github.com/docker/docker/client.Client.
package docker provides an implementation of github.com/frantjc/forge.ContainerRuntime by interacting with a Docker daemon via a *github.com/docker/docker/client.Client.

Jump to

Keyboard shortcuts

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