libpak

package module
v1.27.4 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2020 License: Apache-2.0 Imports: 18 Imported by: 247

README

libpak

libpak is a Go library with useful functionality for building Paketo-style buildpacks.

License

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Build

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

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

func Detect

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

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

func IsNoValidDependencies added in v1.15.0

func IsNoValidDependencies(err error) bool

IsNoValidDependencies indicates whether an error is a NoValidDependenciesError.

func ShallowMerge

ShallowMerge merges two BuildpackPlanEntry's together. Declared versions are combined with a comma delimiter and metadata is combined with the values for b taking priority over the values of a when the keys are duplicated.

Types

type BindingResolver

type BindingResolver struct {

	// Bindings are the bindings to resolve against.
	Bindings libcnb.Bindings
}

BindingResolver provides functionality for resolving a binding given a collection of constraints.

func (*BindingResolver) Resolve

func (b *BindingResolver) Resolve(kind string, provider string, tags ...string) (libcnb.Binding, bool, error)

Resolve returns the matching binding within the collection of Bindings. The candidate set is filtered by the constraints.

type BuildpackDependency

type BuildpackDependency struct {
	// ID is the dependency ID.
	ID string `mapstructure:"id" toml:"id"`

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

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

	// URI is the dependency URI.
	URI string `mapstructure:"uri" toml:"uri"`

	// SHA256 is the hash of the dependency.
	SHA256 string `mapstructure:"sha256" toml:"sha256"`

	// Stacks are the stacks the dependency is compatible with.
	Stacks []string `mapstructure:"stacks" toml:"stacks"`

	// Licenses are the stacks the dependency is distributed under.
	Licenses []BuildpackDependencyLicense `mapstructure:"licenses" toml:"licenses"`
}

BuildpackDependency describes a dependency known to the buildpack.

func (BuildpackDependency) AsBuildpackPlanEntry added in v1.21.0

func (b BuildpackDependency) AsBuildpackPlanEntry() libcnb.BuildpackPlanEntry

AsBuildpackPlanEntry renders the dependency as a BuildpackPlanEntry.

type BuildpackDependencyLicense

type BuildpackDependencyLicense struct {

	// Type is the type of the license.  This is typically the SPDX short identifier.
	Type string `mapstructure:"type" toml:"type"`

	// URI is the location where the license can be found.
	URI string `mapstructure:"uri" toml:"uri"`
}

License represents a license that a BuildpackDependency is distributed under. At least one of Name or URI MUST be specified.

type BuildpackMetadata

type BuildpackMetadata struct {

	// DefaultVersions represent the default versions for dependencies keyed by Dependency.Id.
	DefaultVersions map[string]string

	// Dependencies are the dependencies known to the buildpack.
	Dependencies []BuildpackDependency

	// IncludeFiles describes the files to include in the package.
	IncludeFiles []string

	// PrePackage describes a command to invoke before packaging.
	PrePackage string
}

BuildpackMetadata is an extension to libcnb.Buildpack's metadata with opinions.

func NewBuildpackMetadata

func NewBuildpackMetadata(metadata map[string]interface{}) (BuildpackMetadata, error)

NewBuildpackMetadata creates a new instance of BuildpackMetadata from the contents of libcnb.Buildpack.Metadata

type DependenciesFormatter

type DependenciesFormatter []BuildpackDependency

DependenciesFormatter is the formatter for a []BuildpackDependency.

func (DependenciesFormatter) String

func (d DependenciesFormatter) String() string

type DependencyCache

type DependencyCache struct {

	// CachePath is the location where the buildpack has cached its dependencies.
	CachePath string

	// DownloadPath is the location of all downloads during this execution of the build.
	DownloadPath string

	// Logger is the logger used to write to the console.
	Logger bard.Logger

	// UserAgent is the User-Agent string to use with requests.
	UserAgent string
}

DependencyCache allows a user to get an artifact either from a buildpack's cache, a previous download, or to download directly.

func NewDependencyCache

func NewDependencyCache(buildpack libcnb.Buildpack) DependencyCache

NewDependencyCache creates a new instance setting the default cache path (<BUILDPACK_PATH>/dependencies) and user agent (<BUILDPACK_ID>/<BUILDPACK_VERSION>).

func (*DependencyCache) Artifact

func (d *DependencyCache) Artifact(dependency BuildpackDependency) (*os.File, error)

Artifact returns the path to the artifact. Resolution of that path follows three tiers:

1. CachePath 2. DownloadPath 3. Download from URI

If the BuildpackDependency's SHA256 is not set, the download can never be verified to be up to date and will always download, skipping all the caches.

func (*DependencyCache) ArtifactWithRequestModification added in v1.25.0

func (d *DependencyCache) ArtifactWithRequestModification(dependency BuildpackDependency, f RequestModifierFunc) (*os.File, error)

ArtifactWithRequestModification returns the path to the artifact. Resolution of that path follows three tiers:

1. CachePath 2. DownloadPath 3. Download from URI

If the BuildpackDependency's SHA256 is not set, the download can never be verified to be up to date and will always download, skipping all the caches.

type DependencyLayerContributor

type DependencyLayerContributor struct {

	// Dependency is the dependency being contributed.
	Dependency BuildpackDependency

	// DependencyCache is the cache to use to get the dependency.
	DependencyCache DependencyCache

	// LayerContributor is the contained LayerContributor used for the actual contribution.
	LayerContributor LayerContributor

	// Logger is the logger to use.
	Logger bard.Logger

	// RequestModifierFunc is an optional Request Modifier to use when downloading the dependency.
	RequestModifierFunc RequestModifierFunc
}

DependencyLayerContributor is a helper for implementing a libcnb.LayerContributor for a BuildpackDependency in order to get consistent logging and avoidance.

func NewDependencyLayerContributor

func NewDependencyLayerContributor(dependency BuildpackDependency, cache DependencyCache, plan *libcnb.BuildpackPlan) DependencyLayerContributor

NewDependencyLayerContributor creates a new instance and adds the dependency to the Buildpack Plan.

func (*DependencyLayerContributor) Contribute

Contribute is the function to call whe implementing your libcnb.LayerContributor.

type DependencyLayerFunc

type DependencyLayerFunc func(artifact *os.File) (libcnb.Layer, error)

DependencyLayerFunc is a callback function that is invoked when a dependency needs to be contributed.

type DependencyResolver

type DependencyResolver struct {

	// Dependencies are the dependencies to resolve against.
	Dependencies []BuildpackDependency

	// StackID is the stack id of the build.
	StackID string
}

DependencyResolver provides functionality for resolving a dependency fiven a collection of constraints.

func NewDependencyResolver

func NewDependencyResolver(context libcnb.BuildContext) (DependencyResolver, error)

NewDependencyResolver creates a new instance from the buildpack metadata and stack id.

func (*DependencyResolver) Resolve

func (d *DependencyResolver) Resolve(id string, version string) (BuildpackDependency, error)

Resolve returns the latest version of a dependency within the collection of Dependencies. The candidate set is first filtered by the constraints, then the remaining candidates are sorted for the latest result by semver semantics. Version can contain wildcards and defaults to "*" if not specified.

type HelperLayerContributor

type HelperLayerContributor struct {

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

	// LayerContributor is the contained LayerContributor used for the actual contribution.
	LayerContributor LayerContributor

	// Logger is the logger to use.
	Logger bard.Logger
}

HelperLayerContributor is a helper for implementing a libcnb.LayerContributor for a buildpack helper application in order to get consistent logging and avoidance.

func NewHelperLayerContributor

func NewHelperLayerContributor(path string, name string, info libcnb.BuildpackInfo, plan *libcnb.BuildpackPlan) HelperLayerContributor

NewHelperLayerContributor creates a new instance and adds the helper to the Buildpack Plan.

func (*HelperLayerContributor) Contribute

Contribute is the function to call whe implementing your libcnb.LayerContributor.

type HelperLayerFunc

type HelperLayerFunc func(artifact *os.File) (libcnb.Layer, error)

DependencyLayerFunc is a callback function that is invoked when a helper needs to be contributed.

type LayerContributor

type LayerContributor struct {

	// ExpectedMetadata is the metadata to compare against any existing layer metadata.
	ExpectedMetadata interface{}

	// Logger is the logger to use.
	Logger bard.Logger

	// Name is the user readable name of the contribution.
	Name string
}

LayerContributor is a helper for implementing a libcnb.LayerContributor in order to get consistent logging and avoidance.

func NewLayerContributor

func NewLayerContributor(name string, expectedMetadata interface{}) LayerContributor

NewLayerContributor creates a new instance.

func (*LayerContributor) Contribute

func (l *LayerContributor) Contribute(layer libcnb.Layer, f LayerFunc) (libcnb.Layer, error)

Contribute is the function to call when implementing your libcnb.LayerContributor.

type LayerFunc

type LayerFunc func() (libcnb.Layer, error)

LayerFunc is a callback function that is invoked when a layer needs to be contributed.

type MergeFunc

MergeFunc takes two BuildpackPlanEntry's and returns a merged entry.

type NoValidDependenciesError

type NoValidDependenciesError struct {
	// Message is the error message
	Message string
}

NoValidDependenciesError is returned when the resolver cannot find any valid dependencies given the constraints.

func (NoValidDependenciesError) Error

func (n NoValidDependenciesError) Error() string

type PlanEntryResolver

type PlanEntryResolver struct {

	// Plan is the BuildpackPlan to resolve against.
	Plan libcnb.BuildpackPlan
}

PlanEntryResolver provides functionality for resolving a Buildpack Plan Entry given a name.

func (*PlanEntryResolver) Resolve

Resolve calls ResolveWithMerge function passing in the ShallowMerge function as the merge strategy.

func (*PlanEntryResolver) ResolveWithMerge

func (p *PlanEntryResolver) ResolveWithMerge(name string, f MergeFunc) (libcnb.BuildpackPlanEntry, bool, error)

ResolveWithMerge returns a single BuildpackPlanEntry that is a merged version of all entries that have a given name. A merge function is used to describe how two entries are merged together.

type RequestModifierFunc added in v1.25.0

type RequestModifierFunc func(request *http.Request) (*http.Request, error)

RequestModifierFunc is a callback that enables modification of a download request before it is sent. It is often used to set Authorization headers.

Jump to

Keyboard shortcuts

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