gcpbuildpack

package
v0.0.0-...-68371d7 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2020 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package gcpbuildpack is a framework for implementing buildpacks (https://buildpacks.io/).

Index

Constants

This section is empty.

Variables

View Source
var KeepCombinedHead = func(result *ExecResult) string { return keepHead(result.Combined) }

KeepCombinedHead returns the head of the combined stdout/stderr from the result.

View Source
var KeepCombinedTail = func(result *ExecResult) string { return keepTail(result.Combined) }

KeepCombinedTail returns the tail of the combined stdout/stderr from the result.

View Source
var KeepStderrHead = func(result *ExecResult) string { return keepHead(result.Stderr) }

KeepStderrHead returns the head of stderr from the result.

View Source
var KeepStderrTail = func(result *ExecResult) string { return keepTail(result.Stderr) }

KeepStderrTail returns the tail of stderr from the result.

View Source
var KeepStdoutHead = func(result *ExecResult) string { return keepHead(result.Stdout) }

KeepStdoutHead returns the head of stdout from the result.

View Source
var KeepStdoutTail = func(result *ExecResult) string { return keepTail(result.Stdout) }

KeepStdoutTail returns the tail of stdout from the result.

WithCombinedHead keeps the head of the combined stdout/stderr for the error message.

WithCombinedTail keeps the tail of the combined stdout/stderr for the error message.

WithStderrHead keeps the head of stderr for the error message.

WithStderrTail keeps the tail of stderr for the error message.

WithStdoutHead keeps the head of stdout for the error message.

WithStdoutTail keeps the tail of stdout for the error message.

View Source
var WithUserAttribution = func(o *execParams) {
	o.userFailure = true
	o.userTiming = true
}

WithUserAttribution indicates that failure and timing both are attributed to the user.

View Source
var WithUserFailureAttribution = func(o *execParams) {
	o.userFailure = true
}

WithUserFailureAttribution indicates that only failure is attributed to the user.

View Source
var WithUserTimingAttribution = func(o *execParams) {
	o.userTiming = true
}

WithUserTimingAttribution indicates that only timing is attributed to the user.

Functions

func Main

func Main(d DetectFn, b BuildFn)

Main is the main entrypoint to a buildpack's detect and build functions.

func TestDetect

func TestDetect(t *testing.T, detectFn DetectFn, testName string, files map[string]string, env []string, want int)

TestDetect is a helper for testing a buildpack's implementation of /bin/detect.

func TestDetectWithStack

func TestDetectWithStack(t *testing.T, detectFn DetectFn, testName string, files map[string]string, env []string, stack string, want int)

TestDetectWithStack is a helper for testing a buildpack's implementation of /bin/detect which allows setting a custom stack name.

func WithEnv

func WithEnv(env ...string) execOption

WithEnv sets environment variables (of the form "KEY=value").

func WithMessageProducer

func WithMessageProducer(mp MessageProducer) execOption

WithMessageProducer sets a custom MessageProducer to produce the error message.

func WithWorkDir

func WithWorkDir(dir string) execOption

WithWorkDir sets a specific working directory.

Types

type BuildFn

type BuildFn func(*Context) error

BuildFn is the callback signature for Build()

type Context

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

Context provides contextually aware functions for buildpack authors.

func NewContext

func NewContext(info buildpack.Info) *Context

NewContext creates a context.

func NewContextForTests

func NewContextForTests(info buildpack.Info, root string) *Context

NewContextForTests creates a context to be used for tests.

func (*Context) AddBuildPlanProvides

func (ctx *Context) AddBuildPlanProvides(provided buildplan.Provided)

AddBuildPlanProvides adds a provided dependency to the build plan.

func (*Context) AddBuildPlanRequires

func (ctx *Context) AddBuildPlanRequires(required buildplan.Required)

AddBuildPlanRequires adds a required dependency to the build plan.

func (*Context) AddBuildpackPlan

func (ctx *Context) AddBuildpackPlan(plan buildpackplan.Plan)

AddBuildpackPlan adds a required dependency to the build plan.

func (*Context) AddWebProcess

func (ctx *Context) AddWebProcess(cmd []string)

AddWebProcess adds the given command as the web start process, overwriting any previous web start process.

func (*Context) AppendBuildEnv

func (ctx *Context) AppendBuildEnv(l *layers.Layer, name string, format string, args ...interface{})

AppendBuildEnv appends the value of this environment variable to any previous declarations of the value without any delimitation. If delimitation is important during concatenation, callers are required to add it.

func (*Context) AppendLaunchEnv

func (ctx *Context) AppendLaunchEnv(l *layers.Layer, name string, format string, args ...interface{})

AppendLaunchEnv appends the value of this environment variable to any previous declarations of the value without any delimitation. If delimitation is important during concatenation, callers are required to add it.

func (*Context) AppendSharedEnv

func (ctx *Context) AppendSharedEnv(l *layers.Layer, name string, format string, args ...interface{})

AppendSharedEnv appends the value of this environment variable to any previous declarations of the value without any delimitation. If delimitation is important during concatenation, callers are required to add it.

func (*Context) ApplicationRoot

func (ctx *Context) ApplicationRoot() string

ApplicationRoot returns the root folder of the application code.

func (*Context) BuildpackID

func (ctx *Context) BuildpackID() string

BuildpackID returns the buildpack id.

func (*Context) BuildpackName

func (ctx *Context) BuildpackName() string

BuildpackName returns the buildpack name.

func (*Context) BuildpackRoot

func (ctx *Context) BuildpackRoot() string

BuildpackRoot returns the root folder of the buildpack.

func (*Context) BuildpackVersion

func (ctx *Context) BuildpackVersion() string

BuildpackVersion returns the buildpack version.

func (*Context) CacheHit

func (ctx *Context) CacheHit(tag string)

CacheHit records a cache hit debug message. This is used in acceptance test validation.

func (*Context) CacheMiss

func (ctx *Context) CacheMiss(tag string)

CacheMiss records a cache miss debug message. This is used in acceptance test validation.

func (*Context) ClearLayer

func (ctx *Context) ClearLayer(l *layers.Layer)

ClearLayer erases the existing layer, and re-creates the directory.

func (*Context) CreateFile

func (ctx *Context) CreateFile(file string) *os.File

CreateFile creates the specified file, return the File object, exiting on any error.

func (*Context) Debug

func (ctx *Context) Debug() bool

Debug returns whether debug mode is enabled.

func (*Context) Debugf

func (ctx *Context) Debugf(format string, args ...interface{})

Debugf emits a structured logging line if the debug flag is set.

func (*Context) DefaultBuildEnv

func (ctx *Context) DefaultBuildEnv(l *layers.Layer, name string, format string, args ...interface{})

DefaultBuildEnv sets a default for an environment variable with this value.

func (*Context) DefaultLaunchEnv

func (ctx *Context) DefaultLaunchEnv(l *layers.Layer, name string, format string, args ...interface{})

DefaultLaunchEnv sets a default for an environment variable with this value.

func (*Context) DefaultSharedEnv

func (ctx *Context) DefaultSharedEnv(l *layers.Layer, name string, format string, args ...interface{})

DefaultSharedEnv sets a default for an environment variable with this value.

func (*Context) DelimiterBuildEnv

func (ctx *Context) DelimiterBuildEnv(l *layers.Layer, name string, delimiter string)

DelimiterBuildEnv sets a delimiter for an environment variable with this value.

func (*Context) DelimiterLaunchEnv

func (ctx *Context) DelimiterLaunchEnv(l *layers.Layer, name string, delimiter string)

DelimiterLaunchEnv sets a delimiter for an environment variable with this value.

func (*Context) DelimiterSharedEnv

func (ctx *Context) DelimiterSharedEnv(l *layers.Layer, name string, delimiter string)

DelimiterSharedEnv sets a delimiter for an environment variable with this value.

func (*Context) Exec

func (ctx *Context) Exec(cmd []string, opts ...execOption) *ExecResult

Exec runs the given command under the default configuration, handling error if present.

func (*Context) ExecWithErr

func (ctx *Context) ExecWithErr(cmd []string, opts ...execOption) (*ExecResult, *Error)

ExecWithErr runs the given command (with args) under the default configuration, allowing the caller to handle the error.

func (*Context) Exit

func (ctx *Context) Exit(exitCode int, be *Error)

Exit causes the buildpack to exit with the given exit code and message.

func (*Context) FileExists

func (ctx *Context) FileExists(elem ...string) bool

FileExists returns true if a file exists at the path joined by elem, exiting on any error.

func (*Context) Glob

func (ctx *Context) Glob(pattern string) []string

Glob returns the names of all files matching pattern or nil if there is no matching file, exiting on any error.

func (*Context) HTTPStatus

func (ctx *Context) HTTPStatus(url string) int

HTTPStatus returns the status code for a url.

func (*Context) HasAtLeastOne

func (ctx *Context) HasAtLeastOne(pattern string) bool

HasAtLeastOne walks through file tree searching for at least one match.

func (*Context) Layer

func (ctx *Context) Layer(name string) *layers.Layer

Layer returns a layer, creating its directory.

func (*Context) Logf

func (ctx *Context) Logf(format string, args ...interface{})

Logf emits a structured logging line.

func (*Context) MkdirAll

func (ctx *Context) MkdirAll(path string, perm os.FileMode)

MkdirAll creates all necessary directories for the given path, exiting on any error.

func (*Context) OptIn

func (ctx *Context) OptIn(format string, args ...interface{})

OptIn is used during the detect phase to opt in to the build process.

func (*Context) OptOut

func (ctx *Context) OptOut(format string, args ...interface{})

OptOut is used during the detect phase to opt out of the build process.

func (*Context) OverrideBuildEnv

func (ctx *Context) OverrideBuildEnv(l *layers.Layer, name string, format string, args ...interface{})

OverrideBuildEnv overrides any existing value for an environment variable with this value.

func (*Context) OverrideLaunchEnv

func (ctx *Context) OverrideLaunchEnv(l *layers.Layer, name string, format string, args ...interface{})

OverrideLaunchEnv overrides any existing value for an environment variable with this value.

func (*Context) OverrideSharedEnv

func (ctx *Context) OverrideSharedEnv(l *layers.Layer, name string, format string, args ...interface{})

OverrideSharedEnv overrides any existing value for an environment variable with this value.

func (*Context) PrependBuildEnv

func (ctx *Context) PrependBuildEnv(l *layers.Layer, name string, format string, args ...interface{})

PrependBuildEnv prepends the value of this environment variable to any previous declarations of the value without any delimitation. If delimitation is important during concatenation, callers are required to add it.

func (*Context) PrependLaunchEnv

func (ctx *Context) PrependLaunchEnv(l *layers.Layer, name string, format string, args ...interface{})

PrependLaunchEnv prepends the value of this environment variable to any previous declarations of the value without any delimitation. If delimitation is important during concatenation, callers are required to add it.

func (*Context) PrependPathBuildEnv

func (ctx *Context) PrependPathBuildEnv(l *layers.Layer, name string, format string, args ...interface{})

PrependPathBuildEnv prepends the value of this environment variable to any previous declarations of the value using the OS path delimiter.

func (*Context) PrependPathLaunchEnv

func (ctx *Context) PrependPathLaunchEnv(l *layers.Layer, name string, format string, args ...interface{})

PrependPathLaunchEnv prepends the value of this environment variable to any previous declarations of the value using the OS path delimiter.

func (*Context) PrependPathSharedEnv

func (ctx *Context) PrependPathSharedEnv(l *layers.Layer, name string, format string, args ...interface{})

PrependPathSharedEnv prepends the value of this environment variable to any previous declarations of the value using the OS path delimiter.

func (*Context) PrependSharedEnv

func (ctx *Context) PrependSharedEnv(l *layers.Layer, name string, format string, args ...interface{})

PrependSharedEnv prepends the value of this environment variable to any previous declarations of the value without any delimitation. If delimitation is important during concatenation, callers are required to add it.

func (*Context) ReadDir

func (ctx *Context) ReadDir(elem ...string) []os.FileInfo

ReadDir invokes ioutil.ReadDir, exiting on any error.

func (*Context) ReadFile

func (ctx *Context) ReadFile(filename string) []byte

ReadFile invokes ioutil.ReadFile, exiting on any error.

func (*Context) ReadMetadata

func (ctx *Context) ReadMetadata(l *layers.Layer, metadata interface{})

ReadMetadata reads arbitrary layer metadata from the filesystem.

func (*Context) RemoveAll

func (ctx *Context) RemoveAll(elem ...string)

RemoveAll removes the given path, exiting on any error.

func (*Context) RemoveMetadata

func (ctx *Context) RemoveMetadata(l *layers.Layer)

RemoveMetadata remove layer metadata from the filesystem.

func (*Context) Rename

func (ctx *Context) Rename(old, new string)

Rename renames the old path to the new path, exiting on any error.

func (*Context) SetFunctionsEnvVars

func (ctx *Context) SetFunctionsEnvVars(l *layers.Layer)

SetFunctionsEnvVars sets launch-time functions environment variables.

func (*Context) Setenv

func (ctx *Context) Setenv(key, value string)

Setenv immediately sets an environment variable, exiting on any error. Note: this only sets an env var for the current script invocation. If you need an env var that persists through the build environment or the launch environment, use ctx.PrependBuildEnv,...

func (*Context) Span

func (ctx *Context) Span(label string, start time.Time, status Status)

Span emits a structured Stackdriver span.

func (ctx *Context) Symlink(oldname string, newname string)

Symlink creates newname as a symbolic name to oldname, exiting on any error.

func (*Context) TempDir

func (ctx *Context) TempDir(dir, prefix string) string

TempDir creates a temp directory, returning the directory name. exiting on any error. It is the caller's responsibility to remove the created directory.

func (*Context) Tipf

func (ctx *Context) Tipf(format string, args ...interface{})

Tipf emits a structured logging line for usage tips.

func (*Context) Warnf

func (ctx *Context) Warnf(format string, args ...interface{})

Warnf emits a structured logging line for warnings.

func (*Context) WriteFile

func (ctx *Context) WriteFile(filename string, data []byte, perm os.FileMode)

WriteFile invokes ioutil.WriteFile, exiting on any error.

func (*Context) WriteMetadata

func (ctx *Context) WriteMetadata(l *layers.Layer, metadata interface{}, flags ...layers.Flag)

WriteMetadata writes arbitrary layer metadata to the filesystem.

type DetectFn

type DetectFn func(*Context) error

DetectFn is the callback signature for Detect()

type Error

type Error struct {
	BuildpackID      string  `json:"buildpackId"`
	BuildpackVersion string  `json:"buildpackVersion"`
	Type             Status  `json:"errorType"`
	Status           Status  `json:"canonicalCode"`
	ID               ErrorID `json:"errorId"`
	Message          string  `json:"errorMessage"`
}

Error is a gcpbuildpack structured error.

func Errorf

func Errorf(status Status, format string, args ...interface{}) *Error

Errorf constructs an Error.

func InternalErrorf

func InternalErrorf(format string, args ...interface{}) *Error

InternalErrorf constructs an Error with status StatusInternal (Google-attributed SLO).

func UserErrorf

func UserErrorf(format string, args ...interface{}) *Error

UserErrorf constructs an Error with status StatusUnknown (user-attributed SLO).

func (*Error) Error

func (e *Error) Error() string

type ErrorID

type ErrorID string

ErrorID is a short error code passed to the user for supportability.

type ExecResult

type ExecResult struct {
	ExitCode int
	Stdout   string
	Stderr   string
	Combined string
}

ExecResult bundles exec results.

type MessageProducer

type MessageProducer func(result *ExecResult) string

MessageProducer is a function that produces a useful message from the result.

type Status

type Status int

Status is the standard Google API status.

const (
	StatusOk                 Status = 0
	StatusCancelled          Status = 1
	StatusUnknown            Status = 2
	StatusInvalidArgument    Status = 3
	StatusDeadlineExceeded   Status = 4
	StatusNotFound           Status = 5
	StatusAlreadyExists      Status = 6
	StatusPermissionDenied   Status = 7
	StatusResourceExhausted  Status = 8
	StatusFailedPrecondition Status = 9
	StatusAborted            Status = 10
	StatusOutOfRange         Status = 11
	StatusUnimplemented      Status = 12
	StatusInternal           Status = 13 // Google-attributed error
	StatusUnavailable        Status = 14
	StatusDataLoss           Status = 15
	StatusUnauthenticated    Status = 16
)

Statuses matching https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto All error status are attributed to the user, except for those denoted.

func (Status) MarshalJSON

func (s Status) MarshalJSON() ([]byte, error)

MarshalJSON marshals the enum as a quoted json string

func (Status) String

func (s Status) String() string

func (*Status) UnmarshalJSON

func (s *Status) UnmarshalJSON(b []byte) error

UnmarshalJSON unmashals a quoted json string to the enum value

Jump to

Keyboard shortcuts

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