Documentation
¶
Overview ¶
Package gcpbuildpack is a framework for implementing buildpacks (https://buildpacks.io/).
Index ¶
- Variables
- func Main(d DetectFn, b BuildFn)
- func TestDetect(t *testing.T, detectFn DetectFn, testName string, files map[string]string, ...)
- func TestDetectWithStack(t *testing.T, detectFn DetectFn, testName string, files map[string]string, ...)
- func WithEnv(env ...string) execOption
- func WithMessageProducer(mp MessageProducer) execOption
- func WithWorkDir(dir string) execOption
- type BuildFn
- type Context
- func (ctx *Context) AddBuildPlanProvides(provided buildplan.Provided)
- func (ctx *Context) AddBuildPlanRequires(required buildplan.Required)
- func (ctx *Context) AddBuildpackPlan(plan buildpackplan.Plan)
- func (ctx *Context) AddWebProcess(cmd []string)
- func (ctx *Context) AppendBuildEnv(l *layers.Layer, name string, format string, args ...interface{})
- func (ctx *Context) AppendLaunchEnv(l *layers.Layer, name string, format string, args ...interface{})
- func (ctx *Context) AppendSharedEnv(l *layers.Layer, name string, format string, args ...interface{})
- func (ctx *Context) ApplicationRoot() string
- func (ctx *Context) BuildpackID() string
- func (ctx *Context) BuildpackName() string
- func (ctx *Context) BuildpackRoot() string
- func (ctx *Context) BuildpackVersion() string
- func (ctx *Context) CacheHit(tag string)
- func (ctx *Context) CacheMiss(tag string)
- func (ctx *Context) ClearLayer(l *layers.Layer)
- func (ctx *Context) CreateFile(file string) *os.File
- func (ctx *Context) Debug() bool
- func (ctx *Context) Debugf(format string, args ...interface{})
- func (ctx *Context) DefaultBuildEnv(l *layers.Layer, name string, format string, args ...interface{})
- func (ctx *Context) DefaultLaunchEnv(l *layers.Layer, name string, format string, args ...interface{})
- func (ctx *Context) DefaultSharedEnv(l *layers.Layer, name string, format string, args ...interface{})
- func (ctx *Context) DelimiterBuildEnv(l *layers.Layer, name string, delimiter string)
- func (ctx *Context) DelimiterLaunchEnv(l *layers.Layer, name string, delimiter string)
- func (ctx *Context) DelimiterSharedEnv(l *layers.Layer, name string, delimiter string)
- func (ctx *Context) Exec(cmd []string, opts ...execOption) *ExecResult
- func (ctx *Context) ExecWithErr(cmd []string, opts ...execOption) (*ExecResult, *Error)
- func (ctx *Context) Exit(exitCode int, be *Error)
- func (ctx *Context) FileExists(elem ...string) bool
- func (ctx *Context) Glob(pattern string) []string
- func (ctx *Context) HTTPStatus(url string) int
- func (ctx *Context) HasAtLeastOne(pattern string) bool
- func (ctx *Context) Layer(name string) *layers.Layer
- func (ctx *Context) Logf(format string, args ...interface{})
- func (ctx *Context) MkdirAll(path string, perm os.FileMode)
- func (ctx *Context) OptIn(format string, args ...interface{})
- func (ctx *Context) OptOut(format string, args ...interface{})
- func (ctx *Context) OverrideBuildEnv(l *layers.Layer, name string, format string, args ...interface{})
- func (ctx *Context) OverrideLaunchEnv(l *layers.Layer, name string, format string, args ...interface{})
- func (ctx *Context) OverrideSharedEnv(l *layers.Layer, name string, format string, args ...interface{})
- func (ctx *Context) PrependBuildEnv(l *layers.Layer, name string, format string, args ...interface{})
- func (ctx *Context) PrependLaunchEnv(l *layers.Layer, name string, format string, args ...interface{})
- func (ctx *Context) PrependPathBuildEnv(l *layers.Layer, name string, format string, args ...interface{})
- func (ctx *Context) PrependPathLaunchEnv(l *layers.Layer, name string, format string, args ...interface{})
- func (ctx *Context) PrependPathSharedEnv(l *layers.Layer, name string, format string, args ...interface{})
- func (ctx *Context) PrependSharedEnv(l *layers.Layer, name string, format string, args ...interface{})
- func (ctx *Context) ReadDir(elem ...string) []os.FileInfo
- func (ctx *Context) ReadFile(filename string) []byte
- func (ctx *Context) ReadMetadata(l *layers.Layer, metadata interface{})
- func (ctx *Context) RemoveAll(elem ...string)
- func (ctx *Context) RemoveMetadata(l *layers.Layer)
- func (ctx *Context) Rename(old, new string)
- func (ctx *Context) SetFunctionsEnvVars(l *layers.Layer)
- func (ctx *Context) Setenv(key, value string)
- func (ctx *Context) Span(label string, start time.Time, status Status)
- func (ctx *Context) Symlink(oldname string, newname string)
- func (ctx *Context) TempDir(dir, prefix string) string
- func (ctx *Context) Tipf(format string, args ...interface{})
- func (ctx *Context) Warnf(format string, args ...interface{})
- func (ctx *Context) WriteFile(filename string, data []byte, perm os.FileMode)
- func (ctx *Context) WriteMetadata(l *layers.Layer, metadata interface{}, flags ...layers.Flag)
- type DetectFn
- type Error
- type ErrorID
- type ExecResult
- type MessageProducer
- type Status
Constants ¶
This section is empty.
Variables ¶
var KeepCombinedHead = func(result *ExecResult) string { return keepHead(result.Combined) }
KeepCombinedHead returns the head of the combined stdout/stderr from the result.
var KeepCombinedTail = func(result *ExecResult) string { return keepTail(result.Combined) }
KeepCombinedTail returns the tail of the combined stdout/stderr from the result.
var KeepStderrHead = func(result *ExecResult) string { return keepHead(result.Stderr) }
KeepStderrHead returns the head of stderr from the result.
var KeepStderrTail = func(result *ExecResult) string { return keepTail(result.Stderr) }
KeepStderrTail returns the tail of stderr from the result.
var KeepStdoutHead = func(result *ExecResult) string { return keepHead(result.Stdout) }
KeepStdoutHead returns the head of stdout from the result.
var KeepStdoutTail = func(result *ExecResult) string { return keepTail(result.Stdout) }
KeepStdoutTail returns the tail of stdout from the result.
var WithCombinedHead = WithMessageProducer(KeepCombinedHead)
WithCombinedHead keeps the head of the combined stdout/stderr for the error message.
var WithCombinedTail = WithMessageProducer(KeepCombinedTail)
WithCombinedTail keeps the tail of the combined stdout/stderr for the error message.
var WithStderrHead = WithMessageProducer(KeepStderrHead)
WithStderrHead keeps the head of stderr for the error message.
var WithStderrTail = WithMessageProducer(KeepStderrTail)
WithStderrTail keeps the tail of stderr for the error message.
var WithStdoutHead = WithMessageProducer(KeepStdoutHead)
WithStdoutHead keeps the head of stdout for the error message.
var WithStdoutTail = WithMessageProducer(KeepStdoutTail)
WithStdoutTail keeps the tail of stdout for the error message.
var WithUserAttribution = func(o *execParams) { o.userFailure = true o.userTiming = true }
WithUserAttribution indicates that failure and timing both are attributed to the user.
var WithUserFailureAttribution = func(o *execParams) { o.userFailure = true }
WithUserFailureAttribution indicates that only failure is attributed to the user.
var WithUserTimingAttribution = func(o *execParams) { o.userTiming = true }
WithUserTimingAttribution indicates that only timing is attributed to the user.
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 Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context provides contextually aware functions for buildpack authors.
func NewContextForTests ¶
NewContextForTests creates a context to be used for tests.
func (*Context) AddBuildPlanProvides ¶
AddBuildPlanProvides adds a provided dependency to the build plan.
func (*Context) AddBuildPlanRequires ¶
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 ¶
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 ¶
ApplicationRoot returns the root folder of the application code.
func (*Context) BuildpackID ¶
BuildpackID returns the buildpack id.
func (*Context) BuildpackName ¶
BuildpackName returns the buildpack name.
func (*Context) BuildpackRoot ¶
BuildpackRoot returns the root folder of the buildpack.
func (*Context) BuildpackVersion ¶
BuildpackVersion returns the buildpack version.
func (*Context) CacheHit ¶
CacheHit records a cache hit debug message. This is used in acceptance test validation.
func (*Context) CacheMiss ¶
CacheMiss records a cache miss debug message. This is used in acceptance test validation.
func (*Context) ClearLayer ¶
ClearLayer erases the existing layer, and re-creates the directory.
func (*Context) CreateFile ¶
CreateFile creates the specified file, return the File object, exiting on any error.
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 ¶
DelimiterBuildEnv sets a delimiter for an environment variable with this value.
func (*Context) DelimiterLaunchEnv ¶
DelimiterLaunchEnv sets a delimiter for an environment variable with this value.
func (*Context) DelimiterSharedEnv ¶
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) FileExists ¶
FileExists returns true if a file exists at the path joined by elem, exiting on any error.
func (*Context) Glob ¶
Glob returns the names of all files matching pattern or nil if there is no matching file, exiting on any error.
func (*Context) HTTPStatus ¶
HTTPStatus returns the status code for a url.
func (*Context) HasAtLeastOne ¶
HasAtLeastOne walks through file tree searching for at least one match.
func (*Context) MkdirAll ¶
MkdirAll creates all necessary directories for the given path, exiting on any error.
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) ReadMetadata ¶
ReadMetadata reads arbitrary layer metadata from the filesystem.
func (*Context) RemoveMetadata ¶
RemoveMetadata remove layer metadata from the filesystem.
func (*Context) SetFunctionsEnvVars ¶
SetFunctionsEnvVars sets launch-time functions environment variables.
func (*Context) Setenv ¶
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) Symlink ¶
Symlink creates newname as a symbolic name to oldname, exiting on any error.
func (*Context) TempDir ¶
TempDir creates a temp directory, returning the directory name. exiting on any error. It is the caller's responsibility to remove the created directory.
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 InternalErrorf ¶
InternalErrorf constructs an Error with status StatusInternal (Google-attributed SLO).
func UserErrorf ¶
UserErrorf constructs an Error with status StatusUnknown (user-attributed SLO).
type ErrorID ¶
type ErrorID string
ErrorID is a short error code passed to the user for supportability.
type ExecResult ¶
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 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 ¶
MarshalJSON marshals the enum as a quoted json string
func (*Status) UnmarshalJSON ¶
UnmarshalJSON unmashals a quoted json string to the enum value