Documentation
¶
Index ¶
- Constants
- func CreateBuildContext(functionName string, handler string, language string, copyExtraPaths []string, ...) (string, error)
- func MakeTar(tarPath string, context string, buildConfig *BuildConfig) error
- type BuildConfig
- type BuildContextConfig
- type BuildContextOption
- type BuildResult
- type BuildResultStream
- type BuilderOption
- type FunctionBuilder
Constants ¶
const ( BuildInProgress = "in_progress" BuildSuccess = "success" BuildFailed = "failed" )
const ( DefaultTemplateDir = "./template" DefaultTemplateHandler = "function" DefaultBuildDir = "./build" )
const BuilderConfigFileName = "com.openfaas.docker.config"
Variables ¶
This section is empty.
Functions ¶
func CreateBuildContext ¶
func CreateBuildContext(functionName string, handler string, language string, copyExtraPaths []string, options ...BuildContextOption) (string, error)
CreateBuildContext create a Docker build context using the provided function handler and language template.
Parameters:
- functionName: name of the function.
- handler: path to the function handler.
- language: name of the language template to use.
- copyExtraPaths: additional paths to copy into the function handler folder. Paths should be relative to the current directory. Any paths outside if this directory will be skipped.
By default templates are looked up in the `./template` directory. The path the the template directory can be overridden by setting the `builder.WithTemplateDir` option. CreateBuildContext overlays the function handler in the `function` folder of the template by default. This setting can be overridden by setting the `builder.WithHandlerOverlay` option.
The function returns the path to the build context, `./build/<functionName>` by default. The build directory can be overridden by setting the `builder.WithBuildDir` option. An error is returned if creating the build context fails.
Types ¶
type BuildConfig ¶
type BuildConfig struct { // Image reference. Image string `json:"image"` // Extra build arguments for the Dockerfile. BuildArgs map[string]string `json:"buildArgs,omitempty"` // Platforms for multi-arch builds. Platforms []string `json:"platforms,omitempty"` // SkipPush is a flag to skip skip pushing the image to the registry. SkipPush bool `json:"skipPush,omitempty"` }
BuildConfig represents the configuration for a build operation.
type BuildContextConfig ¶
type BuildContextOption ¶
type BuildContextOption func(*BuildContextConfig)
func WithBuildDir ¶
func WithBuildDir(path string) BuildContextOption
WithBuildDir is an option to configure the directory the build context is created in. If this options is not set a default path `./build` is used.
func WithHandlerOverlay ¶
func WithHandlerOverlay(path string) BuildContextOption
WithHandlerOverlay is an option to configure the path where the function handler needs to be overlayed in the template. If this option is not set a default overlay path `function` is used.
func WithTemplateDir ¶
func WithTemplateDir(path string) BuildContextOption
WithTemplateDir is an option to configure the directory where the build template is looked up. If this option is not set a default path `./template` is used.
type BuildResult ¶
type BuildResult struct { // Log contains the build log. Log []string `json:"log"` // Image is the image reference of the built function. Image string `json:"image"` // Status is the status of the build. Status string `json:"status"` // Error is the error message if the build failed. Error string `json:"error,omitempty"` }
BuildResult represents the result of a build operation.
type BuildResultStream ¶ added in v0.2.17
type BuildResultStream struct {
// contains filtered or unexported fields
}
BuildResultStream represents a stream of build results. The Results method can be used to iterate over the build results.
func (*BuildResultStream) Close ¶ added in v0.2.17
func (b *BuildResultStream) Close() error
Close closes the build stream preventing further iteration. The stream is automatically closed when you iterate through all results or when the iteration terminates
func (*BuildResultStream) Results ¶ added in v0.2.17
func (b *BuildResultStream) Results() iter.Seq2[BuildResult, error]
Results returns an iterator over build results. It returns a single-use iterator
type BuilderOption ¶
type BuilderOption func(*FunctionBuilder)
func WithHmacAuth ¶
func WithHmacAuth(secret string) BuilderOption
WithHmacAuth configures the HMAC secret used to sign request payloads to the builder API.
type FunctionBuilder ¶
type FunctionBuilder struct { // URL of the OpenFaaS Builder API. URL *url.URL // contains filtered or unexported fields }
func NewFunctionBuilder ¶
func NewFunctionBuilder(url *url.URL, client *http.Client, options ...BuilderOption) *FunctionBuilder
NewFunctionBuilder create a new builder for building OpenFaaS functions using the Function Builder API.
func (*FunctionBuilder) Build ¶
func (b *FunctionBuilder) Build(tarPath string) (BuildResult, error)
Build invokes the function builder API with the provided tar archive containing the build config and context to build and push a function image.
func (*FunctionBuilder) BuildWithStream ¶ added in v0.2.17
func (b *FunctionBuilder) BuildWithStream(tarPath string) (*BuildResultStream, error)
BuildWithStream invokes the function builder API with the provided tar archive containing the build config and context to build and push a function image.
The function returns a sequence of build results. The sequence is closed when the build is complete.