phase

package
v0.20.4 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: Apache-2.0 Imports: 39 Imported by: 2

Documentation

Overview

Package phase handles logic internal to the CNB lifecycle, and roughly corresponds to the actions denoted by "the lifecycle MUST" and "the lifecycle SHALL" in the Platform Interface Specification.

Index

Constants

View Source
const (
	CodeDetectPass = 0
	CodeDetectFail = 100
)
View Source
const RebasableLabel = "io.buildpacks.rebasable"

Variables

View Source
var (
	ErrFailedDetection = errors.New("no buildpacks participating")
	ErrBuildpack       = errors.New("buildpack(s) failed with err")
)

Functions

func PrependExtensions

func PrependExtensions(orderBp buildpack.Order, orderExt buildpack.Order) buildpack.Order

func SBOMExtensions

func SBOMExtensions() []string

func TruncateSha

func TruncateSha(sha string) string

Types

type Analyzer

type Analyzer struct {
	PreviousImage imgutil.Image
	RunImage      imgutil.Image
	Logger        log.Logger
	SBOMRestorer  layer.SBOMRestorer
	PlatformAPI   *api.Version
}

Analyzer reads metadata from the previous image (if it exists) and the run image, and additionally restores the SBOM layer from the previous image for use later in the build.

func (*Analyzer) Analyze

func (a *Analyzer) Analyze() (files.Analyzed, error)

Analyze fetches the layers metadata from the previous image and writes analyzed.toml.

type BuildEnv

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

BuildEnv encapsulates modifications that the lifecycle can make to buildpacks' build environment.

type Builder

type Builder struct {
	AppDir         string
	BuildConfigDir string
	LayersDir      string
	PlatformDir    string
	BuildExecutor  buildpack.BuildExecutor
	DirStore       DirStore
	Group          buildpack.Group
	Logger         log.Logger
	Out, Err       io.Writer
	Plan           files.Plan
	PlatformAPI    *api.Version
	AnalyzeMD      files.Analyzed
}

func (*Builder) Build

func (b *Builder) Build() (*files.BuildMetadata, error)

type BuildpackAPIVerifier

type BuildpackAPIVerifier interface {
	VerifyBuildpackAPI(kind, name, requestedVersion string, logger log.Logger) error
}

BuildpackAPIVerifier verifies a requested Buildpack API version.

type Cache

type Cache interface {
	Exists() bool
	Name() string
	SetMetadata(metadata platform.CacheMetadata) error
	RetrieveMetadata() (platform.CacheMetadata, error)
	AddLayerFile(tarPath string, sha string) error
	ReuseLayer(sha string) error
	RetrieveLayer(sha string) (io.ReadCloser, error)
	Commit() error
	VerifyLayer(sha string) error
}

type CacheHandler

type CacheHandler interface {
	InitCache(imageRef, dir string, deletionEnabled bool) (Cache, error)
}

CacheHandler wraps initialization of a cache image or cache volume.

type ConfigHandler

type ConfigHandler interface {
	ReadAnalyzed(path string, logger log.Logger) (files.Analyzed, error)
	ReadGroup(path string) (buildpack.Group, error)
	ReadOrder(path string) (buildpack.Order, buildpack.Order, error)
	ReadRun(runPath string, logger log.Logger) (files.Run, error)
	ReadPlan(path string) (files.Plan, error)
}

ConfigHandler reads configuration files for the lifecycle.

type ConnectedFactory

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

ConnectedFactory is used to construct lifecycle phases that require access to an image repository (registry, layout directory, or docker daemon) and/or a cache.

func NewConnectedFactory

func NewConnectedFactory(
	platformAPI *api.Version,
	apiVerifier BuildpackAPIVerifier,
	cacheHandler CacheHandler,
	configHandler ConfigHandler,
	imageHandler image.Handler,
	registryHandler image.RegistryHandler,
) *ConnectedFactory

NewConnectedFactory constructs a new ConnectedFactory.

func (*ConnectedFactory) NewAnalyzer

func (f *ConnectedFactory) NewAnalyzer(inputs platform.LifecycleInputs, logger log.Logger) (*Analyzer, error)

NewAnalyzer configures a new Analyzer according to the provided Platform API version.

type DefaultDetectResolver

type DefaultDetectResolver struct {
	Logger log.Logger
}

func NewDefaultDetectResolver

func NewDefaultDetectResolver(logger log.Logger) *DefaultDetectResolver

func (*DefaultDetectResolver) Resolve

Resolve aggregates the detect output for a group of buildpacks and tries to resolve a build plan for the group. If any required buildpack in the group failed detection or a build plan cannot be resolved, it returns an error.

type DetectResolver

type DetectResolver interface {
	Resolve(done []buildpack.GroupElement, detectRuns *sync.Map) ([]buildpack.GroupElement, []files.BuildPlanEntry, error)
}

DetectResolver given a group of buildpacks (and optional image extensions) processes the outputs of each `./bin/detect` to determine if the group is viable - that is, whether all non-optional buildpacks passed detection and a valid Build Plan can be resolved from each "requires" and "provides" expressed by each group element.

type Detector

type Detector struct {
	AppDir         string
	BuildConfigDir string
	DirStore       DirStore
	Executor       buildpack.DetectExecutor
	HasExtensions  bool
	Logger         log.LoggerHandlerWithLevel
	Order          buildpack.Order
	PlatformDir    string
	Resolver       DetectResolver
	Runs           *sync.Map
	AnalyzeMD      files.Analyzed
	PlatformAPI    *api.Version
	// contains filtered or unexported fields
}

func (*Detector) Detect

func (d *Detector) Detect() (buildpack.Group, files.Plan, error)

func (*Detector) DetectOrder

func (d *Detector) DetectOrder(order buildpack.Order) (buildpack.Group, files.Plan, error)

type DirStore

type DirStore interface {
	Lookup(kind, id, version string) (buildpack.Descriptor, error)
	LookupBp(id, version string) (*buildpack.BpDescriptor, error)
	LookupExt(id, version string) (*buildpack.ExtDescriptor, error)
}

DirStore is a repository of buildpacks and/or image extensions. Each element should be present on disk according to the format outlined in the Platform Interface Specification, namely: `/cnb/<buildpacks|extensions>/<id>/<version>/<root directory>`.

type DockerfileApplier

type DockerfileApplier interface {
	ImageFor(reference string) (v1.Image, error)
	Apply(dockerfile extend.Dockerfile, toBaseImage v1.Image, withBuildOptions extend.Options, logger log.Logger) (v1.Image, error)
	Cleanup() error
}

DockerfileApplier given a base image and a `build.Dockerfile` or `run.Dockerfile` will apply it to the base image and return a new image, or an error if encountered.

type ExportOptions

type ExportOptions struct {
	// WorkingImage is the image to save.
	WorkingImage imgutil.Image
	// AdditionalNames are additional tags to save to, besides WorkingImage.Name().
	AdditionalNames []string
	// ExtendedDir is the location of extension-provided layers.
	ExtendedDir string
	// AppDir is the source directory.
	AppDir string
	// LayersDir is the location of buildpack-provided layers.
	LayersDir string
	// OrigMetadata was read from the previous image during the `analyze` phase, and is used to determine if a previously-uploaded layer can be re-used.
	OrigMetadata files.LayersMetadata
	// LauncherConfig is the launcher config.
	LauncherConfig LauncherConfig
	// DefaultProcessType is the user-provided default process type.
	DefaultProcessType string
	// RunImageRef is the run image reference for the layer metadata label.
	RunImageRef string
	// RunImageForExport is run image metadata for the layer metadata label for Platform API >= 0.12.
	RunImageForExport files.RunImageForExport
	// Project is project metadata for the project metadata label.
	Project files.ProjectMetadata
}

type Exporter

type Exporter struct {
	Buildpacks   []buildpack.GroupElement
	LayerFactory LayerFactory
	Logger       log.Logger
	PlatformAPI  *api.Version
}

func (*Exporter) Cache

func (e *Exporter) Cache(layersDir string, cacheStore Cache) error

func (*Exporter) Export

func (e *Exporter) Export(opts ExportOptions) (files.Report, error)

type Extender

type Extender struct {
	AppDir       string // explicitly ignored by the Dockerfile applier, also the Dockefile build context
	ExtendedDir  string // output directory for extended image layers
	GeneratedDir string // input Dockerfiles are found here
	ImageRef     string // the image to extend
	LayersDir    string // explicitly ignored by the Dockerfile applier
	PlatformDir  string // explicitly ignored by the Dockerfile applier

	CacheTTL          time.Duration            // a platform input
	DockerfileApplier DockerfileApplier        // uses kaniko, BuildKit, or other to apply the provided Dockerfile to the provided image
	Extensions        []buildpack.GroupElement // extensions are ordered from group.toml

	PlatformAPI *api.Version
}

func (*Extender) Extend

func (e *Extender) Extend(kind string, logger log.Logger) error

type GenerateResult

type GenerateResult struct {
	AnalyzedMD files.Analyzed
	Plan       files.Plan
}

type Generator

type Generator struct {
	AppDir         string
	BuildConfigDir string
	GeneratedDir   string // e.g., <layers>/generated
	PlatformAPI    *api.Version
	PlatformDir    string
	AnalyzedMD     files.Analyzed
	DirStore       DirStore
	Executor       buildpack.GenerateExecutor
	Extensions     []buildpack.GroupElement
	Logger         log.Logger
	Out, Err       io.Writer
	Plan           files.Plan
	RunMetadata    files.Run
}

func (*Generator) Generate

func (g *Generator) Generate() (GenerateResult, error)

type HermeticFactory

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

HermeticFactory is used to construct lifecycle phases that do NOT require access to an image repository.

func NewHermeticFactory

func NewHermeticFactory(
	platformAPI *api.Version,
	apiVerifier BuildpackAPIVerifier,
	configHandler ConfigHandler,
	dirStore DirStore,
) *HermeticFactory

NewHermeticFactory is used to construct a new HermeticFactory.

func (*HermeticFactory) NewDetector

NewDetector constructs a new Detector by initializing services and reading the provided analyzed and order files.

func (*HermeticFactory) NewExtender

func (f *HermeticFactory) NewExtender(inputs platform.LifecycleInputs, dockerfileApplier DockerfileApplier, logger log.Logger) (*Extender, error)

NewExtender constructs a new Extender by initializing services and reading the provided analyzed and group files to determine the image to extend and the extensions to use.

func (*HermeticFactory) NewGenerator

func (f *HermeticFactory) NewGenerator(inputs platform.LifecycleInputs, stdout, stderr io.Writer, logger log.Logger) (*Generator, error)

NewGenerator constructs a new Generator by initializing services and reading the provided analyzed, group, plan, and run files.

type LauncherConfig

type LauncherConfig struct {
	Path     string
	SBOMDir  string
	Metadata files.LauncherMetadata
}

type LayerDir

type LayerDir interface {
	Identifier() string
	Path() string
}

type LayerFactory

type LayerFactory interface {
	DirLayer(id string, dir string, createdBy string) (layers.Layer, error)
	LauncherLayer(path string) (layers.Layer, error)
	ProcessTypesLayer(metadata launch.Metadata) (layers.Layer, error)
	SliceLayers(dir string, slices []layers.Slice) ([]layers.Layer, error)
	TarLayer(withID string, fromTarPath string, createdBy string) (layer layers.Layer, err error)
}

LayerFactory given a directory on the local filesystem will return a `layers.Layer` that can be used to construct an OCI image.

type MultiError

type MultiError struct {
	Errors []error
}

func (*MultiError) Error

func (me *MultiError) Error() string

type Platform

type Platform interface {
	API() *api.Version
}

type Rebaser

type Rebaser struct {
	Logger      log.Logger
	PlatformAPI *api.Version
	Force       bool
}

func (*Rebaser) Rebase

func (r *Rebaser) Rebase(workingImage imgutil.Image, newBaseImage imgutil.Image, outputImageRef string, additionalNames []string) (files.RebaseReport, error)

Rebase changes the underlying base image for an application image.

type Restorer

type Restorer struct {
	LayersDir string
	Logger    log.Logger

	Buildpacks            []buildpack.GroupElement
	LayerMetadataRestorer layer.MetadataRestorer
	LayersMetadata        files.LayersMetadata
	PlatformAPI           *api.Version
	SBOMRestorer          layer.SBOMRestorer
}

func (*Restorer) Restore

func (r *Restorer) Restore(cache Cache) error

Restore restores metadata for launch and cache layers into the layers directory and attempts to restore layer data for cache=true layers, removing the layer when unsuccessful. If a usable cache is not provided, Restore will not restore any cache=true layer metadata.

Directories

Path Synopsis
Package testmock is a generated GoMock package.
Package testmock is a generated GoMock package.
auth
Package testmockauth is a generated GoMock package.
Package testmockauth is a generated GoMock package.
cache
Package testmockcache is a generated GoMock package.
Package testmockcache is a generated GoMock package.

Jump to

Keyboard shortcuts

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