solver

package
v0.0.0-...-1b31410 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2018 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.Errorf("not found")
View Source
var NoSelector = digest.FromBytes(nil)

Functions

func RunCacheStorageTests

func RunCacheStorageTests(t *testing.T, st func() (CacheKeyStorage, func()))

Types

type Builder

type Builder interface {
	Build(ctx context.Context, e Edge) (CachedResult, error)
}
type CacheInfoLink struct {
	Input    Index         `json:"Input,omitempty"`
	Output   Index         `json:"Output,omitempty"`
	Digest   digest.Digest `json:"Digest,omitempty"`
	Selector digest.Digest `json:"Selector,omitempty"`
}

CacheInfoLink is a link between two cache keys

type CacheKey

type CacheKey interface {
	// Deps are dependant cache keys
	Deps() []CacheKeyWithSelector
	// Base digest for operation. Usually CacheMap.Digest
	Digest() digest.Digest
	// Index for the output that is cached
	Output() Index
	// Helpers for implementations for adding internal metadata
	SetValue(key, value interface{})
	GetValue(key interface{}) interface{}
}

CacheKey is an identifier for storing/loading build cache

func NewCacheKey

func NewCacheKey(dgst digest.Digest, index Index, deps []CacheKeyWithSelector) CacheKey

NewCacheKey creates a new cache key for a specific output index

type CacheKeyInfo

type CacheKeyInfo struct {
	ID     string
	Base   digest.Digest
	Output int
	Deps   []CacheKeyInfoWithSelector
}

CacheKeyInfo is storable metadata about single cache key

type CacheKeyInfoWithSelector

type CacheKeyInfoWithSelector struct {
	ID       string
	Selector digest.Digest
}

CacheKeyInfoWithSelector is CacheKeyInfo combined with a selector

type CacheKeyStorage

type CacheKeyStorage interface {
	Get(id string) (CacheKeyInfo, error)
	Walk(fn func(id string) error) error
	Set(info CacheKeyInfo) error

	WalkResults(id string, fn func(CacheResult) error) error
	Load(id string, resultID string) (CacheResult, error)
	AddResult(id string, res CacheResult) error
	Release(resultID string) error

	AddLink(id string, link CacheInfoLink, target string) error
	WalkLinks(id string, link CacheInfoLink, fn func(id string) error) error
}

CacheKeyStorage is interface for persisting cache metadata

func NewInMemoryCacheStorage

func NewInMemoryCacheStorage() CacheKeyStorage

type CacheKeyWithSelector

type CacheKeyWithSelector struct {
	Selector digest.Digest
	CacheKey ExportableCacheKey
}

CacheKeyWithSelector combines a cache key with an optional selector digest. Used to limit the matches for dependency cache key.

type CacheLink struct {
	Source   digest.Digest
	Input    Index
	Output   Index
	Base     digest.Digest
	Selector digest.Digest
}

CacheLink is a link between two cache records

type CacheManager

type CacheManager interface {
	// ID is used to identify cache providers that are backed by same source
	// to avoid duplicate calls to the same provider
	ID() string
	// Query searches for cache paths from one cache key to the output of a
	// possible match.
	Query(inp []ExportableCacheKey, inputIndex Index, dgst digest.Digest, outputIndex Index, selector digest.Digest) ([]*CacheRecord, error)
	// Load pulls and returns the cached result
	Load(ctx context.Context, rec *CacheRecord) (Result, error)
	// Save saves a result based on a cache key
	Save(key CacheKey, s Result) (ExportableCacheKey, error)
}

CacheManager implements build cache backend

func NewCacheManager

func NewCacheManager(id string, storage CacheKeyStorage, results CacheResultStorage) CacheManager

func NewInMemoryCacheManager

func NewInMemoryCacheManager() CacheManager

type CacheMap

type CacheMap struct {
	// Digest is a base digest for operation that needs to be combined with
	// inputs cache or selectors for dependencies.
	Digest digest.Digest
	Deps   []struct {
		// Optional digest that is merged with the cache key of the input
		Selector digest.Digest
		// Optional function that returns a digest for the input based on its
		// return value
		ComputeDigestFunc ResultBasedCacheFunc
	}
}

type CacheRecord

type CacheRecord struct {
	ID           string
	CacheKey     ExportableCacheKey
	CacheManager CacheManager
	Loadable     bool
	// Size int
	CreatedAt time.Time
	Priority  int
}

CacheRecord is an identifier for loading in cache

type CacheResult

type CacheResult struct {
	// Payload   []byte
	CreatedAt time.Time
	ID        string
}

CacheResult is a record for a single solve result

type CacheResultStorage

type CacheResultStorage interface {
	Save(Result) (CacheResult, error)
	Load(ctx context.Context, res CacheResult) (Result, error)
	LoadRemote(ctx context.Context, res CacheResult) (*Remote, error)
	Exists(id string) bool
}

CacheResultStorage is interface for converting cache metadata result to actual solve result

func NewInMemoryResultStorage

func NewInMemoryResultStorage() CacheResultStorage

type CachedResult

type CachedResult interface {
	Result
	CacheKey() ExportableCacheKey
	Export(ctx context.Context, converter func(context.Context, Result) (*Remote, error)) ([]ExportRecord, error)
}

CachedResult is a result connected with its cache key

func NewCachedResult

func NewCachedResult(res Result, k CacheKey, exp Exporter) CachedResult

NewCachedResult combines a result and cache key into cached result

type Edge

type Edge struct {
	Index  Index
	Vertex Vertex
}

Edge is a path to a specific output of the vertex

type EdgeFactory

type EdgeFactory interface {
	GetEdge(Edge) *edge
	SetEdge(Edge, *edge)
}

EdgeFactory allows access to the edges from a shared graph

type EdgeIndex

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

EdgeIndex is a synchronous map for detecting edge collisions.

func NewEdgeIndex

func NewEdgeIndex() *EdgeIndex

func (*EdgeIndex) LoadOrStore

func (ei *EdgeIndex) LoadOrStore(e *edge, dgst digest.Digest, index Index, deps [][]CacheKey) *edge

func (*EdgeIndex) Release

func (ei *EdgeIndex) Release(e *edge)

type ExportRecord

type ExportRecord struct {
	Digest digest.Digest
	Links  map[CacheLink]struct{}
	Remote *Remote
}

ExportRecord defines a single record in the exported cache chain

type ExportableCacheKey

type ExportableCacheKey struct {
	CacheKey
	Exporter
}

ExportableCacheKey is a cache key connected with an exporter that can export a chain of cacherecords pointing to that key

type Exporter

type Exporter interface {
	Export(ctx context.Context, m map[digest.Digest]*ExportRecord, converter func(context.Context, Result) (*Remote, error)) (*ExportRecord, error)
}

Exporter can export the artifacts of the build chain

type Index

type Index int

Index is a index value for output edge

type Job

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

func (*Job) Build

func (j *Job) Build(ctx context.Context, e Edge) (CachedResult, error)

func (*Job) Discard

func (j *Job) Discard() error

func (*Job) Status

func (j *Job) Status(ctx context.Context, ch chan *client.SolveStatus) error

type JobList

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

JobList provides a shared graph of all the vertexes currently being processed. Every vertex that is being solved needs to be loaded into job first. Vertex operations are invoked and progress tracking happends through jobs. TODO: s/JobList/Solver

func NewJobList

func NewJobList(opts SolverOpt) *JobList

func (*JobList) Close

func (jl *JobList) Close()

func (*JobList) Get

func (jl *JobList) Get(id string) (*Job, error)

func (*JobList) GetEdge

func (jl *JobList) GetEdge(e Edge) *edge

func (*JobList) NewJob

func (jl *JobList) NewJob(id string) (*Job, error)

func (*JobList) SetEdge

func (jl *JobList) SetEdge(e Edge, newEdge *edge)

type Op

type Op interface {
	// CacheMap returns structure describing how the operation is cached
	CacheMap(context.Context) (*CacheMap, error)
	// Exec runs an operation given results from previous operations.
	Exec(ctx context.Context, inputs []Result) (outputs []Result, err error)
}

Op is an implementation for running a vertex

type Remote

type Remote struct {
	Descriptors []ocispec.Descriptor
	Provider    content.Provider
}

Remote is a descriptor or a list of stacked descriptors that can be pulled from a content provider

type ResolveOpFunc

type ResolveOpFunc func(Vertex, Builder) (Op, error)

ResolveOpFunc finds an Op implementation for a Vertex

type Result

type Result interface {
	ID() string
	Release(context.Context) error
	Sys() interface{}
}

Result is an abstract return value for a solve

type ResultBasedCacheFunc

type ResultBasedCacheFunc func(context.Context, Result) (digest.Digest, error)

type Scheduler

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

func NewScheduler

func NewScheduler(ef EdgeFactory) *Scheduler

func (*Scheduler) Stop

func (s *Scheduler) Stop()

type SharedResult

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

SharedResult is a result that can be cloned

func NewSharedResult

func NewSharedResult(main Result) *SharedResult

func (*SharedResult) Clone

func (r *SharedResult) Clone() Result

func (*SharedResult) Release

func (r *SharedResult) Release(ctx context.Context) error

type SolverOpt

type SolverOpt struct {
	ResolveOpFunc ResolveOpFunc
	DefaultCache  CacheManager
}

type Vertex

type Vertex interface {
	// Digest is a content-addressable vertex identifier
	Digest() digest.Digest
	// Sys returns an internal value that is used to execute the vertex. Usually
	// this is capured by the operation resolver method during solve.
	Sys() interface{}
	Options() VertexOptions
	// Array of edges current vertex depends on.
	Inputs() []Edge
	Name() string
}

Vertex is one node in the build graph

type VertexOptions

type VertexOptions struct {
	IgnoreCache bool
	CacheSource CacheManager
	Description map[string]string // text values with no special meaning for solver

}

VertexOptions has optional metadata for the vertex that is not contained in digest

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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