Documentation
¶
Overview ¶
build := func(context packit.BuildContext) (packit.BuildResult, error) { return packit.BuildResult{ Processes: []packit.Process{ { Type: "web", Command: `while true; do nc -l -p $PORT -c 'echo -e "HTTP/1.1 200 OK\n\n Hello, world!\n"'; done`, }, }, }, nil } packit.Run(detect, build) }
Summary ¶
These examples show the very basics of what a buildpack implementation using packit might entail. For more details, please consult the documentation of the types and functions declared herein.
Index ¶
- Variables
- func Build(f BuildFunc, options ...Option)
- func Detect(f DetectFunc, options ...Option)
- func Run(detect DetectFunc, build BuildFunc, options ...Option)
- type BuildContext
- type BuildFunc
- type BuildPlan
- type BuildPlanProvision
- type BuildPlanRequirement
- type BuildResult
- type BuildpackInfo
- type BuildpackPlan
- type BuildpackPlanEntry
- type DetectContext
- type DetectFunc
- type DetectResult
- type Environment
- type EnvironmentWriter
- type ExitHandler
- type Layer
- type LayerType
- type Layers
- type Option
- type OptionConfig
- type Process
- type TOMLWriter
Constants ¶
This section is empty.
Variables ¶
var Fail = internal.Fail
Fail is a sentinal value that can be used to indicate a failure to detect during the detect phase. Fail implements the Error interface and should be returned as the error value in the DetectFunc signature.
Functions ¶
func Build ¶
Build is an implementation of the build phase according to the Cloud Native Buildpacks specification. Calling this function with a BuildFunc will perform the build phase process.
func Detect ¶
func Detect(f DetectFunc, options ...Option)
Detect is an implementation of the detect phase according to the Cloud Native Buildpacks specification. Calling this function with a DetectFunc will perform the detect phase process.
func Run ¶ added in v0.0.10
func Run(detect DetectFunc, build BuildFunc, options ...Option)
Run combines the invocation of both build and detect into a single entry point. Calling Run from an executable with a name matching "build" or "detect" will result in the matching DetectFunc or BuildFunc being called.
Types ¶
type BuildContext ¶
type BuildContext struct { // BuildpackInfo includes the details of the buildpack parsed from the // buildpack.toml included in the buildpack contents. BuildpackInfo BuildpackInfo // CNBPath is the absolute path location of the buildpack contents. // This path is useful for finding the buildpack.toml or any other // files included in the buildpack. CNBPath string // Layers provides access to layers managed by the buildpack. It can be used // to create new layers or retrieve cached layers from previous builds. Layers Layers // Plan includes the BuildpackPlan provided by the lifecycle as specified in // the specification: // https://github.com/buildpacks/spec/blob/master/buildpack.md#buildpack-plan-toml. Plan BuildpackPlan // Stack is the value of the chosen stack. This value is populated from the // $CNB_STACK_ID environment variable. Stack string // WorkingDir is the location of the application source code as provided by // the lifecycle. WorkingDir string }
BuildContext provides the contextual details that are made available by the buildpack lifecycle during the build phase. This context is populated by the Build function and passed to BuildFunc during execution.
type BuildFunc ¶
type BuildFunc func(BuildContext) (BuildResult, error)
BuildFunc is the definition of a callback that can be invoked when the Build function is executed. Buildpack authors should implement a BuildFunc that performs the specific build phase operations for a buildpack.
type BuildPlan ¶
type BuildPlan struct { // Provides is a list of BuildPlanProvisions that are provided by this // buildpack. Provides []BuildPlanProvision `toml:"provides"` // Requires is a list of BuildPlanRequirements that are required by this // buildpack. Requires []BuildPlanRequirement `toml:"requires"` // Or is a list of additional BuildPlans that may be selected by the // lifecycle Or []BuildPlan `toml:"or,omitempty"` }
BuildPlan is a representation of the Build Plan as specified in the specification: https://github.com/buildpacks/spec/blob/master/buildpack.md#build-plan-toml. The BuildPlan allows buildpacks to indicate what dependencies they provide or require.
type BuildPlanProvision ¶
type BuildPlanProvision struct { // Name is the identifier whereby buildpacks can coordinate that a dependency // is provided or required. Name string `toml:"name"` }
BuildPlanProvision is a representation of a dependency that can be provided by a buildpack.
type BuildPlanRequirement ¶
type BuildPlanRequirement struct { // Name is the identifier whereby buildpacks can coordinate that a dependency // is provided or required. Name string `toml:"name"` // Version allows a requirement to include a constraint describing what // versions of the dependency are considered acceptable. Version string `toml:"version"` // Metadata is an unspecified field allowing buildpacks to communicate extra // details about their requirement. Examples of this type of metadata might // include details about what source was used to decide the Version // constraint for a requirement. Metadata interface{} `toml:"metadata"` }
type BuildResult ¶
type BuildResult struct { // Plan is the set of refinements to the Buildpack Plan that were performed // during the build phase. Plan BuildpackPlan // Layers is a list of layers that will be persisted by the lifecycle at the // end of the build phase. Layers not included in this list will not be made // available to the lifecycle. Layers []Layer // Processes is a list of processes that will be returned to the lifecycle to // be executed during the launch phase. Processes []Process }
BuildResult allows buildpack authors to indicate the result of the build phase for a given buildpack. This result, returned in a BuildFunc callback, will be parsed and persisted by the Build function and returned to the lifecycle at the end of the build phase execution.
type BuildpackInfo ¶
type BuildpackInfo struct { // ID is the identifier specified in the `buildpack.id` field of the buildpack.toml. ID string `toml:"id"` // Name is the identifier specified in the `buildpack.name` field of the buildpack.toml. Name string `toml:"name"` // Version is the identifier specified in the `buildpack.version` field of the buildpack.toml. Version string `toml:"version"` }
BuildpackInfo is a representation of the basic information for a buildpack provided in its buildpack.toml file as described in the specification: https://github.com/buildpacks/spec/blob/master/buildpack.md#buildpacktoml-toml.
type BuildpackPlan ¶
type BuildpackPlan struct { // Entries is a list of BuildpackPlanEntry fields that are declared in the // buildpack plan TOML file. Entries []BuildpackPlanEntry `toml:"entries"` }
BuildpackPlan is a representation of the buildpack plan provided by the lifecycle and defined in the specification: https://github.com/buildpacks/spec/blob/master/buildpack.md#buildpack-plan-toml. It is also used to return a set of refinements to the plan at the end of the build phase.
type BuildpackPlanEntry ¶
type BuildpackPlanEntry struct { // Name is the name of the dependency the the buildpack should provide. Name string `toml:"name"` // Version if the version contraint that defines what would be an acceptable // dependency provided by the buildpack. Version string `toml:"version"` // Metadata is an unspecified field allowing buildpacks to communicate extra // details about their requirement. Examples of this type of metadata might // include details about what source was used to decide the Version // constraint for a requirement. Metadata map[string]interface{} `toml:"metadata"` }
BuildpackPlanEntry is a representation of a single buildpack plan entry specified by the lifecycle.
type DetectContext ¶
type DetectContext struct { // WorkingDir is the location of the application source code as provided by // the lifecycle. WorkingDir string // CNBPath is the absolute path location of the buildpack contents. // This path is useful for finding the buildpack.toml or any other // files included in the buildpack. CNBPath string // BuildpackInfo includes the details of the buildpack parsed from the // buildpack.toml included in the buildpack contents. BuildpackInfo BuildpackInfo }
DetectContext provides the contextual details that are made available by the buildpack lifecycle during the detect phase. This context is populated by the Detect function and passed to the DetectFunc during execution.
type DetectFunc ¶
type DetectFunc func(DetectContext) (DetectResult, error)
DetectFunc is the definition of a callback that can be invoked when the Detect function is executed. Buildpack authors should implement a DetectFunc that performs the specific detect phase operations for a buildpack.
type DetectResult ¶
type DetectResult struct { // Plan is the set of Build Plan provisions and requirements that are // detected during the detect phase of the lifecycle. Plan BuildPlan }
DetectResult allows buildpack authors to indicate the result of the detect phase for a given buildpack. This result, returned in a DetectFunc callback, will be parsed and persisted by the Detect function and returned to the lifecycle at the end of the detect phase execution.
type Environment ¶
Environment provides a key-value store for declaring environment variables.
func (Environment) Append ¶
func (e Environment) Append(name, value, delim string)
Append adds a key-value pair to the environment as an appended value according to the specification: https://github.com/buildpacks/spec/blob/master/buildpack.md#append.
func (Environment) Default ¶
func (e Environment) Default(name, value string)
Default adds a key-value pair to the environment as a default value according to the specification: https://github.com/buildpacks/spec/blob/master/buildpack.md#default.
func (Environment) Override ¶
func (e Environment) Override(name, value string)
Override adds a key-value pair to the environment as an overridden value according to the specification: https://github.com/buildpacks/spec/blob/master/buildpack.md#override.
func (Environment) Prepend ¶
func (e Environment) Prepend(name, value, delim string)
Prepend adds a key-value pair to the environment as a prepended value according to the specification: https://github.com/buildpacks/spec/blob/master/buildpack.md#prepend.
type EnvironmentWriter ¶
EnvironmentWriter serves as the interface for types that can write an Environment to a directory on disk according to the specification: https://github.com/buildpacks/spec/blob/master/buildpack.md#provided-by-the-buildpacks.
type ExitHandler ¶
type ExitHandler interface {
Error(error)
}
ExitHandler serves as the interface for types that can handle an error during the Detect or Build functions. ExitHandlers are responsible for translating error values into exit codes according the specification: https://github.com/buildpacks/spec/blob/master/buildpack.md#detection and https://github.com/buildpacks/spec/blob/master/buildpack.md#build.
type Layer ¶
type Layer struct { // Path is the absolute location of the layer on disk. Path string `toml:"-"` // Name is the descriptive name of the layer. Name string `toml:"-"` // Build indicates whether the layer is available to subsequent buildpacks // during their build phase according to the specification: // https://github.com/buildpacks/spec/blob/master/buildpack.md#build-layers. Build bool `toml:"build"` // Launch indicates whether the layer is exported into the application image // and made available during the launch phase according to the specification: // https://github.com/buildpacks/spec/blob/master/buildpack.md#launch-layers. Launch bool `toml:"launch"` // Cache indicates whether the layer is persisted and made available to // subsequent builds of the same application according to the specification: // https://github.com/buildpacks/spec/blob/master/buildpack.md#launch-layers // and // https://github.com/buildpacks/spec/blob/master/buildpack.md#build-layers. Cache bool `toml:"cache"` // made available during both the build and launch phases according to the // specification: // https://github.com/buildpacks/spec/blob/master/buildpack.md#provided-by-the-buildpacks. SharedEnv Environment `toml:"-"` // BuildEnv is the set of environment variables attached to the layer and // made available during the build phase according to the specification: // https://github.com/buildpacks/spec/blob/master/buildpack.md#provided-by-the-buildpacks. BuildEnv Environment `toml:"-"` // LaunchEnv is the set of environment variables attached to the layer and // made available during the launch phase according to the specification: // https://github.com/buildpacks/spec/blob/master/buildpack.md#provided-by-the-buildpacks. LaunchEnv Environment `toml:"-"` // Metadata is an unspecified field allowing buildpacks to communicate extra // details about the layer. Examples of this type of metadata might include // details about what versions of software are included in the layer such // that subsequent builds can inspect that metadata and choose to reuse the // layer if suitable. The Metadata field ultimately fills the metadata field // of the Layer Content Metadata TOML file according to the specification: // https://github.com/buildpacks/spec/blob/master/buildpack.md#layer-content-metadata-toml. Metadata map[string]interface{} `toml:"metadata"` }
Layer provides a representation of a layer managed by a buildpack as described by the specification: https://github.com/buildpacks/spec/blob/master/buildpack.md#layers.
type LayerType ¶
type LayerType uint8
LayerType defines the set of layer types that can be declared according to the specification: https://github.com/buildpacks/spec/blob/master/buildpack.md#layer-types.
const ( // BuildLayer indicates that the layer will be made available during the // build phase. BuildLayer LayerType = iota // LaunchLayer indicates that the layer will be made available during the // launch phase. LaunchLayer // CacheLayer indicates that the layer will be cached and made available to // the buildpack on subsequent rebuilds. CacheLayer )
type Layers ¶
type Layers struct { // Path is the absolute location of the set of layers managed by a buildpack // on disk. Path string }
Layers represents the set of layers managed by a buildpack.
type Option ¶
type Option func(config OptionConfig) OptionConfig
Option declares a function signature that can be used to define optional modifications to the behavior of the Detect and Build functions.
func WithArgs ¶
WithArgs is an Option that overrides the value of os.Args for a given invocation of Build or Detect.
func WithExitHandler ¶
func WithExitHandler(exitHandler ExitHandler) Option
WithExitHandler is an Option that overrides the ExitHandler for a given invocation of Build or Detect.
type OptionConfig ¶
type OptionConfig struct {
// contains filtered or unexported fields
}
OptionConfig is the set of configurable options for the Build and Detect functions.
type Process ¶
type Process struct { // Type is an identifier to describe the type of process to be executed, eg. // "web". Type string `toml:"type"` // Command is the start command to be executed at launch. Command string `toml:"command"` // Args is a list of arguments to be passed to the command at launch. Args []string `toml:"args"` // Direct indicates whether the process should bypass the shell when invoked. Direct bool `toml:"direct"` }
Process represents a process to be run during the launch phase as described in the specification: https://github.com/buildpacks/spec/blob/master/buildpack.md#launch. The fields of the process are describe in the specification of the launch.toml file: https://github.com/buildpacks/spec/blob/master/buildpack.md#launchtoml-toml.
type TOMLWriter ¶
TOMLWriter serves as the interface for types that can handle the writing of TOML files. TOMLWriters take a path to a file location on disk and a datastructure to marshal.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package fs provides a set of filesystem helpers that can be useful when developing Cloud Native Buildpacks.
|
Package fs provides a set of filesystem helpers that can be useful when developing Cloud Native Buildpacks. |
Package pexec provides a mechanism for invoking a program executable with a varying set of arguments.
|
Package pexec provides a mechanism for invoking a program executable with a varying set of arguments. |
Package postal provides a service for resolving and installing dependencies for a buildpack.
|
Package postal provides a service for resolving and installing dependencies for a buildpack. |