buildpack

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: Apache-2.0 Imports: 36 Imported by: 2

Documentation

Index

Constants

View Source
const (
	KindBuildpack = "buildpack"
	KindExtension = "extension"
)
View Source
const MetadataLabel = "io.buildpacks.buildpackage.metadata"

TODO: Move to dist

Variables

This section is empty.

Functions

func BuildpacksFromOCILayoutBlob

func BuildpacksFromOCILayoutBlob(blob Blob) (mainBP BuildModule, dependencies []BuildModule, err error)

BuildpacksFromOCILayoutBlob constructs buildpacks from a blob in OCI layout format.

func ConfigFromOCILayoutBlob

func ConfigFromOCILayoutBlob(blob Blob) (config v1.ImageConfig, err error)

func CopyConfigFile added in v0.34.0

func CopyConfigFile(baseDir string, target dist.Target) (string, error)

CopyConfigFile will copy the buildpack.toml file from the base directory into the corresponding platform folder for the specified target and desired distribution version.

func HasDockerLocator

func HasDockerLocator(locator string) bool

func IsOCILayoutBlob

func IsOCILayoutBlob(blob blob2.Blob) (bool, error)

IsOCILayoutBlob checks whether a blob is in OCI layout format.

func NewDownloader

func NewDownloader(logger Logger, imageFetcher ImageFetcher, downloader Downloader, registryResolver RegistryResolver) *buildpackDownloader

func ParseIDLocator

func ParseIDLocator(locator string) (id string, version string)

ParseIDLocator parses a buildpack locator in the following formats into its ID and version.

  • <id>[@<version>]
  • urn:cnb:builder:<id>[@<version>]
  • urn:cnb:registry:<id>[@<version>]
  • from=builder:<id>[@<version>] (deprecated)

If version is omitted, the version returned will be empty. Any "from=builder:" or "urn:cnb" prefix will be ignored.

func ParsePackageLocator

func ParsePackageLocator(locator string) (imageName string)

ParsePackageLocator parses a locator (in format `[docker://][<host>/]<path>[:<tag>⏐@<digest>]`) to image name (`[<host>/]<path>[:<tag>⏐@<digest>]`)

func ParseRegistryID

func ParseRegistryID(registryID string) (namespace string, name string, version string, err error)

ParseRegistryID parses a registry id (ie. `<namespace>/<name>@<version>`) into namespace, name and version components.

Supported formats:

  • <ns>/<name>[@<version>]
  • urn:cnb:registry:<ns>/<name>[@<version>]

func PlatformRootFolder added in v0.34.0

func PlatformRootFolder(bpPathURI string, target dist.Target) (bool, string)

PlatformRootFolder finds the top-most directory that identifies a target in a given buildpack <root> folder. Let's define a target with the following format: os[/arch][/variant]:[name@version], and consider the following examples:

  • Given a target linux/amd64 the platform root folder will be <root>/linux/amd64 if the folder exists
  • Given a target windows/amd64:windows@10.0.20348.1970 the platform root folder will be <root>/windows/amd64/windows@10.0.20348.1970 if the folder exists
  • When no target folder exists, the root folder will be equal to <root> folder

Note: If the given target has more than 1 distribution, it is recommended to use `ExpandTargetsDistributions` before calling this method.

func Set added in v0.30.0

func Set(exclude []string) map[string]struct{}

Set returns a set of the given string slice.

func ToLayerTar

func ToLayerTar(dest string, module BuildModule) (string, error)

Types

type Blob

type Blob interface {
	// Open returns a io.ReadCloser for the contents of the Blob in tar format.
	Open() (io.ReadCloser, error)
}

type BuildModule added in v0.28.0

type BuildModule interface {
	// Open returns a reader to a tar with contents structured as per the distribution spec
	// (currently '/cnb/buildpacks/{ID}/{version}/*', all entries with a zeroed-out
	// timestamp and root UID/GID).
	Open() (io.ReadCloser, error)
	Descriptor() Descriptor
}

func ExtensionsFromOCILayoutBlob added in v0.28.0

func ExtensionsFromOCILayoutBlob(blob Blob) (mainExt BuildModule, err error)

ExtensionsFromOCILayoutBlob constructs extensions from a blob in OCI layout format.

func FromBlob

func FromBlob(descriptor Descriptor, blob Blob) BuildModule

FromBlob constructs a buildpack or extension from a blob. It is assumed that the buildpack contents are structured as per the distribution spec (currently '/cnb/buildpacks/{ID}/{version}/*' or '/cnb/extensions/{ID}/{version}/*').

func FromBuildpackRootBlob added in v0.28.0

func FromBuildpackRootBlob(blob Blob, layerWriterFactory archive.TarWriterFactory, logger Logger) (BuildModule, error)

FromBuildpackRootBlob constructs a buildpack from a blob. It is assumed that the buildpack contents reside at the root of the blob. The constructed buildpack contents will be structured as per the distribution spec (currently a tar with contents under '/cnb/buildpacks/{ID}/{version}/*').

func FromExtensionRootBlob added in v0.28.0

func FromExtensionRootBlob(blob Blob, layerWriterFactory archive.TarWriterFactory, logger Logger) (BuildModule, error)

FromExtensionRootBlob constructs an extension from a blob. It is assumed that the extension contents reside at the root of the blob. The constructed extension contents will be structured as per the distribution spec (currently a tar with contents under '/cnb/extensions/{ID}/{version}/*').

type BuildModuleWriter added in v0.30.0

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

func NewBuildModuleWriter added in v0.30.0

func NewBuildModuleWriter(logger logging.Logger, factory archive.TarWriterFactory) *BuildModuleWriter

NewBuildModuleWriter creates a BuildModule writer

func (*BuildModuleWriter) NToLayerTar added in v0.30.0

func (b *BuildModuleWriter) NToLayerTar(tarPath, filename string, modules []BuildModule, exclude map[string]struct{}) (string, []BuildModule, error)

NToLayerTar creates a tar file containing the all the Buildpacks given, but excluding the ones which FullName() is in the exclude list. It returns the path to the tar file, the list of Buildpacks that were excluded, and any error

type Descriptor added in v0.28.0

type Descriptor interface {
	API() *api.Version
	EnsureStackSupport(stackID string, providedMixins []string, validateRunStageMixins bool) error
	EnsureTargetSupport(os, arch, distroName, distroVersion string) error
	EscapedID() string
	Info() dist.ModuleInfo
	Kind() string
	Order() dist.Order
	Stacks() []dist.Stack
	Targets() []dist.Target
}

type DownloadOptions

type DownloadOptions struct {
	// Buildpack registry name. Defines where all registry buildpacks will be pulled from.
	RegistryName string

	// The base directory to use to resolve relative assets
	RelativeBaseDir string

	// Deprecated: the older alternative to specify the OS to download; use Target instead
	ImageOS string

	// Deprecated: the older alternative to buildpack URI
	ImageName string

	// The kind of module to download (valid values: "buildpack", "extension"). Defaults to "buildpack".
	ModuleKind string

	Daemon bool

	PullPolicy image.PullPolicy

	// The OS/Architecture/Variant to download.
	Target *dist.Target
}

type Downloader

type Downloader interface {
	Download(ctx context.Context, pathOrURI string) (blob.Blob, error)
}

type FlattenModuleInfos added in v0.33.0

type FlattenModuleInfos interface {
	FlattenModules() []ModuleInfos
}

func ParseFlattenBuildModules added in v0.33.0

func ParseFlattenBuildModules(buildpacksID []string) (FlattenModuleInfos, error)

type ImageFactory

type ImageFactory interface {
	NewImage(repoName string, local bool, target dist.Target) (imgutil.Image, error)
}

type ImageFetcher

type ImageFetcher interface {
	Fetch(ctx context.Context, name string, options image.FetchOptions) (imgutil.Image, error)
	CheckReadAccess(repo string, options image.FetchOptions) bool
}

type LocatorType

type LocatorType int
const (
	InvalidLocator LocatorType = iota
	FromBuilderLocator
	URILocator
	IDLocator
	PackageLocator
	RegistryLocator
)

func GetLocatorType

func GetLocatorType(locator string, relativeBaseDir string, buildpacksFromBuilder []dist.ModuleInfo) (LocatorType, error)

GetLocatorType determines which type of locator is designated by the given input. If a type cannot be determined, `INVALID_LOCATOR` will be returned. If an error is encountered, it will be returned.

func (LocatorType) String

func (l LocatorType) String() string

type Logger

type Logger interface {
	Debug(msg string)
	Debugf(fmt string, v ...interface{})
	Info(msg string)
	Infof(fmt string, v ...interface{})
	Warn(msg string)
	Warnf(fmt string, v ...interface{})
	Error(msg string)
	Errorf(fmt string, v ...interface{})
}

type ManagedCollection added in v0.30.0

type ManagedCollection interface {
	// AllModules returns all build modules handled by the manager.
	AllModules() []BuildModule

	// ExplodedModules returns all build modules that will be added to the output artifact as a single layer
	// containing a single module.
	ExplodedModules() []BuildModule

	// AddModules adds module information to the collection as flattened or not, depending on how the collection is configured.
	AddModules(main BuildModule, deps ...BuildModule)

	// FlattenedModules returns all build modules that will be added to the output artifact as a single layer
	// containing multiple modules.
	FlattenedModules() [][]BuildModule

	// ShouldFlatten returns true if the given module should be flattened.
	ShouldFlatten(module BuildModule) bool
}

ManagedCollection keeps track of build modules and the manner in which they should be added to an OCI image (as flattened or exploded).

func NewManagedCollectionV1 added in v0.33.0

func NewManagedCollectionV1(flattenAll bool) ManagedCollection

NewManagedCollectionV1 will create a manager instance responsible for flattening Buildpack Packages.

func NewManagedCollectionV2 added in v0.33.0

func NewManagedCollectionV2(modules FlattenModuleInfos) ManagedCollection

NewManagedCollectionV2 will create a manager instance responsible for flattening buildpacks inside a Builder. The flattened build modules provided are the groups of buildpacks that must be put together in a single layer; the manager will take care of keeping them in the correct group (flattened or exploded) once they are added.

type Metadata

type Metadata struct {
	dist.ModuleInfo
	Stacks []dist.Stack `toml:"stacks" json:"stacks"`
}

type ModuleInfos added in v0.33.0

type ModuleInfos interface {
	BuildModule() []dist.ModuleInfo
}

type ModuleTar added in v0.30.0

type ModuleTar interface {
	Info() dist.ModuleInfo
	Path() string
}

func ToNLayerTar added in v0.30.0

func ToNLayerTar(dest string, module BuildModule) ([]ModuleTar, error)

type MultiArchConfig added in v0.34.0

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

MultiArchConfig targets can be defined in .toml files or can be overridden by end-users via the command line; this structure offers utility methods to determine the expected final targets configuration.

func NewMultiArchConfig added in v0.34.0

func NewMultiArchConfig(targets []dist.Target, expected []dist.Target, logger logging.Logger) (*MultiArchConfig, error)

func (*MultiArchConfig) CopyConfigFiles added in v0.34.0

func (m *MultiArchConfig) CopyConfigFiles(baseDir string) ([]string, error)

CopyConfigFiles will, given a base directory (which is expected to be the root folder of a single buildpack), copy the buildpack.toml file from the base directory into the corresponding platform root folder for each target. It will return an array with all the platform root folders where the buildpack.toml file was copied.

func (*MultiArchConfig) Targets added in v0.34.0

func (m *MultiArchConfig) Targets() []dist.Target

type Package

type Package interface {
	Label(name string) (value string, err error)
	GetLayer(diffID string) (io.ReadCloser, error)
}

type PackageBuilder

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

func NewBuilder

func NewBuilder(imageFactory ImageFactory, ops ...PackageBuilderOption) *PackageBuilder

TODO: Rename to PackageBuilder

func (*PackageBuilder) AddDependencies added in v0.30.0

func (b *PackageBuilder) AddDependencies(main BuildModule, dependencies []BuildModule)

func (*PackageBuilder) AddDependency

func (b *PackageBuilder) AddDependency(buildpack BuildModule)

func (*PackageBuilder) AllModules added in v0.30.0

func (b *PackageBuilder) AllModules() []BuildModule

func (*PackageBuilder) FlattenedModules added in v0.30.0

func (b *PackageBuilder) FlattenedModules() [][]BuildModule

func (*PackageBuilder) SaveAsFile

func (b *PackageBuilder) SaveAsFile(path string, target dist.Target, labels map[string]string) error

func (*PackageBuilder) SaveAsImage

func (b *PackageBuilder) SaveAsImage(repoName string, publish bool, target dist.Target, labels map[string]string) (imgutil.Image, error)

func (*PackageBuilder) SetBuildpack

func (b *PackageBuilder) SetBuildpack(buildpack BuildModule)

func (*PackageBuilder) SetExtension added in v0.30.0

func (b *PackageBuilder) SetExtension(extension BuildModule)

func (*PackageBuilder) ShouldFlatten added in v0.30.0

func (b *PackageBuilder) ShouldFlatten(module BuildModule) bool

type PackageBuilderOption added in v0.30.0

type PackageBuilderOption func(*options) error

func DoNotFlatten added in v0.33.0

func DoNotFlatten(exclude []string) PackageBuilderOption

func FlattenAll added in v0.33.0

func FlattenAll() PackageBuilderOption

func WithLayerWriterFactory added in v0.30.0

func WithLayerWriterFactory(factory archive.TarWriterFactory) PackageBuilderOption

func WithLogger added in v0.30.0

func WithLogger(logger logging.Logger) PackageBuilderOption

type RegistryResolver

type RegistryResolver interface {
	Resolve(registryName, bpURI string) (string, error)
}

type WorkableImage

type WorkableImage interface {
	SetLabel(string, string) error
	AddLayerWithDiffID(path, diffID string) error
}

Jump to

Keyboard shortcuts

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