Documentation
¶
Overview ¶
Package functions contains functions for building embedded functions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultBaseImageCacheDir ¶
func DefaultBaseImageCacheDir() string
DefaultBaseImageCacheDir returns the default per-user cache directory for function runtime base image layers, or "" to disable caching when there is no per-user directory to put it in. It sits beside the xpkg cache rather than inside it, since the two hold different kinds of artifact and would be pruned on different terms.
Falling back to os.TempDir() would put the cache at a predictable path that another user on a shared machine could have created first, with permissions of their choosing. The layers are public registry content rather than anything sensitive, but a cache is not worth a world-readable directory someone else controls — and callers already treat "" as "do not cache", so declining is cheap.
Nothing prunes this directory. Layers are keyed by content digest, so entries are never stale, but they are also never replaced: every base image version a user builds against accumulates. Users can delete the directory safely — the next build refetches what it needs — but the CLI should grow a retention policy or a prune command before this becomes the kind of thing people discover by running out of disk.
Types ¶
type BuildContext ¶
type BuildContext struct {
// ProjectFS is the project root filesystem.
ProjectFS afero.Fs
// FunctionPath is the function's path relative to ProjectFS root,
// e.g. "functions/my-fn".
FunctionPath string
// SchemasPath is the schemas dir relative to ProjectFS root, e.g.
// "schemas". Used by Python to stage schemas/python/ alongside the
// function source so the relative path-dep resolves at build time.
SchemasPath string
// Architectures is the list of architectures to build for.
Architectures []string
// OSBasePath is the absolute on-disk path of the function directory.
// Used by FSToTar to resolve symlinks.
OSBasePath string
// BaseImageCacheDir is where runtime base image layers are cached between
// builds. Empty disables caching, so layers are fetched from the registry
// every time.
BaseImageCacheDir string
}
BuildContext bundles the inputs that function builders work from. Each builder slices the parts of the project it needs: the function subdirectory for Go/KCL/go-templating, plus the schemas dir for Python.
func (BuildContext) FunctionFS ¶
func (c BuildContext) FunctionFS() afero.Fs
FunctionFS returns a filesystem rooted at the function's source directory.
type Builder ¶
type Builder interface {
// Name returns a name for this builder.
Name() string
// Build builds the function described by the given context, returning
// an image for each architecture. This image will *not* include
// package metadata; it's just the runtime image for the function.
Build(ctx context.Context, c BuildContext) ([]v1.Image, error)
// contains filtered or unexported methods
}
Builder knows how to build a particular kind of function.
type Identifier ¶
type Identifier interface {
// Identify returns a suitable builder for the function whose source lives
// in the given filesystem. It returns an error if no such builder is
// available.
Identify(fromFS afero.Fs, imageConfigs []pkgv1beta1.ImageConfig) (Builder, error)
}
Identifier knows how to identify an appropriate builder for a function based on its source code.
var DefaultIdentifier Identifier = realIdentifier{}
DefaultIdentifier is the default builder identifier, suitable for production use.
var FakeIdentifier Identifier = nopIdentifier{}
FakeIdentifier is an identifier that always returns a fake builder. This is for use in tests where we don't want to do real builds.