lifecycle

package module
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2020 License: Apache-2.0 Imports: 25 Imported by: 0

README

Lifecycle

Build Status GoDoc

A reference implementation of the Cloud Native Buildpacks specification.

Supported APIs

Lifecycle Version Platform APIs Buildpack APIs
0.9.x 0.3, 0.4 0.2, 0.3, 0.4
0.8.x 0.3 0.2
0.7.x 0.2 0.2
0.6.x 0.2 0.2

Commands

Build

Either:

  • detector - Chooses buildpacks (via /bin/detect) and produces a build plan.
  • analyzer - Restores layer metadata from the previous image and from the cache.
  • restorer - Restores cached layers.
  • builder - Executes buildpacks (via /bin/build).
  • exporter - Creates an image and caches layers.

Or:

  • creator - Runs the five phases listed above in order.
Run
  • launcher - Invokes a chosen process.
Rebase
  • rebaser - Creates an image from a previous image with updated base layers.

Development

To test, build, and package binaries into an archive, simply run:

$ make all

This will create an archive at out/lifecycle-<LIFECYCLE_VERSION>+linux.x86-64.tgz.

LIFECYCLE_VERSION defaults to the value returned by git describe --tags if not on a release branch (for more information about the release process, see RELEASE. It can be changed by prepending LIFECYCLE_VERSION=<some version> to the make command. For example:

$ LIFECYCLE_VERSION=1.2.3 make all

Steps can also be run individually as shown below.

Test

Formats, vets, and tests the code.

$ make test
Build

Builds binaries to out/linux/lifecycle/.

$ make build

To clean the out/ directory, run make clean.

Package

Creates an archive at out/lifecycle-<LIFECYCLE_VERSION>+linux.x86-64.tgz, using the contents of the out/linux/lifecycle/ directory, for the given (or default) LIFECYCLE_VERSION.

$ make package

Documentation

Index

Constants

View Source
const (
	CodeDetectPass  = 0
	CodeDetectFail  = 100
	EnvBuildpackDir = "CNB_BUILDPACK_DIR"
)
View Source
const (
	BuildMetadataLabel = "io.buildpacks.build.metadata"
	LayerMetadataLabel = "io.buildpacks.lifecycle.metadata"
	StackIDLabel       = "io.buildpacks.stack.id"
	MixinsLabel        = "io.buildpacks.stack.mixins"
)
View Source
const (
	ProjectMetadataLabel = "io.buildpacks.project.metadata"
)

Variables

This section is empty.

Functions

func DecodeLabel

func DecodeLabel(image imgutil.Image, label string, v interface{}) error

func TruncateSha

func TruncateSha(sha string) string

func WriteTOML

func WriteTOML(path string, data interface{}) error

Types

type AnalyzedMetadata

type AnalyzedMetadata struct {
	Image    *ImageIdentifier `toml:"image"`
	Metadata LayersMetadata   `toml:"metadata"`
}

type Analyzer

type Analyzer struct {
	Buildpacks []GroupBuildpack
	LayersDir  string
	Logger     Logger
	SkipLayers bool
}

func (*Analyzer) Analyze

func (a *Analyzer) Analyze(image imgutil.Image, cache Cache) (AnalyzedMetadata, error)

Analyze restores metadata for launch and cache layers into the layers directory. If a usable cache is not provided, Analyze will not restore any cache=true layer metadata.

type BOMEntry

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

type BuildConfig added in v0.10.0

type BuildConfig struct {
	Env         BuildEnv
	AppDir      string
	PlatformDir string
	LayersDir   string
	Out         io.Writer
	Err         io.Writer
}

type BuildEnv

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

type BuildMetadata

type BuildMetadata struct {
	BOM        []BOMEntry       `toml:"bom" json:"bom"`
	Buildpacks []GroupBuildpack `toml:"buildpacks" json:"buildpacks"`
	Labels     []Label          `toml:"labels" json:"-"`
	Launcher   LauncherMetadata `toml:"-" json:"launcher"`
	Processes  []launch.Process `toml:"processes" json:"processes"`
	Slices     []layers.Slice   `toml:"slices" json:"-"`
}

type BuildPlan

type BuildPlan struct {
	Entries []BuildPlanEntry `toml:"entries"`
}

type BuildPlanEntry

type BuildPlanEntry struct {
	Providers []GroupBuildpack `toml:"providers"`
	Requires  []Require        `toml:"requires"`
}

type BuildReport added in v0.10.0

type BuildReport struct {
	BOM []BOMEntry `toml:"bom"`
}

type BuildResult added in v0.10.0

type BuildResult struct {
	BOM         []BOMEntry
	Labels      []Label
	MetRequires []string
	Processes   []launch.Process
	Slices      []layers.Slice
}

type BuildTOML added in v0.10.0

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

type Builder

type Builder struct {
	AppDir         string
	LayersDir      string
	PlatformDir    string
	PlatformAPI    *api.Version
	Env            BuildEnv
	Group          BuildpackGroup
	Plan           BuildPlan
	Out, Err       io.Writer
	BuildpackStore BuildpackStore
}

func (*Builder) Build

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

func (*Builder) BuildConfig added in v0.10.0

func (b *Builder) BuildConfig() (BuildConfig, error)

type Buildpack

type Buildpack interface {
	Build(bpPlan BuildpackPlan, config BuildConfig) (BuildResult, error)
}

type BuildpackGroup

type BuildpackGroup struct {
	Group []GroupBuildpack `toml:"group"`
}

func ReadGroup

func ReadGroup(path string) (BuildpackGroup, error)

func (BuildpackGroup) Detect

type BuildpackInfo added in v0.9.0

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

type BuildpackLayerMetadata

type BuildpackLayerMetadata struct {
	LayerMetadata
	BuildpackLayerMetadataFile
}

type BuildpackLayerMetadataFile

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

type BuildpackLayersMetadata

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

type BuildpackOrder

type BuildpackOrder []BuildpackGroup

func ReadOrder

func ReadOrder(path string) (BuildpackOrder, error)

func (BuildpackOrder) Detect

type BuildpackPlan added in v0.9.0

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

type BuildpackStore added in v0.7.0

type BuildpackStore interface {
	Lookup(bpID, bpVersion string) (Buildpack, error)
}

type BuildpackTOML added in v0.9.0

type BuildpackTOML struct {
	API       string         `toml:"api"`
	Buildpack BuildpackInfo  `toml:"buildpack"`
	Order     BuildpackOrder `toml:"order"`
	Dir       string         `toml:"-"`
}

func (*BuildpackTOML) Build added in v0.10.0

func (b *BuildpackTOML) Build(bpPlan BuildpackPlan, config BuildConfig) (BuildResult, error)

func (*BuildpackTOML) Detect added in v0.9.0

func (b *BuildpackTOML) Detect(c *DetectConfig) DetectRun

func (*BuildpackTOML) String added in v0.9.0

func (b *BuildpackTOML) String() string

type Cache

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

type CacheMetadata

type CacheMetadata struct {
	Buildpacks []BuildpackLayersMetadata `json:"buildpacks"`
}

func (*CacheMetadata) MetadataForBuildpack

func (cm *CacheMetadata) MetadataForBuildpack(id string) BuildpackLayersMetadata

type DetectConfig

type DetectConfig struct {
	FullEnv       []string
	ClearEnv      []string
	AppDir        string
	PlatformDir   string
	BuildpacksDir string
	Logger        Logger
	// contains filtered or unexported fields
}

type DetectRun added in v0.9.0

type DetectRun struct {
	Or     planSectionsList `toml:"or"`
	Output []byte           `toml:"-"`
	Code   int              `toml:"-"`
	Err    error            `toml:"-"`
	// contains filtered or unexported fields
}

type DirBuildpackStore added in v0.10.0

type DirBuildpackStore struct {
	Dir string
}

func (*DirBuildpackStore) Lookup added in v0.10.0

func (f *DirBuildpackStore) Lookup(bpID, bpVersion string) (Buildpack, error)

type Error added in v0.9.0

type Error struct {
	RootError error
	Type      ErrorType
}

func NewLifecycleError added in v0.9.0

func NewLifecycleError(cause error, errType ErrorType) *Error

func (*Error) Cause added in v0.9.0

func (le *Error) Cause() error

func (*Error) Error added in v0.9.0

func (le *Error) Error() string

type ErrorType added in v0.9.0

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

type ExportOptions added in v0.7.0

type ExportOptions struct {
	LayersDir          string
	AppDir             string
	WorkingImage       imgutil.Image
	RunImageRef        string
	OrigMetadata       LayersMetadata
	AdditionalNames    []string
	LauncherConfig     LauncherConfig
	Stack              StackMetadata
	Project            ProjectMetadata
	DefaultProcessType string
}

type ExportReport added in v0.9.0

type ExportReport struct {
	Build BuildReport `toml:"build,omitempty"`
	Image ImageReport `toml:"image"`
}

type Exporter

type Exporter struct {
	Buildpacks   []GroupBuildpack
	LayerFactory LayerFactory
	Logger       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) (ExportReport, error)

type GitMetadata

type GitMetadata struct {
	Repository string `json:"repository"`
	Commit     string `json:"commit"`
}

type GroupBuildpack added in v0.10.0

type GroupBuildpack struct {
	ID       string `toml:"id" json:"id"`
	Version  string `toml:"version" json:"version"`
	Optional bool   `toml:"optional,omitempty" json:"optional,omitempty"`
	API      string `toml:"api,omitempty" json:"-"`
	Homepage string `toml:"homepage,omitempty" json:"homepage,omitempty"`
}

func (GroupBuildpack) Lookup added in v0.10.0

func (bp GroupBuildpack) Lookup(buildpacksDir string) (*BuildpackTOML, error)

func (GroupBuildpack) String added in v0.10.0

func (bp GroupBuildpack) String() string

type ImageIdentifier

type ImageIdentifier struct {
	Reference string `toml:"reference"`
}

FIXME: fix key names to be accurate in the daemon case

type ImageReport added in v0.9.0

type ImageReport struct {
	Tags    []string `toml:"tags"`
	ImageID string   `toml:"image-id,omitempty"`
	Digest  string   `toml:"digest,omitempty"`
}

type Label added in v0.9.0

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

type LaunchTOML

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

type LauncherConfig

type LauncherConfig struct {
	Path     string
	Metadata LauncherMetadata
}

type LauncherMetadata

type LauncherMetadata struct {
	Version string         `json:"version"`
	Source  SourceMetadata `json:"source"`
}

type LayerFactory added in v0.8.1

type LayerFactory interface {
	DirLayer(id string, dir 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)
}

type LayerMetadata

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

type LayersMetadata

type LayersMetadata struct {
	App          []LayerMetadata           `json:"app" toml:"app"`
	Buildpacks   []BuildpackLayersMetadata `json:"buildpacks" toml:"buildpacks"`
	Config       LayerMetadata             `json:"config" toml:"config"`
	Launcher     LayerMetadata             `json:"launcher" toml:"launcher"`
	ProcessTypes LayerMetadata             `json:"process-types" toml:"process-types"`
	RunImage     RunImageMetadata          `json:"runImage" toml:"run-image"`
	Stack        StackMetadata             `json:"stack" toml:"stack"`
}

NOTE: This struct MUST be kept in sync with `LayersMetadataCompat`

func (*LayersMetadata) MetadataForBuildpack

func (m *LayersMetadata) MetadataForBuildpack(id string) BuildpackLayersMetadata

type LayersMetadataCompat

type LayersMetadataCompat struct {
	App          interface{}               `json:"app" toml:"app"`
	Config       LayerMetadata             `json:"config" toml:"config"`
	Launcher     LayerMetadata             `json:"launcher" toml:"launcher"`
	ProcessTypes LayerMetadata             `json:"process-types" toml:"process-types"`
	Buildpacks   []BuildpackLayersMetadata `json:"buildpacks" toml:"buildpacks"`
	RunImage     RunImageMetadata          `json:"runImage" toml:"run-image"`
	Stack        StackMetadata             `json:"stack" toml:"stack"`
}

NOTE: This struct MUST be kept in sync with `LayersMetadata`. It exists for situations where the `App` field type cannot be guaranteed, yet the original struct data must be maintained.

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 MultiError

type MultiError struct {
	Errors []error
}

func (*MultiError) Error

func (me *MultiError) Error() string

type ProjectMetadata added in v0.7.0

type ProjectMetadata struct {
	Source *ProjectSource `toml:"source" json:"source,omitempty"`
}

type ProjectSource added in v0.7.0

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

type Provide

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

type RebaseReport added in v0.9.0

type RebaseReport struct {
	Image ImageReport `toml:"image"`
}

type Rebaser

type Rebaser struct {
	Logger Logger
}

func (*Rebaser) Rebase

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

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 Restorer

type Restorer struct {
	LayersDir  string
	Buildpacks []GroupBuildpack
	Logger     Logger
}

func (*Restorer) Restore

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

Restore attempts to restore layer data for cache=true layers, removing the layer when unsuccessful. If a usable cache is not provided, Restore will remove all cache=true layer metadata.

type RunImageMetadata

type RunImageMetadata struct {
	TopLayer  string `json:"topLayer" toml:"top-layer"`
	Reference string `json:"reference" toml:"reference"`
}

type SourceMetadata

type SourceMetadata struct {
	Git GitMetadata `json:"git"`
}

type StackMetadata

type StackMetadata struct {
	RunImage StackRunImageMetadata `json:"runImage" toml:"run-image"`
}

func (*StackMetadata) BestRunImageMirror

func (sm *StackMetadata) BestRunImageMirror(registry string) (string, error)

type StackRunImageMetadata

type StackRunImageMetadata struct {
	Image   string   `toml:"image" json:"image"`
	Mirrors []string `toml:"mirrors" json:"mirrors,omitempty"`
}

type StoreTOML added in v0.10.0

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

type Unmet added in v0.10.0

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

Directories

Path Synopsis
acceptance
cmd
testmock
Package testmock is a generated GoMock package.
Package testmock is a generated GoMock package.
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