libcnb

package module
v2.0.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: Apache-2.0 Imports: 13 Imported by: 14

README

github.com/buildpacks/libcnb

Go Reference

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

For operations such as building an app, creating a builder or packaging a buildpack, you may use pack as a Go library.

Usage

Installation
go get github.com/buildpacks/libcnb

or for the v2 alpha

go get github.com/buildpacks/libcnb@v2.0.0-alpha.1
Docs

https://pkg.go.dev/github.com/buildpacks/libcnb?tab=doc

License

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

Documentation

Index

Examples

Constants

View Source
const (
	// MinSupportedBPVersion indicates the minium supported version of the Buildpacks API
	MinSupportedBPVersion = "0.8"

	// MaxSupportedBPVersion indicates the maximum supported version of the Buildpacks API
	MaxSupportedBPVersion = "0.9"
)

Constants to track minimum and maximum supported Buildpack API versions

View Source
const (
	BOMFormatCycloneDXExtension = "cdx.json"
	BOMFormatSPDXExtension      = "spdx.json"
	BOMFormatSyftExtension      = "syft.json"
	BOMMediaTypeCycloneDX       = "application/vnd.cyclonedx+json"
	BOMMediaTypeSPDX            = "application/spdx+json"
	BOMMediaTypeSyft            = "application/vnd.syft+json"
	BOMUnknown                  = "unknown"
)
View Source
const (
	// BindingProvider is the key for a binding's provider.
	BindingProvider = "provider"

	// BindingType is the key for a binding's type.
	BindingType = "type"

	// EnvServiceBindings is the name of the environment variable that contains the path to service bindings directory.
	//
	// See the Service Binding Specification for Kubernetes for more details - https://k8s-service-bindings.github.io/spec/
	EnvServiceBindings = "SERVICE_BINDING_ROOT"

	// EnvBuildpackDirectory is the name of the environment variable that contains the path to the buildpack
	EnvBuildpackDirectory = "CNB_BUILDPACK_DIR"

	// EnvExtensionDirectory is the name of the environment variable that contains the path to the extension
	EnvExtensionDirectory = "CNB_EXTENSION_DIR"

	// EnvVcapServices is the name of the environment variable that contains the bindings in cloudfoundry
	EnvVcapServices = "VCAP_SERVICES"

	// EnvLayersDirectory is the name of the environment variable that contains the root path to all buildpack layers
	EnvLayersDirectory = "CNB_LAYERS_DIR"

	// EnvOutputDirectory is the name of the environment variable that contains the path to the output directory
	EnvOutputDirectory = "CNB_OUTPUT_DIR"

	// EnvPlatformDirectory is the name of the environment variable that contains the path to the platform directory
	EnvPlatformDirectory = "CNB_PLATFORM_DIR"

	// EnvDetectBuildPlanPath is the name of the environment variable that contains the path to the build plan
	EnvDetectPlanPath = "CNB_BUILD_PLAN_PATH"

	// EnvBuildPlanPath is the name of the environment variable that contains the path to the build plan
	EnvBuildPlanPath = "CNB_BP_PLAN_PATH"

	// EnvStackID is the name of the environment variable that contains the stack id
	EnvStackID = "CNB_STACK_ID"

	// DefaultPlatformBindingsLocation is the typical location for bindings, which exists under the platform directory
	//
	// Not guaranteed to exist, but often does. This should only be used as a fallback if EnvServiceBindings and EnvPlatformDirectory are not set
	DefaultPlatformBindingsLocation = "/platform/bindings"
)

Variables

This section is empty.

Functions

func Build

func Build(build BuildFunc, config Config)

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

Example
package main

import (
	"os"
	"path/filepath"

	cdx "github.com/CycloneDX/cyclonedx-go"

	"github.com/buildpacks/libcnb/v2"
	"github.com/buildpacks/libcnb/v2/log"
)

const (
	DefaultVersion = "0.1"
)

type Builder struct {
	Logger log.Logger
}

// BuildpackPlan may contain multiple entries for a single buildpack, resolve
// into a single entry.
func resolve(plan libcnb.BuildpackPlan, name string) libcnb.BuildpackPlanEntry {
	entry := libcnb.BuildpackPlanEntry{
		Name:     name,
		Metadata: map[string]interface{}{},
	}
	for _, e := range plan.Entries {
		for k, v := range e.Metadata {
			entry.Metadata[k] = v
		}
	}
	return entry
}

func populateLayer(layer libcnb.Layer, version string) (libcnb.Layer, error) {
	exampleFile := filepath.Join(layer.Path, "example.txt")
	os.WriteFile(exampleFile, []byte(version), 0600)
	layer.SharedEnvironment.Default("EXAMPLE_FILE", exampleFile)

	// Provide an SBOM
	bom := cdx.NewBOM()
	bom.Metadata = &cdx.Metadata{
		Component: &cdx.Component{
			Type:    cdx.ComponentTypeFile,
			Name:    "example",
			Version: version,
		},
	}
	sbomPath := layer.SBOMPath(libcnb.CycloneDXJSON)
	sbomFile, err := os.OpenFile(sbomPath, os.O_CREATE|os.O_WRONLY, 0600)
	if err != nil {
		return layer, err
	}
	defer sbomFile.Close()
	encoder := cdx.NewBOMEncoder(sbomFile, cdx.BOMFileFormatJSON)
	if err := encoder.Encode(bom); err != nil {
		return layer, err
	}
	return layer, nil
}

func (b Builder) Build(context libcnb.BuildContext) (libcnb.BuildResult, error) {
	// Reduce possible multiple buildpack plan entries to a single entry
	entry := resolve(context.Plan, Provides)
	result := libcnb.NewBuildResult()

	// Read metadata from the buildpack plan, often contributed by libcnb.Requires
	// of the Detect phase
	version := DefaultVersion
	if v, ok := entry.Metadata["version"].(string); ok {
		version = v
	}

	// Create a layer
	layer, err := context.Layers.Layer("example")
	if err != nil {
		return result, err
	}
	layer.LayerTypes = libcnb.LayerTypes{
		Launch: true,
		Build:  true,
		Cache:  true,
	}

	layer, err = populateLayer(layer, version)
	if err != nil {
		return result, nil
	}

	result.Layers = append(result.Layers, layer)
	return result, nil
}

func main() {
	detector := Detector{log.New(os.Stdout)}
	builder := Builder{log.New(os.Stdout)}
	libcnb.BuildpackMain(detector.Detect, builder.Build)
}
Output:

func BuildpackMain

func BuildpackMain(detect DetectFunc, build BuildFunc, options ...Option)

BuildpackMain is called by the main function of a buildpack, encapsulating both detection and build in the same binary.

func Detect

func Detect(detect DetectFunc, config Config)

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

Example
package main

import (
	"errors"
	"os"
	"path/filepath"

	"github.com/buildpacks/libcnb/v2"
	"github.com/buildpacks/libcnb/v2/log"
)

const (
	Provides         = "example"
	BpExampleVersion = "BP_EXAMPLE_VERSION"
)

type Detector struct {
	Logger log.Logger
}

func (Detector) Detect(context libcnb.DetectContext) (libcnb.DetectResult, error) {
	version := "1.0"
	// Scan the application source folder to see if the example buildpack is
	// required.  If `version.toml` does not exist we return a failed DetectResult
	// but no runtime error has occurred, so we return an empty error.
	versionPath := filepath.Join(context.ApplicationPath, "version.toml")
	if _, err := os.Open(versionPath); errors.Is(err, os.ErrNotExist) {
		return libcnb.DetectResult{}, nil
	}
	// Read the version number from the buildpack definition
	if exampleVersion, exists := context.Buildpack.Metadata["version"]; exists {
		version = exampleVersion.(string)
	}
	// Accept version number from the environment if the user provides it
	if exampleVersion, exists := context.Platform.Environment[BpExampleVersion]; exists {
		version = exampleVersion
	}
	metadata := map[string]interface{}{
		"version": version,
	}
	return libcnb.DetectResult{
		Pass: true,
		Plans: []libcnb.BuildPlan{
			{
				// Let the system know that if other buildpacks Require "example"
				// then this buildpack Provides the implementation logic.
				Provides: []libcnb.BuildPlanProvide{
					{Name: Provides},
				},
				// It is common for a buildpack to Require itself if the build phase
				// needs information from the detect phase. Here we pass the version number
				// as metadata to the build phase.
				Requires: []libcnb.BuildPlanRequire{
					{
						Name:     Provides,
						Metadata: metadata,
					},
				},
			},
		},
	}, nil
}

func main() {
	detector := Detector{log.New(os.Stdout)}
	libcnb.BuildpackMain(detector.Detect, nil)
}
Output:

func ExtensionMain

func ExtensionMain(detect DetectFunc, generate GenerateFunc, options ...Option)

ExtensionMain is called by the main function of a extension, encapsulating both detection and generation in the same binary.

func Generate

func Generate(generate GenerateFunc, config Config)

Generate is called by the main function of a extension, for generate phase

Example
package main

import (
	"fmt"
	"os"

	"github.com/buildpacks/libcnb/v2"
	"github.com/buildpacks/libcnb/v2/log"
)

type Generator struct {
	Logger log.Logger
}

func (Generator) Generate(context libcnb.GenerateContext) (libcnb.GenerateResult, error) {
	// here you can read the context.ApplicationPath folder
	// and create run.Dockerfile and build.Dockerfile in the context.OutputPath folder
	// and read metadata from the context.Extension struct

	// Just to use context to keep compiler happy =)
	fmt.Println(context.Extension.Info.ID)

	result := libcnb.NewGenerateResult()
	return result, nil
}

func main() {
	generator := Generator{log.New(os.Stdout)}
	libcnb.ExtensionMain(nil, generator.Generate)
}
Output:

func RunExecD

func RunExecD(execDMap map[string]ExecD, options ...Option)

RunExecD is called by the main function of a buildpack's execd binary, encompassing multiple execd executors in one binary.

Types

type Binding

type Binding struct {

	// Name is the name of the binding
	Name string

	// Path is the path to the binding directory.
	Path string

	// Type is the type of the binding.
	Type string

	// Provider is the optional provider of the binding.
	Provider string

	// Secret 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, path string, secret map[string]string) Binding

NewBinding creates a new Binding initialized with a secret.

func NewBindingFromPath

func NewBindingFromPath(path string) (Binding, error)

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

func (Binding) SecretFilePath

func (b Binding) SecretFilePath(name string) (string, bool)

SecretFilePath return the path to a secret file with the given name.

func (Binding) String

func (b Binding) String() string

type Bindings

type Bindings []Binding

Bindings is a collection of bindings keyed by their name.

func NewBindings

func NewBindings(platformDir string) (Bindings, error)

NewBindings creates a new bindings from all the bindings at the path defined by $SERVICE_BINDING_ROOT. If that isn't defined, bindings are read from <platform>/bindings. If that isn't defined, bindings are read from $VCAP_SERVICES. If that isn't defined, the specified platform path will be used

func NewBindingsFromPath

func NewBindingsFromPath(path string) (Bindings, error)

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

func NewBindingsFromVcapServicesEnv

func NewBindingsFromVcapServicesEnv(content string) (Bindings, error)

NewBindingsFromVcapServicesEnv creates a new instance from all the bindings given from the VCAP_SERVICES.

type BuildContext

type BuildContext struct {
	// ApplicationPath is the location of the application source code as provided by
	// the lifecycle.
	ApplicationPath string

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

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

	// Logger is the way to write messages to the end user
	Logger log.Logger

	// 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 BuildFunc

type BuildFunc func(context BuildContext) (BuildResult, error)

BuildFunc takes a context and returns a result, performing buildpack build behaviors.

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"`

	// 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 {
	// Labels are the image labels contributed by the buildpack.
	Labels []Label

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

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

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

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

	// Unmet contains buildpack plan entries that were not satisfied by the buildpack and therefore should be
	// passed to subsequent providers.
	Unmet []UnmetPlanEntry
}

BuildResult contains the results of detection.

func NewBuildResult

func NewBuildResult() BuildResult

NewBuildResult creates a new BuildResult instance, initializing empty fields.

func (BuildResult) String

func (b BuildResult) String() string

type BuildTOML

type BuildTOML struct {
	// Unmet is a collection of buildpack plan entries that should be passed through to subsequent providers.
	Unmet []UnmetPlanEntry
}

BuildTOML represents the contents of build.toml.

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"`

	// Path is the path to the buildpack.
	Path string `toml:"-"`

	// 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 `toml:"id"`

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

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

	// Homepage is the homepage of the buildpack.
	Homepage string `toml:"homepage"`

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

	// Description is a string describing the buildpack.
	Description string `toml:"description"`

	// Keywords is a list of words that are associated with the buildpack.
	Keywords []string `toml:"keywords"`

	// Licenses a list of buildpack licenses.
	Licenses []License `toml:"licenses"`

	// SBOM is the list of supported SBOM media types
	SBOMFormats []string `toml:"sbom-formats"`
}

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 BuildpackPlan

type BuildpackPlan struct {

	// Entries represents all 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"`

	// 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.

func NewConfig

func NewConfig(options ...Option) Config

NewConfig will generate a config from the given set of options

type DetectContext

type DetectContext struct {

	// ApplicationPath is the location of the application source code as provided by
	// the lifecycle.
	ApplicationPath string

	// Buildpack is metadata about the buildpack from buildpack.toml (empty when processing an extension)
	Buildpack Buildpack

	// Extension is metadata about the extension from extension.toml (empty when processing a buildpack)
	Extension Extension

	// Logger is the way to write messages to the end user
	Logger log.Logger

	// 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 DetectFunc

type DetectFunc func(context DetectContext) (DetectResult, error)

DetectFunc takes a context and returns a result, performing buildpack detect behaviors.

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 Environment

type Environment map[string]string

Environment represents the file-based environment variable specification.

func (Environment) Append

func (e Environment) Append(name string, delimiter 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

func (e Environment) Appendf(name string, delimiter 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

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) 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

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, delimiter 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) Prependf

func (e Environment) Prependf(name string, delimiter 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.

func (Environment) ProcessAppend

func (e Environment) ProcessAppend(processType string, name string, delimiter string, a ...interface{})

ProcessAppend 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) ProcessAppendf

func (e Environment) ProcessAppendf(processType string, name string, delimiter string, format string, a ...interface{})

ProcessAppendf 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) ProcessDefault

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

ProcessDefault 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) ProcessDefaultf

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

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

func (Environment) ProcessOverride

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

ProcessOverride 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) ProcessOverridef

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

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

func (Environment) ProcessPrepend

func (e Environment) ProcessPrepend(processType string, name string, delimiter string, a ...interface{})

ProcessPrepend 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) ProcessPrependf

func (e Environment) ProcessPrependf(processType string, name string, delimiter string, format string, a ...interface{})

ProcessPrependf 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 Exec

type Exec struct {
	// Path is the path to the exec.d directory.
	Path string
}

Exec represents the exec.d layer location

func (Exec) FilePath

func (e Exec) FilePath(name string) string

FilePath returns the fully qualified file path for a given name.

func (Exec) ProcessFilePath

func (e Exec) ProcessFilePath(processType string, name string) string

ProcessFilePath returns the fully qualified file path for a given name.

type ExecD

type ExecD interface {
	Execute() (map[string]string, error)
}

ExecD describes an interface for types that follow the Exec.d specification. It should return a map of environment variables and their values as output.

type ExecDWriter

type ExecDWriter interface {

	// Write is called with the map of environment value key value
	// pairs that will be written out
	Write(value map[string]string) error
}

ExecDWriter is the interface implemented by a type that wants to write exec.d output to file descriptor 3.

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 Extension

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

	// Info is information about the extension.
	Info ExtensionInfo `toml:"extension"`

	// Path is the path to the extension.
	Path string `toml:"-"`

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

Extension is the contents of the extension.toml file.

type ExtensionInfo

type ExtensionInfo struct {
	// ID is the ID of the extension.
	ID string `toml:"id"`

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

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

	// Homepage is the homepage of the extension.
	Homepage string `toml:"homepage"`

	// Description is a string describing the extension.
	Description string `toml:"description"`

	// Keywords is a list of words that are associated with the extension.
	Keywords []string `toml:"keywords"`

	// Licenses a list of extension licenses.
	Licenses []License `toml:"licenses"`
}

ExtensionInfo is information about the extension.

type GenerateContext

type GenerateContext struct {
	// ApplicationPath is the location of the application source code as provided by
	// the lifecycle.
	ApplicationPath string

	// Extension is metadata about the extension, from extension.toml.
	Extension Extension

	// OutputDirectory is the location Dockerfiles should be written to.
	OutputDirectory string

	// Logger is the way to write messages to the end user
	Logger log.Logger

	// 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
}

GenerateContext contains the inputs to generate.

type GenerateFunc

type GenerateFunc func(context GenerateContext) (GenerateResult, error)

BuildFunc takes a context and returns a result, performing extension generate behaviors.

type GenerateResult

type GenerateResult struct {
	// Unmet contains buildpack plan entries that were not satisfied by the buildpack and therefore should be
	// passed to subsequent providers.
	Unmet []UnmetPlanEntry
}

GenerateResult contains the results of detection.

func NewGenerateResult

func NewGenerateResult() GenerateResult

NewBuildResult creates a new BuildResult instance, initializing empty fields.

func (GenerateResult) String

func (b GenerateResult) String() string

type Label

type Label struct {
	// Key is the key of the label.
	Key string `toml:"key"`

	// Value is the value of the label.
	Value string `toml:"value"`
}

Label represents an image label.

type LaunchTOML

type LaunchTOML struct {
	// Labels is the collection of image labels contributed by the buildpack.
	Labels []Label `toml:"labels"`

	// 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"`
}

LaunchTOML represents the contents of launch.toml.

type Layer

type Layer struct {
	// LayerTypes indicates the type of layer
	LayerTypes `toml:"types"`

	// 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:"-"`

	// Exec is the exec.d executables set in the layer.
	Exec Exec `toml:"-"`
}

Contribute represents a layer managed by the buildpack.

func (Layer) Reset

func (l Layer) Reset() (Layer, error)

func (Layer) SBOMPath

func (l Layer) SBOMPath(bt SBOMFormat) string

SBOMPath returns the path to the layer specific SBOM File

type LayerTypes

type LayerTypes 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"`
}

LayerTypes describes which types apply to a given layer. A layer may have any combination of Launch, Build, and Cache types.

type Layers

type Layers struct {
	// Path is the layers filesystem location.
	Path string
}

Layers represents the layers part of the specification.

func (Layers) BuildSBOMPath

func (l Layers) BuildSBOMPath(bt SBOMFormat) string

BOMBuildPath returns the full path to the build SBoM file for the buildpack

func (Layers) LaunchSBOMPath

func (l Layers) LaunchSBOMPath(bt SBOMFormat) string

BOMLaunchPath returns the full path to the launch SBoM file for the buildpack

func (*Layers) Layer

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

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

type License

type License struct {
	// Type is the identifier for the license.
	// It MAY use the SPDX 2.1 license expression, but is not limited to identifiers in the SPDX Licenses List.
	Type string `toml:"type"`

	// URI may be specified in lieu of or in addition to type to point to the license
	// if this buildpack is using a nonstandard license.
	URI string `toml:"uri"`
}

License contains information about a Software License governing the use or redistribution of a buildpack

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 WithDirectoryContentFormatter

func WithDirectoryContentFormatter(formatter log.DirectoryContentFormatter) Option

WithDirectoryContentFormatter creates an Option that sets a ExecDWriter implementation.

func WithEnvironmentWriter

func WithEnvironmentWriter(environmentWriter EnvironmentWriter) Option

WithEnvironmentWriter creates an Option that sets an EnvironmentWriter implementation.

func WithExecDWriter

func WithExecDWriter(execdWriter ExecDWriter) Option

WithExecDWriter creates an Option that sets a ExecDWriter implementation.

func WithExitHandler

func WithExitHandler(exitHandler ExitHandler) Option

WithExitHandler creates an Option that sets an ExitHandler implementation.

func WithLogger

func WithLogger(logger log.Logger) Option

WithLogger creates an Option that sets a ExecDWriter 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 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"`

	// WorkingDirectory is a directory to execute the command in, removes the need to use a shell environment to CD into working directory
	WorkingDirectory string `toml:"working-directory,omitempty"`

	// Default can be set to true to indicate that the process
	// type being defined should be the default process type for the app image.
	Default bool `toml:"default,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

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.

func (Profile) ProcessAdd

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

ProcessAdd 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) ProcessAddf

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

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

type SBOMFormat

type SBOMFormat int

BOMFormat indicates the format of the SBOM entry

const (
	CycloneDXJSON SBOMFormat = iota
	SPDXJSON
	SyftJSON
	UnknownFormat
)

func SBOMFormatFromString

func SBOMFormatFromString(from string) (SBOMFormat, error)

func (SBOMFormat) MediaType

func (b SBOMFormat) MediaType() string

func (SBOMFormat) String

func (b SBOMFormat) String() string

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.

type UnmetPlanEntry

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

UnmetPlanEntry denotes an unmet buildpack plan entry. When a buildpack returns an UnmetPlanEntry in the BuildResult, any BuildpackPlanEntry with a matching Name will be provided to subsequent providers.

Directories

Path Synopsis
log

Jump to

Keyboard shortcuts

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