lifecycle

package module
v0.6.1 Latest Latest
Warning

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

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

README

Lifecycle

Build Status GoDoc

A reference implementation of the Cloud Native Buildpacks specification.

This lifecycle implements the following versioned APIs

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

Variables

View Source
var ErrFail = errors.New("no buildpacks participating")
View Source
var POSIXBuildEnv = map[string][]string{
	"bin": {
		"PATH",
	},
	"lib": {
		"LD_LIBRARY_PATH",
		"LIBRARY_PATH",
	},
	"include": {
		"CPATH",
	},
	"pkgconfig": {
		"PKG_CONFIG_PATH",
	},
}
View Source
var POSIXLaunchEnv = map[string][]string{
	"bin": {"PATH"},
	"lib": {"LD_LIBRARY_PATH"},
}

Functions

func DecodeLabel

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

func MetadataFilePath

func MetadataFilePath(layersDir string) string

func SetupCredHelpers

func SetupCredHelpers(dockerPath string, refs ...string) 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
	GID, UID   int
	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  []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"`
}

type BuildpackOrder

type BuildpackOrder []BuildpackGroup

func ReadOrder

func ReadOrder(path string) (BuildpackOrder, error)

func (BuildpackOrder) Detect

type Cache

type Cache interface {
	Name() string
	SetMetadata(metadata CacheMetadata) error
	RetrieveMetadata() (CacheMetadata, error)
	AddLayerFile(sha string, tarPath 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 Env

type Env struct {
	LookupEnv func(key string) (string, bool)
	Getenv    func(key string) string
	Setenv    func(key, value string) error
	Unsetenv  func(key string) error
	Environ   func() []string
	Map       map[string][]string
}

func (*Env) AddEnvDir

func (p *Env) AddEnvDir(envDir string) error

func (*Env) AddRootDir

func (p *Env) AddRootDir(baseDir string) error

func (*Env) List

func (p *Env) List() []string

func (*Env) WithPlatform

func (p *Env) WithPlatform(platformDir string) (out []string, err error)

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(
	layersDir,
	appDir string,
	workingImage imgutil.Image,
	runImageRef string,
	origMetadata LayersMetadata,
	additionalNames []string,
	launcherConfig LauncherConfig,
	stack StackMetadata,
) 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 []Process `toml:"processes"`
	Slices    []Slice   `toml:"slices"`
}

type Launcher

type Launcher struct {
	DefaultProcessType string
	LayersDir          string
	AppDir             string
	Processes          []Process
	Buildpacks         []Buildpack
	Env                BuildEnv
	Exec               func(argv0 string, argv []string, envv []string) error
}

func (*Launcher) Launch

func (l *Launcher) Launch(self string, cmd []string) error

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 Process

type Process struct {
	Type    string   `toml:"type" json:"type"`
	Command string   `toml:"command" json:"command"`
	Args    []string `toml:"args" json:"args"`
	Direct  bool     `toml:"direct" json:"direct"`
}

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
	UID        int
	GID        int
}

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