fw

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2020 License: MPL-2.0-no-copyleft-exception Imports: 10 Imported by: 0

Documentation

Overview

Package fw is composed of a framework for designing tinyCI runner agents.

Inside this directory as subdirectories are several packages that cover config files, signals, and other features that are documented and also optional in most cases.

To implement a runner, it must contain a struct that must satisfy the Runner interface. Then, an Entrypoint must be created with metadata about the runner, and the runner struct itself. Then, Run(Entrypoint) needs to be called. The rest of the system will automate the process of:

  • Coordinating and starting your run
  • Managing signals and cancellations
  • Logging certain functionality

What is done outside of these framework needs is largely irrelevant to the framework itself.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(e *Entrypoint) error

Run runs the given Entrypoint, which should contain a Runner to launch as well as other information about the runner. On error you can assume the only safe option is to exit.

At the time of this call, arguments will be parsed. Avoid parsing arguments before this call.

Types

type Entrypoint

type Entrypoint struct {
	// Usage is the way to use the runner application.
	Usage string
	// Description is an extended description of what the runner does and how it works.
	Description string
	// Version is the version of the runner program.
	Version string
	// Author is the author of the runner program.
	Author string
	// Flags are any extra flags you want to handle. We use urfave/cli for managing flags.
	Flags []cli.Flag
	// TeardownTimeout is the amount of time to wait for the runner to tear down
	// everything so it can exit.
	TeardownTimeout time.Duration
	// Launch is the Runner intended to be executed.
	Launch Runner
	// contains filtered or unexported fields
}

Entrypoint is composed of boot-time entities used to start up the application, such as the argument parser and Runner object to enter.

func (*Entrypoint) SetTerminate

func (e *Entrypoint) SetTerminate(log *log.SubLogger)

SetTerminate tells the runner to terminate at the end of the next iteration

type Runner

type Runner interface {

	//
	// Lifecycle hooks
	//
	// Init is the entrypoint of the runner application and will be run shortly
	// after command line arguments are processed.
	Init(*fwcontext.Context) error
	// BeforeRun is executed to set up the run but not actually execute it.
	BeforeRun(*fwcontext.RunContext) error
	// Run is the actual running of the job. Errors from contexts are handled as
	// cancellations. The status (pass/fail) is returned as the primary value.
	Run(*fwcontext.RunContext) (bool, error)

	//
	// Data calls
	//
	// QueueName is the name of the queue to pull runs off of.
	QueueName() string
	// Hostname is the name of the host; a tag to uniquely identify it.
	Hostname() string

	//
	// Client acquisition
	//
	// QueueClient is a client to the queuesvc.
	QueueClient() *queue.Client
	// LogsvcClient is a client to the logsvc.
	LogsvcClient(*fwcontext.RunContext) *log.SubLogger
}

Runner is the interface that a runner must implement to leverage this framework.

type SignalContext

type SignalContext struct {
	// QueueClient is a client to the queuesvc
	QueueClient *queue.Client
	// RunContext is the run context
	RunContext *fwcontext.RunContext

	Ctx context.Context

	Log     *log.SubLogger
	Channel chan os.Signal

	Entrypoint *Entrypoint
}

SignalContext is the context in which the handlers run under; they will be used to store clients as well as data about the run.

Creating a new one of these for each run is a necessity.

func (*SignalContext) HandleCancel

func (sigctx *SignalContext) HandleCancel()

HandleCancel allows the user to program the queuesvc with a cancellation when a signal is received, and simultaneously trigger a cancellation of the run.

To use this function, populate the *Context as described; then call this in a goroutine. Once triggered, it is assuming the daemon is shutting down and will trigger all cancellation behavior in the context.

Directories

Path Synopsis
Package config presents a standard framework-compatible configuration for runners.
Package config presents a standard framework-compatible configuration for runners.
Package git implements functionality to work with git and GitHub.
Package git implements functionality to work with git and GitHub.
Package overlay implements union filesystems via overlayfs for the purposes of keep your source tree clean.
Package overlay implements union filesystems via overlayfs for the purposes of keep your source tree clean.
Package utils contains useful one-off tools for implementing runners.
Package utils contains useful one-off tools for implementing runners.

Jump to

Keyboard shortcuts

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