buildpack

package
v0.19.3 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 23 Imported by: 3

Documentation

Index

Constants

View Source
const (
	MediaTypeCycloneDX = "application/vnd.cyclonedx+json"
	MediaTypeSPDX      = "application/spdx+json"
	MediaTypeSyft      = "application/vnd.syft+json"

	ExtensionCycloneDX = "sbom.cdx.json"
	ExtensionSPDX      = "sbom.spdx.json"
	ExtensionSyft      = "sbom.syft.json"
)
View Source
const (
	// EnvBpPlanPath is the absolute path of the filtered build plan, containing relevant Buildpack Plan entries from detection
	EnvBpPlanPath = "CNB_BP_PLAN_PATH"
	// EnvLayersDir is the absolute path of the buildpack layers directory (read-write); a different copy is provided for each buildpack;
	// contents may be saved to either or both of: the final output image or the cache
	EnvLayersDir = "CNB_LAYERS_DIR"
)
View Source
const (
	KindBuildpack = "Buildpack"
	KindExtension = "Extension"
)
View Source
const (
	// EnvBuildPlanPath is the absolute path of the build plan; a different copy is provided for each buildpack
	EnvBuildPlanPath = "CNB_BUILD_PLAN_PATH"
	// EnvBuildpackDir is the absolute path of the buildpack root directory (read-only)
	EnvBuildpackDir = "CNB_BUILDPACK_DIR"
	// EnvExtensionDir is the absolute path of the extension root directory (read-only)
	EnvExtensionDir = "CNB_EXTENSION_DIR"
	// EnvPlatformDir is the absolute path of the platform directory (read-only); a single copy is provided for all buildpacks
	EnvPlatformDir = "CNB_PLATFORM_DIR"
)
View Source
const (
	DockerfileKindBuild = "build"
	DockerfileKindRun   = "run"
)
View Source
const (
	// EnvOutputDir is the absolute path of the extension output directory (read-write); a different copy is provided for each extension;
	// contents are copied to the generator's <generated> directory
	EnvOutputDir = "CNB_OUTPUT_DIR"
)

Variables

This section is empty.

Functions

func DecodeLaunchTOML added in v0.15.0

func DecodeLaunchTOML(launchPath string, bpAPI string, launchTOML *LaunchTOML) error

DecodeLaunchTOML reads a launch.toml file

func EncodeLayerMetadataFile

func EncodeLayerMetadataFile(lmf LayerMetadataFile, path, buildpackAPI string) error

func MadeCached added in v0.13.1

func MadeCached(l Layer) bool

func MadeLaunch added in v0.13.1

func MadeLaunch(l Layer) bool

func Malformed added in v0.13.1

func Malformed(l Layer) bool

func ValidateBuildDockerfile added in v0.17.0

func ValidateBuildDockerfile(dockerfile string, logger log.Logger) error

func ValidateRunDockerfile added in v0.17.0

func ValidateRunDockerfile(dInfo *DockerfileInfo, logger log.Logger) error

Types

type BOMEntry

type BOMEntry struct {
	Require
	Buildpack GroupElement `toml:"buildpack" json:"buildpack"`
}

func WithBuildpack

func WithBuildpack(bp GroupElement, bom []BOMEntry) []BOMEntry

type BOMFile added in v0.13.0

type BOMFile struct {
	BuildpackID string
	LayerName   string
	LayerType   LayerType
	Path        string
}

func (*BOMFile) Name added in v0.13.0

func (b *BOMFile) Name() (string, error)

Name() returns the destination filename for a given BOM file cdx files should be renamed to "sbom.cdx.json" spdx files should be renamed to "sbom.spdx.json" syft files should be renamed to "sbom.syft.json" If the BOM is neither cdx, spdx, nor syft, the 2nd return argument will return an error to indicate an unsupported format

type BOMValidator added in v0.13.0

type BOMValidator interface {
	ValidateBOM(GroupElement, []BOMEntry) ([]BOMEntry, error)
}

func NewBOMValidator added in v0.13.0

func NewBOMValidator(_ string, layersDir string, logger log.Logger) BOMValidator

NewBOMValidator returns a validator for the legacy unstructured BOM.

type BaseInfo added in v0.15.0

type BaseInfo struct {
	ClearEnv bool   `toml:"clear-env,omitempty"`
	Homepage string `toml:"homepage,omitempty"`
	ID       string `toml:"id"`
	Name     string `toml:"name"`
	Version  string `toml:"version"`
}

BaseInfo is information shared by both buildpacks and extensions. For buildpacks it winds up under the toml `buildpack` key along with SBOM info, but extensions have no SBOMs.

type BpDescriptor added in v0.15.0

type BpDescriptor struct {
	WithAPI     string           `toml:"api"`
	Buildpack   BpInfo           `toml:"buildpack"`
	Order       Order            `toml:"order"`
	WithRootDir string           `toml:"-"`
	Targets     []TargetMetadata `toml:"targets"`
	Stacks      []StackMetadata  `tome:"stacks"` // just for backwards compat so we can check if it's the bionic stack, which we translate to a target

}

func ReadBpDescriptor added in v0.15.0

func ReadBpDescriptor(path string) (*BpDescriptor, error)

func (*BpDescriptor) API added in v0.15.0

func (d *BpDescriptor) API() string

func (*BpDescriptor) ClearEnv added in v0.15.0

func (d *BpDescriptor) ClearEnv() bool

func (*BpDescriptor) Homepage added in v0.15.0

func (d *BpDescriptor) Homepage() string

func (*BpDescriptor) RootDir added in v0.15.0

func (d *BpDescriptor) RootDir() string

func (*BpDescriptor) String added in v0.15.0

func (d *BpDescriptor) String() string

func (*BpDescriptor) TargetsList added in v0.17.0

func (d *BpDescriptor) TargetsList() []TargetMetadata

type BpInfo added in v0.15.0

type BpInfo struct {
	BaseInfo
	SBOM []string `toml:"sbom-formats,omitempty" json:"sbom-formats,omitempty"`
}

type BuildEnv

type BuildEnv interface {
	AddRootDir(baseDir string) error
	AddEnvDir(envDir string, defaultAction env.ActionType) error
	WithOverrides(platformDir string, buildConfigDir string) ([]string, error)
	List() []string
}

type BuildExecutor added in v0.15.0

type BuildExecutor interface {
	Build(d BpDescriptor, inputs BuildInputs, logger log.Logger) (BuildOutputs, error)
}

BuildExecutor executes a single buildpack's `./bin/build` binary, providing inputs as defined in the Buildpack Interface Specification, and processing outputs for the platform.

type BuildInputs added in v0.15.0

type BuildInputs struct {
	AppDir         string
	BuildConfigDir string
	LayersDir      string
	PlatformDir    string
	Env            BuildEnv
	TargetEnv      []string
	Out, Err       io.Writer
	Plan           Plan
}

type BuildOutputs added in v0.15.0

type BuildOutputs struct {
	BOMFiles    []BOMFile
	BuildBOM    []BOMEntry
	Labels      []Label
	LaunchBOM   []BOMEntry
	MetRequires []string
	Processes   []launch.Process
	Slices      []layers.Slice
}

type BuildPlan

type BuildPlan struct {
	PlanSections
	Or planSectionsList `toml:"or"`
}

type BuildTOML

type BuildTOML struct {
	BOM   []BOMEntry `toml:"bom"`
	Unmet []Unmet    `toml:"unmet"`
}

type DefaultBuildExecutor added in v0.15.0

type DefaultBuildExecutor struct{}

func (*DefaultBuildExecutor) Build added in v0.15.0

func (e *DefaultBuildExecutor) Build(d BpDescriptor, inputs BuildInputs, logger log.Logger) (BuildOutputs, error)

type DefaultDetectExecutor added in v0.15.0

type DefaultDetectExecutor struct{}

func (*DefaultDetectExecutor) Detect added in v0.15.0

type DefaultGenerateExecutor added in v0.15.0

type DefaultGenerateExecutor struct{}

func (*DefaultGenerateExecutor) Generate added in v0.15.0

type Descriptor

type Descriptor interface {
	API() string
	Homepage() string
	TargetsList() []TargetMetadata
}

Descriptor exposes information contained in a buildpack.toml or extension.toml that is generic to buildpacks and/or image extensions.

type DetectExecutor added in v0.15.0

type DetectExecutor interface {
	Detect(d Descriptor, inputs DetectInputs, logger log.Logger) DetectOutputs
}

DetectExecutor executes a single buildpack or image extension's `./bin/detect` binary, providing inputs as defined in the Buildpack Interface Specification, and processing outputs for the platform. For image extensions (where `./bin/detect` is optional), pre-populated outputs are processed here.

type DetectInputs added in v0.15.0

type DetectInputs struct {
	AppDir         string
	BuildConfigDir string
	PlatformDir    string
	Env            BuildEnv
	TargetEnv      []string
}

type DetectOutputs added in v0.15.0

type DetectOutputs struct {
	BuildPlan
	Output []byte `toml:"-"`
	Code   int    `toml:"-"`
	Err    error  `toml:"-"`
}

type DockerfileInfo added in v0.15.0

type DockerfileInfo struct {
	ExtensionID string
	Kind        string
	Path        string
	// WithBase if populated indicates that the Dockerfile switches the image base to the provided value.
	// If WithBase is empty, Extend should be true, otherwise there is nothing for the Dockerfile to do.
	// However if WithBase is populated, Extend may be true or false.
	WithBase string
	// Extend if true indicates that the Dockerfile contains image modifications
	// and if false indicates that the Dockerfile only switches the image base.
	// If Extend is false, WithBase should be non-empty, otherwise there is nothing for the Dockerfile to do.
	// However if Extend is true, WithBase may be empty or non-empty.
	Extend bool
	Ignore bool
}

type Error

type Error struct {
	RootError error
	Type      ErrorType
}

func NewError added in v0.13.1

func NewError(cause error, errType ErrorType) *Error

func (*Error) Cause

func (le *Error) Cause() error

func (*Error) Error

func (le *Error) Error() string

type ErrorType

type ErrorType string
const ErrTypeBuildpack ErrorType = "ERR_BUILDPACK"
const ErrTypeFailedDetection ErrorType = "ERR_FAILED_DETECTION"

type ExtDescriptor added in v0.15.0

type ExtDescriptor struct {
	WithAPI     string           `toml:"api"`
	Extension   ExtInfo          `toml:"extension"`
	WithRootDir string           `toml:"-"`
	Targets     []TargetMetadata `toml:"targets"`
}

func ReadExtDescriptor added in v0.15.0

func ReadExtDescriptor(path string) (*ExtDescriptor, error)

func (*ExtDescriptor) API added in v0.15.0

func (d *ExtDescriptor) API() string

func (*ExtDescriptor) ClearEnv added in v0.15.0

func (d *ExtDescriptor) ClearEnv() bool

func (*ExtDescriptor) Homepage added in v0.15.0

func (d *ExtDescriptor) Homepage() string

func (*ExtDescriptor) RootDir added in v0.15.0

func (d *ExtDescriptor) RootDir() string

func (*ExtDescriptor) String added in v0.15.0

func (d *ExtDescriptor) String() string

func (*ExtDescriptor) TargetsList added in v0.17.0

func (d *ExtDescriptor) TargetsList() []TargetMetadata

type ExtInfo added in v0.15.0

type ExtInfo struct {
	BaseInfo
}

type ExtendArg added in v0.15.0

type ExtendArg struct {
	Name  string `toml:"name"`
	Value string `toml:"value"`
}

type ExtendBuildConfig added in v0.15.0

type ExtendBuildConfig struct {
	Args []ExtendArg `toml:"args"`
}

type ExtendConfig added in v0.15.0

type ExtendConfig struct {
	Build ExtendBuildConfig `toml:"build"`
}

type GenerateExecutor added in v0.15.0

type GenerateExecutor interface {
	Generate(d ExtDescriptor, inputs GenerateInputs, logger log.Logger) (GenerateOutputs, error)
}

GenerateExecutor executes a single image extension's `./bin/generate` binary, providing inputs as defined in the Buildpack Interface Specification, and processing outputs for the platform. Pre-populated outputs for image extensions that are missing `./bin/generate` are processed here.

type GenerateInputs added in v0.15.0

type GenerateInputs struct {
	AppDir         string
	BuildConfigDir string
	OutputDir      string // a temp directory provided by the lifecycle to capture extensions output
	PlatformDir    string
	Env            BuildEnv
	TargetEnv      []string
	Out, Err       io.Writer
	Plan           Plan
}

type GenerateOutputs added in v0.15.0

type GenerateOutputs struct {
	Dockerfiles []DockerfileInfo
	Contexts    []extend.ContextInfo
	MetRequires []string
}

type Group

type Group struct {
	Group           []GroupElement `toml:"group"`
	GroupExtensions []GroupElement `toml:"group-extensions,omitempty" json:"group-extensions,omitempty"`
}

func (Group) Append

func (bg Group) Append(group ...Group) Group

func (Group) HasExtensions added in v0.15.0

func (bg Group) HasExtensions() bool

type GroupElement added in v0.15.0

type GroupElement struct {

	// ID specifies the ID of the buildpack or extension.
	ID string `toml:"id" json:"id"`
	// Version specifies the version of the buildpack or extension.
	Version string `toml:"version" json:"version"`

	// API specifies the Buildpack API that the buildpack or extension implements.
	API string `toml:"api,omitempty" json:"-"`
	// Homepage specifies the homepage of the buildpack or extension.
	Homepage string `toml:"homepage,omitempty" json:"homepage,omitempty"`
	// Extension specifies whether the group element is a buildpack or an extension.
	Extension bool `toml:"extension,omitempty" json:"-"`

	// Optional specifies that the buildpack or extension is optional. Extensions are always optional.
	Optional bool `toml:"optional,omitempty" json:"optional,omitempty"`

	// OrderExtensions holds the order for extensions during the detect phase.
	OrderExtensions Order `toml:"-" json:"-"`
}

A GroupElement represents a buildpack referenced in a buildpack.toml's [[order.group]] OR a buildpack or extension in order.toml OR a buildpack or extension in group.toml.

func (GroupElement) Equals added in v0.15.0

func (e GroupElement) Equals(o GroupElement) bool

func (GroupElement) IsExtensionsOrder added in v0.15.0

func (e GroupElement) IsExtensionsOrder() bool

func (GroupElement) Kind added in v0.15.0

func (e GroupElement) Kind() string

func (GroupElement) NoAPI added in v0.15.0

func (e GroupElement) NoAPI() GroupElement

func (GroupElement) NoExtension added in v0.15.0

func (e GroupElement) NoExtension() GroupElement

func (GroupElement) NoHomepage added in v0.15.0

func (e GroupElement) NoHomepage() GroupElement

func (GroupElement) NoOpt added in v0.15.0

func (e GroupElement) NoOpt() GroupElement

func (GroupElement) String added in v0.15.0

func (e GroupElement) String() string

func (GroupElement) WithAPI added in v0.15.0

func (e GroupElement) WithAPI(version string) GroupElement

func (GroupElement) WithHomepage added in v0.15.0

func (e GroupElement) WithHomepage(address string) GroupElement

type Label

type Label struct {
	Key   string `toml:"key"`
	Value string `toml:"value"`
}

type LaunchTOML

type LaunchTOML struct {
	BOM       []BOMEntry
	Labels    []Label
	Processes []ProcessEntry `toml:"processes"`
	Slices    []layers.Slice `toml:"slices"`
}

func (LaunchTOML) ToLaunchProcessesForBuildpack added in v0.15.0

func (lt LaunchTOML) ToLaunchProcessesForBuildpack(bpID string) []launch.Process

converts launch.toml processes to launch.Processes

type Layer added in v0.13.1

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

func (*Layer) HasLocalContents added in v0.13.1

func (l *Layer) HasLocalContents() bool

func (*Layer) Identifier added in v0.13.1

func (l *Layer) Identifier() string

func (*Layer) Name added in v0.13.1

func (l *Layer) Name() string

func (*Layer) Path added in v0.13.1

func (l *Layer) Path() string

func (*Layer) Read added in v0.13.1

func (l *Layer) Read() (LayerMetadata, error)

func (*Layer) Remove added in v0.13.1

func (l *Layer) Remove() error

func (*Layer) WriteMetadata added in v0.13.1

func (l *Layer) WriteMetadata(metadata LayerMetadataFile) error

func (*Layer) WriteSha added in v0.13.1

func (l *Layer) WriteSha(sha string) error

type LayerMetadata added in v0.13.1

type LayerMetadata struct {
	SHA string `json:"sha" toml:"sha"`
	LayerMetadataFile
}

type LayerMetadataFile added in v0.13.1

type LayerMetadataFile struct {
	Data   interface{} `json:"data" toml:"metadata"`
	Build  bool        `json:"build" toml:"build"`
	Launch bool        `json:"launch" toml:"launch"`
	Cache  bool        `json:"cache" toml:"cache"`
}

func DecodeLayerMetadataFile

func DecodeLayerMetadataFile(path string, buildpackAPI string, logger log.Logger) (LayerMetadataFile, error)

type LayerType added in v0.13.0

type LayerType int
const (
	LayerTypeBuild LayerType = iota
	LayerTypeCache
	LayerTypeLaunch
)

type LayersDir added in v0.13.1

type LayersDir struct {
	Path string

	Buildpack GroupElement
	Store     *StoreTOML
	// contains filtered or unexported fields
}

func ReadLayersDir added in v0.13.1

func ReadLayersDir(layersDir string, bp GroupElement, logger log.Logger) (LayersDir, error)

func (*LayersDir) FindLayers added in v0.13.1

func (d *LayersDir) FindLayers(f func(layer Layer) bool) []Layer

func (*LayersDir) NewLayer added in v0.13.1

func (d *LayersDir) NewLayer(name, buildpackAPI string, logger log.Logger) *Layer

type LayersMetadata added in v0.13.1

type LayersMetadata struct {
	ID      string                   `json:"key" toml:"key"`
	Version string                   `json:"version" toml:"version"`
	Layers  map[string]LayerMetadata `json:"layers" toml:"layers"`
	Store   *StoreTOML               `json:"store,omitempty" toml:"store"`
}

type OSDistro added in v0.17.0

type OSDistro struct {
	Name    string `json:"name" toml:"name"`
	Version string `json:"version" toml:"version"`
}

OSDistro is an OS distribution that a buildpack or extension can support.

type Order

type Order []Group

type Plan

type Plan struct {
	Entries []Require `toml:"entries"`
}

type PlanSections

type PlanSections struct {
	Requires []Require `toml:"requires"`
	Provides []Provide `toml:"provides"`
}

type ProcessEntry added in v0.15.0

type ProcessEntry struct {
	Type             string         `toml:"type" json:"type"`
	Command          []string       `toml:"-"` // ignored
	RawCommandValue  toml.Primitive `toml:"command" json:"command"`
	Args             []string       `toml:"args" json:"args"`
	Direct           *bool          `toml:"direct" json:"direct"`
	Default          bool           `toml:"default,omitempty" json:"default,omitempty"`
	WorkingDirectory string         `toml:"working-dir,omitempty" json:"working-dir,omitempty"`
}

func (*ProcessEntry) ToLaunchProcess added in v0.15.0

func (p *ProcessEntry) ToLaunchProcess(bpID string) launch.Process

ToLaunchProcess converts a buildpack.ProcessEntry to a launch.Process

type Provide

type Provide struct {
	Name string `toml:"name"`
}

type Require

type Require struct {
	Name     string                 `toml:"name" json:"name"`
	Version  string                 `toml:"version,omitempty" json:"version,omitempty"`
	Metadata map[string]interface{} `toml:"metadata" json:"metadata"`
}

type StackMetadata added in v0.17.0

type StackMetadata struct {
	ID string `toml:"id"`
}

type StoreTOML

type StoreTOML struct {
	Data map[string]interface{} `json:"metadata" toml:"metadata"`
}

type TargetMetadata added in v0.17.0

type TargetMetadata struct {
	OS          string     `json:"os" toml:"os"`
	Arch        string     `json:"arch" toml:"arch"`
	ArchVariant string     `json:"arch-variant,omitempty" toml:"arch-variant"`
	Distros     []OSDistro `json:"distros,omitempty" toml:"distros"`
}

func (*TargetMetadata) String added in v0.17.0

func (t *TargetMetadata) String() string

type Unmet

type Unmet struct {
	Name string `toml:"name"`
}

Directories

Path Synopsis
Package testmock is a generated GoMock package.
Package testmock is a generated GoMock package.

Jump to

Keyboard shortcuts

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