lifecycle

package module
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: May 8, 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.

By default, LIFECYCLE_VERSION is 0.0.0. 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
)
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

View Source
var ErrFail = errors.New("no buildpacks participating")

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 {
	Processes  []launch.Process `toml:"processes" json:"processes"`
	Buildpacks []Buildpack      `toml:"buildpacks" json:"buildpacks"`
	BOM        []BOMEntry       `toml:"bom" json:"bom"`
	Launcher   LauncherMetadata `toml:"-" json:"launcher"`
	Slices     []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
	Env           BuildEnv
	Group         BuildpackGroup
	Plan          BuildPlan
	Out, Err      *log.Logger
}

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

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 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 BuildpackStore added in v0.7.0

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

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

type Exporter struct {
	Buildpacks   []Buildpack
	ArtifactsDir string
	Logger       Logger
	UID, GID     int
	// contains filtered or unexported fields
}

func (*Exporter) Cache

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

func (*Exporter) Export

func (e *Exporter) Export(opts ExportOptions) 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 LaunchTOML

type LaunchTOML struct {
	Processes []launch.Process `toml:"processes"`
	Slices    []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 LayerMetadata

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

type LayersMetadata

type LayersMetadata struct {
	App        []LayerMetadata           `json:"app" toml:"app"`
	Config     LayerMetadata             `json:"config" toml:"config"`
	Launcher   LayerMetadata             `json:"launcher" toml:"launcher"`
	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 `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"`
	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 Rebaser

type Rebaser struct {
	Logger Logger
}

func (*Rebaser) Rebase

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

type Require

type Require struct {
	Name     string                 `toml:"name" json:"name"`
	Version  string                 `toml:"version" json:"version"`
	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 Slice

type Slice struct {
	Paths []string `tom:"paths"`
}

type SliceLayer

type SliceLayer struct {
	ID      string
	TarPath string
	SHA     string
}

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