libcnb

package module
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2020 License: Apache-2.0 Imports: 8 Imported by: 220

README

libcnb

libcnb is a Go language binding of the Cloud Native Buildpack API. It is a non-opinionated implementation adding language constructs and convenience methods for working with the API.

Usage

go get github.com/buildpacks/libcnb

License

This library is released under version 2.0 of the Apache License.

Documentation

Index

Constants

View Source
const (
	// BindingKind is the metadata key for a binding's kind.
	BindingKind = "kind"

	// BindingProvider is the metadata key for a binding's provider.
	BindingProvider = "provider"

	// BindingTags is the metadata key for a binding's tags.
	BindingTags = "tags"
)

Variables

This section is empty.

Functions

func Build

func Build(builder Builder, options ...Option)

Build is called by the main function of a buildpack, for build.

func Detect

func Detect(detector Detector, options ...Option)

Detect is called by the main function of a buildpack, for detection.

Types

type Application added in v1.1.0

type Application struct {

	// Path is the path to the application.
	Path string
}

Application is the user contributed application to build.

type ApplicationPathFormatter

type ApplicationPathFormatter string

ApplicationPathFormatter is the formatter for an ApplicationPath.

func (ApplicationPathFormatter) String

func (a ApplicationPathFormatter) String() string

type Binding

type Binding struct {

	// Name is the name of the binding
	Name string

	// Metadata is the metadata of the binding.
	Metadata map[string]string

	// Secrete is the secret of the binding.
	Secret map[string]string
}

Binding is a projection of metadata about an external entity to be bound to.

func NewBinding

func NewBinding(name string) Binding

NewBinding creates a new Binding initialized with no metadata or secret.

func NewBindingFromPath

func NewBindingFromPath(path string) (Binding, error)

NewBindingFromPath creates a new binding from the files located at a path.

func (Binding) Kind added in v1.5.0

func (b Binding) Kind() string

Kind returns the kind of the binding.

func (Binding) Provider added in v1.5.0

func (b Binding) Provider() string

Provider returns the provider of the binding.

func (Binding) String

func (b Binding) String() string

func (Binding) Tags added in v1.5.0

func (b Binding) Tags() []string

Tags returns the tags of the binding.

type Bindings

type Bindings []Binding

Bindings is a collection of bindings keyed by their name.

func NewBindingsFromEnvironment

func NewBindingsFromEnvironment() (Bindings, error)

NewBindingsFromEnvironment creates a new bindings from all the bindings at the path defined by $CNB_BINDINGS. If $CNB_BINDINGS is not defined, returns an empty collection of Bindings.

func NewBindingsFromPath

func NewBindingsFromPath(path string) (Bindings, error)

NewBindingsFromPath creates a new instance from all the bindings at a given path.

type BuildContext

type BuildContext struct {

	// Application is application to build.
	Application Application

	// Buildpack is metadata about the buildpack, from buildpack.toml.
	Buildpack Buildpack

	// Layers is the layers available to the buildpack.
	Layers Layers

	// PersistentMetadata is metadata that is persisted even across cache cleaning.
	PersistentMetadata map[string]interface{}

	// Plan is the buildpack plan provided to the buildpack.
	Plan BuildpackPlan

	// Platform is the contents of the platform.
	Platform Platform

	// StackID is the ID of the stack.
	StackID string
}

BuildContext contains the inputs to build.

type BuildPlan

type BuildPlan struct {
	// Provides is the dependencies provided by the buildpack.
	Provides []BuildPlanProvide `toml:"provides,omitempty"`

	// Requires is the dependencies required by the buildpack.
	Requires []BuildPlanRequire `toml:"requires,omitempty"`
}

BuildPlan represents the provisions and requirements of a buildpack during detection.

type BuildPlanProvide

type BuildPlanProvide struct {
	// Name is the name of the dependency.
	Name string `toml:"name"`
}

BuildPlanProvide represents a dependency provided by a buildpack.

type BuildPlanRequire

type BuildPlanRequire struct {
	// Name is the name of the dependency.
	Name string `toml:"name"`

	// Version is the version of the dependency.  Optional.
	Version string `toml:"version,omitempty"`

	// Metadata is the metadata for the dependency. Optional.
	Metadata map[string]interface{} `toml:"metadata,omitempty"`
}

BuildPlanRequire represents a dependency required by a buildpack.

type BuildPlans

type BuildPlans struct {
	// BuildPlan is the first build plan.
	BuildPlan

	// Or is the collection of other build plans.
	Or []BuildPlan `toml:"or,omitempty"`
}

BuildPlans represents a collection of build plans produced by a buildpack during detection.

type BuildResult

type BuildResult struct {

	// Layers is the collection of LayerCreators contributed by the buildpack.
	Layers []LayerContributor

	// PersistentMetadata is metadata that is persisted even across cache cleaning.
	PersistentMetadata map[string]interface{}

	// Plan is the buildpack plan contributed by the buildpack.
	Plan BuildpackPlan

	// Processes are the process types contributed by the buildpack.
	Processes []Process

	// Slices are the application slices contributed by the buildpack.
	Slices []Slice
}

BuildResult contains the results of detection.

func (BuildResult) String added in v1.4.1

func (b BuildResult) String() string

type Builder added in v1.3.0

type Builder interface {

	// Build takes a context and returns a result, performing buildpack build behaviors.
	Build(context BuildContext) (BuildResult, error)
}

Builder describes an interface for types that can be used by the Build function.

type Buildpack

type Buildpack struct {
	// API is the api version expected by the buildpack.
	API string `toml:"api"`

	// Info is information about the buildpack.
	Info BuildpackInfo `toml:"buildpack"`

	// Orders is buildpack collection of order definitions in the buildpack.
	Orders []BuildpackOrder `toml:"order"`

	// Path is the path to the buildpack.
	Path string

	// Stacks is the collection of stacks supported by the buildpack.
	Stacks []BuildpackStack `toml:"stacks"`

	// Metadata is arbitrary metadata attached to the buildpack.
	Metadata map[string]interface{} `toml:"metadata"`
}

Buildpack is the contents of the buildpack.toml file.

type BuildpackInfo

type BuildpackInfo struct {
	// ID is the ID of the buildpack.
	ID string `mapstructure:"id" toml:"id"`

	// Name is the name of the buildpack.
	Name string `mapstructure:"name" toml:"name"`

	// Version is the version of the buildpack.
	Version string `mapstructure:"version" toml:"version"`

	// ClearEnvironment is whether the environment should be clear of user-configured environment variables.
	ClearEnvironment bool `mapstructure:"clear-env" toml:"clear-env"`
}

BuildpackInfo is information about the buildpack.

type BuildpackOrder

type BuildpackOrder struct {
	// Groups is the collection of groups within the order.
	Groups []BuildpackOrderBuildpack `toml:"group"`
}

BuildpackOrder is an order definition in the buildpack.

type BuildpackOrderBuildpack

type BuildpackOrderBuildpack struct {
	// ID is the id of the buildpack.
	ID string `toml:"id"`

	// Version is the version of the buildpack.
	Version string `toml:"version"`

	// Optional is whether the buildpack is optional within the buildpack.
	Optional bool `toml:"optional"`
}

BuildpackOrderBuildpack is a buildpack within in a buildpack order group.

type BuildpackPathFormatter

type BuildpackPathFormatter string

BuildpackPathFormatter is the formatter for a BuildpackPath.

func (BuildpackPathFormatter) String

func (b BuildpackPathFormatter) String() string

type BuildpackPlan

type BuildpackPlan struct {

	// Entries represents all of the buildpack plan entries.
	Entries []BuildpackPlanEntry `toml:"entries,omitempty"`
}

BuildpackPlan represents a buildpack plan.

type BuildpackPlanEntry

type BuildpackPlanEntry struct {
	// Name represents the name of the entry.
	Name string `toml:"name"`

	// Version represents the version of the entry.  Optional.
	Version string `toml:"version,omitempty"`

	// Metadata is the metadata of the entry.  Optional.
	Metadata map[string]interface{} `toml:"metadata,omitempty"`
}

BuildpackPlanEntry represents an entry in the buildpack plan.

type BuildpackStack

type BuildpackStack struct {
	// ID is the id of the stack.
	ID string `toml:"id"`

	// Mixins is the collection of mixins associated with the stack.
	Mixins []string `toml:"mixins"`
}

BuildpackStack is a stack supported by the buildpack.

type Config

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

Config is an object that contains configurable properties for execution.

type DetectContext

type DetectContext struct {

	// Application is the application to build.
	Application Application

	// Buildpack is metadata about the buildpack, from buildpack.toml.
	Buildpack Buildpack

	// Platform is the contents of the platform.
	Platform Platform

	// StackID is the ID of the stack.
	StackID string
}

DetectContext contains the inputs to detection.

type DetectResult

type DetectResult struct {

	// Pass indicates whether detection has passed.
	Pass bool

	// Plans are the build plans contributed by the buildpack.
	Plans []BuildPlan
}

DetectResult contains the results of detection.

type Detector added in v1.3.0

type Detector interface {

	// Detect takes a context and returns a result, performing buildpack detect behaviors.
	Detect(context DetectContext) (DetectResult, error)
}

Detector describes an interface for types that can be used by the Detect function.

type Environment

type Environment map[string]string

Environment represents the file-based environment variable specification.

func (Environment) Append

func (e Environment) Append(name string, a ...interface{})

Append formats using the default formats for its operands and appends the value of this environment variable to any previous declarations of the value without any delimitation. Spaces are added between operands when neither is a string. If delimitation is important during concatenation, callers are required to add it.

func (Environment) Appendf added in v1.6.0

func (e Environment) Appendf(name string, format string, a ...interface{})

Appendf formats according to a format specifier and 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 (Environment) Default

func (e Environment) Default(name string, a ...interface{})

Default formats using the default formats for its operands and sets a default for an environment variable with this value. Spaces are added between operands when neither is a string.

func (Environment) Defaultf added in v1.6.0

func (e Environment) Defaultf(name string, format string, a ...interface{})

Defaultf formats according to a format specifier and sets a default for an environment variable with this value.

func (Environment) Delimiter

func (e Environment) Delimiter(name string, delimiter string)

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

func (Environment) Override

func (e Environment) Override(name string, a ...interface{})

Override formats using the default formats for its operands and overrides any existing value for an environment variable with this value. Spaces are added between operands when neither is a string.

func (Environment) Overridef added in v1.6.0

func (e Environment) Overridef(name string, format string, a ...interface{})

Overridef formats according to a format specifier and overrides any existing value for an environment variable with this value.

func (Environment) Prepend

func (e Environment) Prepend(name string, a ...interface{})

Prepend formats using the default formats for its operands and prepends the value of this environment variable to any previous declarations of the value without any delimitation. Spaces are added between operands when neither is a string. If delimitation is important during concatenation, callers are required to add it.

func (Environment) PrependPath

func (e Environment) PrependPath(name string, a ...interface{})

PrependPath formats using the default formats for its operands and prepends the value of this environment variable to any previous declarations of the value using the OS path delimiter. Spaces are added between operands when neither is a string.

func (Environment) PrependPathf added in v1.6.0

func (e Environment) PrependPathf(name string, format string, a ...interface{})

PrependPathf formats according to a format specifier and prepends the value of this environment variable to any previous declarations of the value using the OS path delimiter.

func (Environment) Prependf added in v1.6.0

func (e Environment) Prependf(name string, format string, a ...interface{})

Prependf formats using the default formats for its operands and 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.

type EnvironmentWriter

type EnvironmentWriter interface {

	// Write is called with the path to a directory where the environment variables should be serialized to and the
	// environment variables to serialize to that directory.
	Write(dir string, environment map[string]string) error
}

EnvironmentWriter is the interface implemented by a type that wants to serialize a map of environment variables to the file system.

type ExitHandler

type ExitHandler interface {

	// Error is called when an error is encountered.
	Error(error)

	// Fail is called when a buildpack fails.
	Fail()

	// Pass is called when a buildpack passes.
	Pass()
}

ExitHandler is the interface implemented by a type that wants to handle exit behavior when a buildpack encounters an error.

type Launch

type Launch struct {

	// Processes is the collection of process types contributed by the buildpack.
	Processes []Process `toml:"processes"`

	// Slices is the collection of slices contributed by the buildpack.
	Slices []Slice `toml:"slices"`
}

Launch represents the contents of launch.toml.

type Layer

type Layer struct {

	// Build indicates that a layer should be used for builds.
	Build bool `toml:"build"`

	// Cache indicates that a layer should be cached.
	Cache bool `toml:"cache"`

	// Launch indicates that a layer should be used for launch.
	Launch bool `toml:"launch"`

	// Metadata is the metadata associated with the layer.
	Metadata map[string]interface{} `toml:"metadata"`

	// Name is the name of the layer.
	Name string `toml:"-"`

	// Path is the filesystem location of the layer.
	Path string `toml:"-"`

	// BuildEnvironment are the environment variables set at build time.
	BuildEnvironment Environment `toml:"-"`

	// LaunchEnvironment are the environment variables set at launch time.
	LaunchEnvironment Environment `toml:"-"`

	// SharedEnvironment are the environment variables set at both build and launch times.
	SharedEnvironment Environment `toml:"-"`

	// Profile is the profile.d scripts set in the layer.
	Profile Profile `toml:"-"`
}

Contribute represents a layer managed by the buildpack.

type LayerContributor

type LayerContributor interface {

	// Contribute accepts a layer and transforms it, returning a layer.
	Contribute(layer Layer) (Layer, error)

	// Name is the name of the layer.
	Name() string
}

LayerContributor is an interface for types that create layers.

type Layers

type Layers struct {

	// Path is the layers filesystem location.
	Path string
}

Layers represents the layers part of the specification.

func (*Layers) Layer

func (l *Layers) Layer(name string) (Layer, error)

Layer creates a new layer, loading metadata if it exists.

type Option

type Option func(config Config) Config

Option is a function for configuring a Config instance.

func WithArguments

func WithArguments(arguments []string) Option

WithArguments creates an Option that sets a collection of arguments.

func WithEnvironmentWriter

func WithEnvironmentWriter(environmentWriter EnvironmentWriter) Option

WithEnvironmentWriter creates an Option that sets an EnvironmentWriter implementation.

func WithExitHandler

func WithExitHandler(exitHandler ExitHandler) Option

WithExitHandler creates an Option that sets an ExitHandler implementation.

func WithTOMLWriter

func WithTOMLWriter(tomlWriter TOMLWriter) Option

WithTOMLWriter creates an Option that sets a TOMLWriter implementation.

type Platform

type Platform struct {

	// Bindings are the external bindings available to the application.
	Bindings Bindings

	// Environment is the environment exposed by the platform.
	Environment map[string]string

	// Path is the path to the platform.
	Path string
}

Platform is the contents of the platform directory.

type PlatformFormatter

type PlatformFormatter Platform

PlatformFormatter is the formatter for a Platform.

func (PlatformFormatter) String

func (p PlatformFormatter) String() string

type Process

type Process struct {

	// Type is the type of the process.
	Type string `toml:"type"`

	// Command is the command of the process.
	Command string `toml:"command"`

	// Arguments are arguments to the command.
	Arguments []string `toml:"args"`

	// Command is exec'd directly by the os (no profile.d scripts run)
	Direct bool `toml:"direct,omitempty"`
}

Process represents metadata about a type of command that can be run.

type Profile

type Profile map[string]string

Profile is the collection of values to be written into profile.d

func (Profile) Add

func (p Profile) Add(name string, a ...interface{})

Add formats using the default formats for its operands and adds an entry for a .profile.d file. Spaces are added between operands when neither is a string.

func (Profile) Addf added in v1.6.0

func (p Profile) Addf(name string, format string, a ...interface{})

Addf formats according to a format specifier and adds an entry for a .profile.d file.

type Slice

type Slice struct {

	// Paths are the contents of the slice.
	Paths []string `toml:"paths"`
}

Slice represents metadata about a slice.

type Store

type Store struct {

	// Metadata represents the persistent metadata.
	Metadata map[string]interface{} `toml:"metadata"`
}

Store represents the contents of store.toml

type TOMLWriter

type TOMLWriter interface {

	// Write is called with the path that a TOML file should be written to and the object to serialize to that file.
	Write(path string, value interface{}) error
}

TOMLWriter is the interface implemented by a type that wants to serialize an object to a TOML file.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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