common

package
v0.0.0-...-2c6a202 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2024 License: Apache-2.0 Imports: 32 Imported by: 6

Documentation

Index

Constants

View Source
const (
	FunctionsDockerImage     = "fnproject/fnserver"
	FuncfileDockerRuntime    = "docker"
	MinRequiredDockerVersion = "17.5.0"
	BuildxBuilderInstance    = "oci_fn_builder"
	DefaultAppShape          = modelsv2.AppShapeGENERICX86
)

Global docker variables.

View Source
const (
	V20180708         = 20180708
	LatestYamlVersion = V20180708
)
View Source
const V20180708Schema = `` /* 1245-byte string literal not displayed */

Variables

View Source
var CommandVerbose bool
View Source
var GlobalVerbose bool
View Source
var (
	// InitialVersion - inital fn version.
	InitialVersion = "0.0.1"
)
View Source
var ShapeMap = map[string][]string{
	modelsv2.AppShapeGENERICX86:    {"linux/amd64"},
	modelsv2.AppShapeGENERICARM:    {"linux/arm64"},
	modelsv2.AppShapeGENERICX86ARM: {"linux/arm64", "linux/amd64"},
}
View Source
var TargetPlatformMap = map[string][]string{
	modelsv2.AppShapeGENERICX86:    {"amd64"},
	modelsv2.AppShapeGENERICARM:    {"arm64"},
	modelsv2.AppShapeGENERICX86ARM: {"amd64_arm64"},
}

Functions

func BumpCommand

func BumpCommand() cli.Command

BumpCommand command to build function version.

func DefaultBashComplete

func DefaultBashComplete(c *cli.Context)

DefaultBashComplete prints the list of all sub commands of the current command (without alias names)

func DeleteFunctions

func DeleteFunctions(c *cli.Context, client *fnclient.Fn, fns []*modelsv2.Fn) error

DeleteFunctions deletes all the functions provided to it. if provided nil it is a no-op

func DeleteTriggers

func DeleteTriggers(c *cli.Context, client *fnclient.Fn, triggers []*modelsv2.Trigger) error

DeleteTriggers deletes all the triggers provided to it. if provided nil it is a no-op

func EncodeFuncFileV20180708YAML

func EncodeFuncFileV20180708YAML(path string, ff *FuncFileV20180708) error

EncodeFuncfileYAML encodes function file.

func EncodeFuncfileYAML

func EncodeFuncfileYAML(path string, ff *FuncFile) error

EncodeFuncfileYAML encodes function file.

func Exists

func Exists(name string) bool

Exists check file exists.

func ExtractAnnotations

func ExtractAnnotations(c *cli.Context) map[string]interface{}

ExtractAnnotations extract annotations from command flags.

func ExtractConfig

func ExtractConfig(configs []string) map[string]string

ExtractConfig parses key-value configuration into a map

func FindFuncfile

func FindFuncfile(path string) (string, error)

findFuncfile for a func.yaml/json/yml file in path

func GetContainerEngineType

func GetContainerEngineType() (string, error)

func GetDir

func GetDir(c *cli.Context) string

GetDir returns the dir if defined as a flag in cli.Context

func GetFuncYamlVersion

func GetFuncYamlVersion(oldFF map[string]interface{}) int

func GetWd

func GetWd() string

GetWd returns working directory.

func IsFuncFile

func IsFuncFile(path string, info os.FileInfo) bool

IsFuncFile check vaid funcfile.

func IsVerbose

func IsVerbose() bool

func ListFnsAndTriggersInApp

func ListFnsAndTriggersInApp(c *cli.Context, client *fnclient.Fn, app *modelsv2.App) ([]*modelsv2.Fn, []*modelsv2.Trigger, error)

ListFnsAndTriggersInApp lists all the functions associated with an app and all the triggers associated with each of those functions

func ListFnsInApp

func ListFnsInApp(c *cli.Context, client *fnclient.Fn, app *modelsv2.App) ([]*modelsv2.Fn, error)

ListFnsInApp gets all the functions associated with an app

func ListTriggersInFunc

func ListTriggersInFunc(c *cli.Context, client *fnclient.Fn, fn *modelsv2.Fn) ([]*modelsv2.Trigger, error)

ListTriggersInFunc gets all the triggers associated with a function

func MergeFuncFileInitYAML

func MergeFuncFileInitYAML(path string, ff *FuncFileV20180708) error

Merge the func.init.yaml from the initImage with a.ff

write out the new func file

func PrintContextualInfo

func PrintContextualInfo()

func PrintDockerfileContent

func PrintDockerfileContent(dockerfile string, stdout io.Writer)

func Push

func Push(ff *FuncFile) error

Push pushes to docker registry.

func PushV20180708

func PushV20180708(ff *FuncFileV20180708) error

Push pushes to docker registry.

func ReadInFuncFile

func ReadInFuncFile() (map[string]interface{}, error)

func RunBuild

func RunBuild(verbose bool, dir, imageName, dockerfile string, buildArgs []string, noCache bool, containerEngineType string, shape string) error

RunBuild runs function from func.yaml/json/yml.

func RunInitImage

func RunInitImage(initImage string, fName string) error

func UserConfirmedMultiResourceDeletion

func UserConfirmedMultiResourceDeletion(aps []*modelsv2.App, fns []*modelsv2.Fn, trs []*modelsv2.Trigger) bool

UserConfirmedMultiResourceDeletion will prompt the user for confirmation to delete all the the resources

func ValidateFileAgainstSchema

func ValidateFileAgainstSchema(jsonFile, schema string) error

func ValidateFullImageName

func ValidateFullImageName(n string) error

ValidateFullImageName validates that the full image name (REGISTRY/name:tag) is allowed for push remember that private registries must be supported here

func ValidateTagImageName

func ValidateTagImageName(n string) error

ValidateTagImageName validates that the last part of the image name (name:tag) is allowed for create/update

func WalkFuncs

func WalkFuncs(root string, walkFn walkFuncsFunc) error

WalkFuncs is similar to filepath.Walk except only returns func.yaml's (so on per function)

func WalkFuncsV20180708

func WalkFuncsV20180708(root string, walkFn walkFuncsFuncV20180708) error

WalkFuncsV20180708 is similar to filepath.Walk except only returns func.yaml's (so on per function)

Types

type AppFile

type AppFile struct {
	Name        string                 `yaml:"name,omitempty" json:"name,omitempty"`
	Config      map[string]string      `yaml:"config,omitempty" json:"config,omitempty"`
	Annotations map[string]interface{} `yaml:"annotations,omitempty" json:"annotations,omitempty"`
	SyslogURL   string                 `yaml:"syslog_url,omitempty" json:"syslog_url,omitempty"`
}

AppFile defines the internal structure of a app.yaml/json/yml

func LoadAppfile

func LoadAppfile(path string) (*AppFile, error)

LoadAppfile returns a parsed appfile.

type Expects

type Expects struct {
	Config []inputVar `yaml:"config" json:"config"`
}

Expects represents expected env vars in funcfile.

type FFTest

type FFTest struct {
	Name   string     `yaml:"name,omitempty" json:"name,omitempty"`
	Input  *InputMap  `yaml:"input,omitempty" json:"input,omitempty"`
	Output *OutputMap `yaml:"outoutput,omitempty" json:"output,omitempty"`
	Err    *string    `yaml:"err,omitempty" json:"err,omitempty"`
}

FFTest represents a test for a funcfile.

type FuncFile

type FuncFile struct {
	// just for posterity, this won't be set on old files, but we can check that
	Schema_version int `yaml:"schema_version,omitempty" json:"schema_version,omitempty"`

	Name string `yaml:"name,omitempty" json:"name,omitempty"`

	// Build params
	Version     string   `yaml:"version,omitempty" json:"version,omitempty"`
	Runtime     string   `yaml:"runtime,omitempty" json:"runtime,omitempty"`
	Entrypoint  string   `yaml:"entrypoint,omitempty" json:"entrypoint,omitempty"`
	Cmd         string   `yaml:"cmd,omitempty" json:"cmd,omitempty"`
	Build       []string `yaml:"build,omitempty" json:"build,omitempty"`
	Tests       []FFTest `yaml:"tests,omitempty" json:"tests,omitempty"`
	BuildImage  string   `yaml:"build_image,omitempty" json:"build_image,omitempty"` // Image to use as base for building
	RunImage    string   `yaml:"run_image,omitempty" json:"run_image,omitempty"`     // Image to use for running
	ContentType string   `yaml:"content_type,omitempty" json:"content_type,omitempty"`

	// Route params
	// TODO embed models.Route
	Type        string                 `yaml:"type,omitempty" json:"type,omitempty"`
	Memory      uint64                 `yaml:"memory,omitempty" json:"memory,omitempty"`
	Cpus        string                 `yaml:"cpus,omitempty" json:"cpus,omitempty"`
	Timeout     *int32                 `yaml:"timeout,omitempty" json:"timeout,omitempty"`
	Path        string                 `yaml:"path,omitempty" json:"path,omitempty"`
	Config      map[string]string      `yaml:"config,omitempty" json:"config,omitempty"`
	IDLETimeout *int32                 `yaml:"idle_timeout,omitempty" json:"idle_timeout,omitempty"`
	Annotations map[string]interface{} `yaml:"annotations,omitempty" json:"annotations,omitempty"`

	// Run/test
	Expects Expects `yaml:"expects,omitempty" json:"expects,omitempty"`
}

FuncFile defines the internal structure of a func.yaml/json/yml

func BuildFunc

func BuildFunc(verbose bool, fpath string, funcfile *FuncFile, buildArg []string, noCache bool) (*FuncFile, error)

BuildFunc bumps version and builds function.

func BumpIt

func BumpIt(fpath string, vtype VType) (*FuncFile, error)

BumpIt returns updated funcfile

func FindAndParseFuncfile

func FindAndParseFuncfile(path string) (fpath string, ff *FuncFile, err error)

FindAndParseFuncfile for a func.yaml/json/yml file.

func LoadFuncfile

func LoadFuncfile(path string) (string, *FuncFile, error)

LoadFuncfile returns a parsed funcfile.

func ParseFuncfile

func ParseFuncfile(path string) (*FuncFile, error)

ParseFuncfile check file type to decode and parse.

func (*FuncFile) ImageName

func (ff *FuncFile) ImageName() string

ImageName returns the name of a funcfile image

func (*FuncFile) RuntimeTag

func (ff *FuncFile) RuntimeTag() (runtime, tag string)

RuntimeTag returns the runtime and tag.

type FuncFileV20180708

type FuncFileV20180708 struct {
	Schema_version int `yaml:"schema_version,omitempty" json:"schema_version,omitempty"`

	Name         string `yaml:"name,omitempty" json:"name,omitempty"`
	Version      string `yaml:"version,omitempty" json:"version,omitempty"`
	Runtime      string `yaml:"runtime,omitempty" json:"runtime,omitempty"`
	Build_image  string `yaml:"build_image,omitempty" json:"build_image,omitempty"` // Image to use as base for building
	Run_image    string `yaml:"run_image,omitempty" json:"run_image,omitempty"`     // Image to use for running
	Cmd          string `yaml:"cmd,omitempty" json:"cmd,omitempty"`
	Entrypoint   string `yaml:"entrypoint,omitempty" json:"entrypoint,omitempty"`
	Content_type string `yaml:"content_type,omitempty" json:"content_type,omitempty"`
	Type         string `yaml:"type,omitempty" json:"type,omitempty"`
	Memory       uint64 `yaml:"memory,omitempty" json:"memory,omitempty"`
	Timeout      *int32 `yaml:"timeout,omitempty" json:"timeout,omitempty"`
	IDLE_timeout *int32 `yaml:"idle_timeout,omitempty" json:"idle_timeout,omitempty"`

	Config      map[string]string      `yaml:"config,omitempty" json:"config,omitempty"`
	Annotations map[string]interface{} `yaml:"annotations,omitempty" json:"annotations,omitempty"`

	SigningDetails SigningDetails `yaml:"signing_details,omitempty" json:"signing_details,omitempty""`

	Build []string `yaml:"build,omitempty" json:"build,omitempty"`

	Expects  Expects   `yaml:"expects,omitempty" json:"expects,omitempty"`
	Triggers []Trigger `yaml:"triggers,omitempty" json:"triggers,omitempty"`
}

FuncFileV20180708 defines the latest internal structure of a func.yaml/json/yml

func BuildFuncV20180708

func BuildFuncV20180708(verbose bool, fpath string, funcfile *FuncFileV20180708, buildArg []string, noCache bool, shape string) (*FuncFileV20180708, error)

BuildFunc bumps version and builds function.

func BumpItV20180708

func BumpItV20180708(fpath string, vtype VType) (*FuncFileV20180708, error)

BumpIt returns updated funcfile

func FindAndParseFuncFileV20180708

func FindAndParseFuncFileV20180708(path string) (fpath string, ff *FuncFileV20180708, err error)

func LoadFuncFileV20180708

func LoadFuncFileV20180708(path string) (string, *FuncFileV20180708, error)

func ParseFuncFileV20180708

func ParseFuncFileV20180708(path string) (ff *FuncFileV20180708, err error)

func (*FuncFileV20180708) ImageNameV20180708

func (ff *FuncFileV20180708) ImageNameV20180708() string

ImageName returns the name of a funcfile image

type InputMap

type InputMap struct {
	Body interface{}
}

InputMap to be used within FFTest.

type NotFoundError

type NotFoundError struct {
	S string
}

NotFoundError represents error string.

func NewNotFoundError

func NewNotFoundError(s string) *NotFoundError

NewNotFoundError returns a new error.

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

type OutputMap

type OutputMap struct {
	Body interface{}
}

OutputMap to be used within FFTest.

type SigningDetails

type SigningDetails struct {
	ImageCompartmentId string `yaml:"image_compartment_id,omitempty" json:"image_compartment_id,omitempty"`
	KmsKeyId           string `yaml:"kms_key_id,omitempty" json:"kms_key_id,omitempty"`
	KmsKeyVersionId    string `yaml:"kms_key_version_id,omitempty" json:"kms_key_version_id,omitempty"`
	SigningAlgorithm   string `yaml:"signing_algorithm,omitempty" json:"signing_algorithm,omitempty"`
}

SigningDetails defines configuration for signing a function image

type Trigger

type Trigger struct {
	Name   string `yaml:"name,omitempty" json:"name,omitempty"`
	Type   string `yaml:"type,omitempty" json:"type,omitempty"`
	Source string `yaml:"source,omitempty" json:"source,omitempty"`
}

Trigger represents a trigger for a FuncFileV20180708

type VType

type VType int

VType represents the version type

const (
	Patch VType = iota
	Minor
	Major
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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