build

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2022 License: Apache-2.0 Imports: 4 Imported by: 2

Documentation

Overview

Package build defines types and interfaces that could potentially be compiled to various external build-tool scripts but share a general internal abstraction and rules for escaping.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Base added in v0.10.0

type Base struct {
	Image string // image identifier
	Stage string // optional internal name used for multi-stage builds
}

Base is a concrete build instruction for declaring the base container image to start with.

func (Base) Compile added in v0.10.0

func (base Base) Compile() []string

Compile returns the base image and stage name.

type Copy

type Copy struct {
	Sources     []string // source file/directory paths
	Destination string   // destination path
}

Copy is a concrete build instruction for copying source files/directories from the build host into the image.

func (Copy) Compile

func (copy Copy) Compile() []string

Compile quotes the defined source files/directories and destination.

type CopyAs added in v0.3.0

type CopyAs struct {
	UID string // owner UID
	GID string // owner GID
	Instruction
}

CopyAs is a concrete build instruction for copying source files/directories and setting their ownership to the given UID/GID.

While it can technically wrap any build.Instruction, it is meant to be used with build.Copy and build.CopyFrom to enforce file/directory ownership.

func (CopyAs) Compile added in v0.3.0

func (ca CopyAs) Compile() []string

Compile returns the variant name unquoted and all quoted CopyAs instruction fields.

type CopyFrom

type CopyFrom struct {
	From string // source variant name
	Copy
}

CopyFrom is a concrete build instruction for copying source files/directories from one variant image to another.

func (CopyFrom) Compile

func (cf CopyFrom) Compile() []string

Compile returns the variant name unquoted and all quoted Copy instruction fields.

type EntryPoint added in v0.3.0

type EntryPoint struct {
	Command []string // command and arguments
}

EntryPoint is a build instruction for declaring a container's default runtime process.

func (EntryPoint) Compile added in v0.3.0

func (ep EntryPoint) Compile() []string

Compile returns the quoted entrypoint command and arguments.

type Env

type Env struct {
	Definitions map[string]string // number of key/value pairs
}

Env is a concrete build instruction for declaring a container's runtime environment variables.

func Home added in v0.3.0

func Home(name string) Env

Home returns a build.Env instruction for setting the user's home directory.

func (Env) Compile

func (env Env) Compile() []string

Compile returns the key/value pairs as a number of `key="value"` strings where the values are properly quoted and the slice is ordered by the keys.

type Instruction

type Instruction interface {
	Compile() []string
}

Instruction defines a common interface that all concrete build types must implement.

func ApplyUser added in v0.3.0

func ApplyUser(uid string, gid string, instructions []Instruction) []Instruction

ApplyUser wraps any build.Copy instructions as build.CopyAs using the given UID/GID.

type Label

type Label struct {
	Definitions map[string]string // number of meta-data key/value pairs
}

Label is a concrete build instruction for declaring a number of meta-data key/value pairs to be included in the image.

func (Label) Compile

func (label Label) Compile() []string

Compile returns the key/value pairs as a number of `key="value"` strings where the values are properly quoted and the slice is ordered by the keys.

type Phase

type Phase int

Phase enum type

const (
	PhasePrivileged       Phase = iota // first, copies/execution done as root
	PhasePrivilegeDropped              // second, copies/execution done as unprivileged user from here on
	PhasePreInstall                    // third, before application files and artifacts are copied
	PhaseInstall                       // fourth, application files and artifacts are copied
	PhasePostInstall                   // fifth, after application files and artifacts are copied
)

Distinct build phases that each compiler implementation should pass to PhaseCompileable configuration (in the order they are defined here) to allow for dependency injection during compilation.

func Phases added in v0.3.0

func Phases() []Phase

Phases returns all build phases in the order to be compiled.

type PhaseCompileable

type PhaseCompileable interface {
	InstructionsForPhase(phase Phase) []Instruction
}

PhaseCompileable defines and interface that all configuration types should implement if they want to inject build instructions into any of the defined build phases.

type Run

type Run struct {
	Command   string   // command string (e.g. "useradd -d %s -u %s")
	Arguments []string // command arguments both inner and final (e.g. ["/home/user", "123", "user"])
}

Run is a concrete build instruction for passing any number of arguments to a shell command.

The command string may contain inner argument placeholders using the "%s" format verb and will be appended with the quoted values of any arguments that remain after interpolation of the command string.

func Chown added in v0.3.0

func Chown(uid string, gid string, path string) Run

Chown returns a build.Run instruction for setting ownership on the given path.

func CreateDirectories added in v0.5.0

func CreateDirectories(paths []string) Run

CreateDirectories returns a build.Run instruction for creating all the given directories.

func CreateDirectory added in v0.3.0

func CreateDirectory(path string) Run

CreateDirectory returns a build.Run instruction for creating the given directory.

func CreateUser added in v0.3.0

func CreateUser(name string, uid string, gid string) []Run

CreateUser returns build.Run instructions for creating the given user account and group.

func (Run) Compile

func (run Run) Compile() []string

Compile quotes all arguments, interpolates the command string with inner arguments, and appends the final arguments.

type RunAll

type RunAll struct {
	Runs []Run // multiple Run instructions to be executed together
}

RunAll is a concrete build instruction for declaring multiple Run instructions that will be executed together in a `cmd1 && cmd2` chain.

func (RunAll) Compile

func (runAll RunAll) Compile() []string

Compile concatenates all individually compiled Run instructions into a single command.

type ScratchBase added in v0.10.0

type ScratchBase struct {
	Stage string // optional internal name used for multi-stage builds
}

ScratchBase is a concrete build instruction for declaring no base image.

func (ScratchBase) Compile added in v0.10.0

func (sb ScratchBase) Compile() []string

Compile returns the stage name.

type StringArg added in v0.10.0

type StringArg struct {
	Name    string // argument name
	Default string // argument default value
}

StringArg is a build instruction defining a build-time replaceable argument with a string value.

func NewStringArg added in v0.10.0

func NewStringArg(varname string, value string) StringArg

NewStringArg creates an ARG instruction with a string default value.

func (StringArg) Compile added in v0.10.0

func (arg StringArg) Compile() []string

Compile returns the ARG instruction.

type UintArg added in v0.10.0

type UintArg struct {
	Name    string // argument name
	Default uint   // argument default value
}

UintArg is a build instruction defining a build-time replaceable argument with an integer value.

func NewUintArg added in v0.10.0

func NewUintArg(varname string, value uint) UintArg

NewUintArg creates an ARG instruction with a uint default value.

func (UintArg) Compile added in v0.10.0

func (arg UintArg) Compile() []string

Compile returns the ARG instruction.

type User added in v0.3.0

type User struct {
	UID string // user ID
}

User is a build instruction for setting which user will run future commands.

func (User) Compile added in v0.3.0

func (user User) Compile() []string

Compile returns the users UID as string

type WorkingDirectory added in v0.3.0

type WorkingDirectory struct {
	Path string // working directory path
}

WorkingDirectory is a build instruction for defining the working directory for future command and entrypoint instructions.

func (WorkingDirectory) Compile added in v0.3.0

func (wd WorkingDirectory) Compile() []string

Compile returns the quoted working directory path.

Jump to

Keyboard shortcuts

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