builder

package
v0.2.15 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2025 License: MIT Imports: 14 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DefaultTemplateDir     = "./template"
	DefaultTemplateHandler = "function"
	DefaultBuildDir        = "./build"
)
View Source
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.

func MakeTar

func MakeTar(tarPath string, context string, buildConfig *BuildConfig) error

MakeTar create a tar archive that contains the build config and build context.

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

type BuildContextConfig

type BuildContextConfig struct {
	// Directory where the build context will be created.
	BuildDir string

	// Directory used to lookup templates
	TemplateDir string

	// Path where the function handler should be overlayed
	// in the selected template
	TemplateHandlerOverlay string
}

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    []string `json:"log"`
	Image  string   `json:"image"`
	Status string   `json:"status"`
}

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.

Jump to

Keyboard shortcuts

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