lifecycle

package module
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2020 License: Apache-2.0 Imports: 23 Imported by: 0

README

Lifecycle

Build Status GoDoc

A reference implementation of the Cloud Native Buildpacks specification.

This lifecycle implements the following versioned APIs

  • Buildpack API 0.2
  • Platform API 0.3

Commands

Build
  • detector - chooses buildpacks (via /bin/detect)
  • analyzer - restores launch layer metadata from the previous build
  • restorer - restores cache
  • builder - executes buildpacks (via /bin/build)
  • exporter - creates image and stores cache
Run
  • launcher - invokes choice of process
Rebase
  • rebaser - remotely patches images with new base image

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"
)
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 []Buildpack
	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 Buildpack `toml:"buildpack" json:"buildpack"`
}

type BuildEnv

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

type BuildMetadata

type BuildMetadata struct {
	BOM        []BOMEntry       `toml:"bom" json:"bom"`
	Buildpacks []Buildpack      `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 []Buildpack `toml:"providers"`
	Requires  []Require   `toml:"requires"`
}

type Builder

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

func (*Builder) Build

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

type Buildpack

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

func (Buildpack) Lookup added in v0.9.0

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

func (Buildpack) String

func (bp Buildpack) String() string

type BuildpackGroup

type BuildpackGroup struct {
	Group []Buildpack `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"`
}

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   *BuildpackStore                   `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 struct {
	Data map[string]interface{} `json:"metadata" toml:"metadata"`
}

type BuildpackTOML added in v0.9.0

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

func (*BuildpackTOML) Detect added in v0.9.0

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

func (BuildpackTOML) String added in v0.9.0

func (bp BuildpackTOML) String() string

type Cache

type Cache interface {
	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 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 {
	Image ImageReport `toml:"image"`
}

type Exporter

type Exporter struct {
	Buildpacks   []Buildpack
	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 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 {
	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(workingImage 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 []Buildpack
	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"`
}

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