dubbo

package
v0.0.0-...-a4cc684 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DubboFile is the file used for the serialized form of a function.
	DubboFile = "dubbo.yaml"

	Dockerfile = "Dockerfile"

	// RunDataDir holds transient runtime metadata
	// By default it is excluded from source control.
	RunDataDir = ".dubbo"
)
View Source
const (
	DefaultRepositoryName = "default"
)
View Source
const (
	// DefaultTemplate is the default function signature / environmental context
	// of the resultant function.  All runtimes are expected to have at least
	// one implementation of each supported function signature.  Currently that
	// includes common
	DefaultTemplate = "common"
)
View Source
const (
	DefaultTemplatesPath = "."
)

Variables

View Source
var (
	DockerfileGolang = `` /* 853-byte string literal not displayed */

	DockerfileJava = `` /* 201-byte string literal not displayed */

	DockerfileByRuntime = map[string]string{
		"go":   DockerfileGolang,
		"java": DockerfileJava,
	}
)
View Source
var (
	// ErrTemplateRepoDoesNotExist is a sentinel error if a template repository responds with 404 status code
	ErrTemplateRepoDoesNotExist  = errors.New("template repo does not exist")
	ErrEnvironmentNotFound       = errors.New("environment not found")
	ErrMismatchedName            = errors.New("name passed the function source")
	ErrNameRequired              = errors.New("name required")
	ErrNotBuilt                  = errors.New("not built")
	ErrNotRunning                = errors.New("function not running")
	ErrRepositoriesNotDefined    = errors.New("custom template repositories location not specified")
	ErrRepositoryNotFound        = errors.New("repository not found")
	ErrRootRequired              = errors.New("function root path is required")
	ErrRuntimeNotFound           = errors.New("language runtime not found")
	ErrRuntimeRequired           = errors.New("language runtime required")
	ErrTemplateMissingRepository = errors.New("template name missing repository prefix")
	ErrTemplateNotFound          = errors.New("template not found")
	ErrTemplatesNotFound         = errors.New("templates path (runtimes) not found")
	ErrContextCanceled           = errors.New("the operation was canceled")
)
View Source
var EmbeddedTemplatesFS = newEmbeddedTemplatesFS()

Functions

func EnsureRunDataDir

func EnsureRunDataDir(root string) error

EnsureRunDataDir creates a .dubbo directory at the given path, and registers it as ignored in a .gitignore file.

func FilesystemFromRepo

func FilesystemFromRepo(uri string) (filesystem.Filesystem, error)

FilesystemFromRepo attempts to fetch a filesystem from a git repository indicated by the given URI. Returns nil if there is not a repo at the URI.

func Fingerprint

func Fingerprint(f *Dubbo) (hash, log string, err error)

Fingerprint the files at a given path. Returns a hash calculated from the filenames and modification timestamps of the files within the given root. Also returns a logfile consisting of the filenames and modification times which contributed to the hash. Intended to determine if there were appreciable changes to a function's source code, certain directories and files are ignored, such as .git and .dubbo.

func NewErrNotInitialized

func NewErrNotInitialized(path string) error

Types

type BuildOption

type BuildOption func(c *BuildOptions)

type BuildOptions

type BuildOptions struct{}

type BuildSpec

type BuildSpec struct {
	// BuilderImages define optional explicit builder images to use by
	// builder implementations in lea of the in-code defaults.  They key
	// is the builder's short name.  For example:
	// builderImages:
	//   pack: example.com/user/my-pack-node-builder
	BuilderImages map[string]string `yaml:"builderImages,omitempty"`

	// Optional list of build-packs to use when building the application
	Buildpacks []string `yaml:"buildpacks,omitempty"`

	BuildEnvs []Env `json:"buildEnvs,omitempty"`
}

type Builder

type Builder interface {
	// Build a function project with source located at path.
	Build(context.Context, *Dubbo) error
}

Builder of function source to runnable image.

type Client

type Client struct {
	KubeCtl *kube.CtlClient // Kube Client
	// contains filtered or unexported fields
}

func New

func New(options ...Option) *Client

New client for function management.

func (*Client) Build

func (c *Client) Build(ctx context.Context, f *Dubbo, options ...BuildOption) (*Dubbo, error)

Build the function at path. Errors if the function is either unloadable or does not contain a populated Image.

func (*Client) Deploy

func (c *Client) Deploy(ctx context.Context, d *Dubbo, opts ...DeployOption) (*Dubbo, error)

func (*Client) Init

func (c *Client) Init(cfg *Dubbo, init bool, cmd *cobra.Command) (*Dubbo, error)

Init Initialize a new function with the given function struct defaults. Does not build/push/deploy. Local FS changes only. For higher-level control see New or Apply.

<path> will default to the absolute path of the current working directory. <name> will default to the current working directory. When <name> is provided but <path> is not, a directory <name> is created in the current working directory and used for <path>.

func (*Client) Push

func (c *Client) Push(ctx context.Context, f *Dubbo) (*Dubbo, error)

Push the image for the named service to the configured registry

func (*Client) Repositories

func (c *Client) Repositories() *Repositories

Repositories accessor

func (*Client) Runtimes

func (c *Client) Runtimes() ([]string, error)

Runtimes available in totality. Not all repository/template combinations necessarily exist, and further validation is performed when a template+runtime is chosen. from a given repository. This is the global list of all available. Returned list is unique and sorted.

func (*Client) Templates

func (c *Client) Templates() *Templates

Templates accessor

type DeployApp

type DeployApp struct{}

func NewDeployer

func NewDeployer(opts ...DeployerOpt) *DeployApp

func (*DeployApp) Deploy

func (d *DeployApp) Deploy(ctx context.Context, f *Dubbo, option ...DeployOption) (DeploymentResult, error)

type DeployOption

type DeployOption func(f *DeployParams)

type DeployParams

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

type DeploySpec

type DeploySpec struct {
	Namespace     string `yaml:"namespace,omitempty"`
	Output        string `yaml:"output,omitempty"`
	ContainerPort int    `yaml:"containerPort,omitempty"`
	TargetPort    int    `yaml:"targetPort,omitempty"`
	NodePort      int    `yaml:"nodePort,omitempty"`
	UseProm       bool   `yaml:"-"`
}

type Deployer

type Deployer interface {
	// Deploy a function of given name, using given backing image.
	Deploy(context.Context, *Dubbo, ...DeployOption) (DeploymentResult, error)
}

Deployer of function source to running status.

type DeployerOpt

type DeployerOpt func(deployer *DeployApp)

type Deployment

type Deployment struct {
	Name        string
	Namespace   string
	Image       string
	Port        int
	TargetPort  int
	NodePort    int
	UseNodePort bool
	UseProm     bool
}

type DeploymentResult

type DeploymentResult struct {
	Status    Status
	Namespace string
}

type Dubbo

type Dubbo struct {
	// Root on disk at which to find/create source and config files.
	Root string `yaml:"-"`

	// Name of the application.
	Name string `yaml:"name,omitempty" jsonschema:"pattern=^[a-z0-9]([-a-z0-9]*[a-z0-9])?$"`

	// Runtime is the language plus context.  java|go etc.
	Runtime string `yaml:"runtime,omitempty"`

	// Template for the application.
	Template string `yaml:"template,omitempty"`

	// Optional full OCI image tag in form:
	//   [registry]/[namespace]/[name]:[tag]
	// example:
	//   quay.io/alice/my.function.name
	// Registry is optional and is defaulted to DefaultRegistry
	// example:
	//   alice/my.function.name
	// If Image is provided, it overrides the default of concatenating
	// "Registry+Name:latest" to derive the Image.
	Image string `yaml:"image,omitempty"`

	// SHA256 hash of the latest image that has been built
	ImageDigest string `yaml:"-"`

	// Created time is the moment that creation was successfully completed
	// according to the client which is in charge of what constitutes being
	// fully "Created" (aka initialized)
	Created time.Time `yaml:"created,omitempty"`

	// BuildSpec define the build properties for a function
	Build BuildSpec `yaml:"build,omitempty"`

	// DeploySpec define the deployment properties for a function
	Deploy DeploySpec `yaml:"deploy,omitempty"`
}

func NewDubbo

func NewDubbo(path string) (*Dubbo, error)

NewDubbo from a given path. Invalid paths, or no function at path are errors. Syntactic errors are returned immediately (yaml unmarshal errors). Dubbo which are syntactically valid are also then logically validated. Dubbo from earlier versions are brought up to current using migrations. Migrations are run prior to validators such that validation can omit concerning itself with backwards compatibility. Migrators must therefore selectively consider the minimal validation necessary to enable migration.

func NewDubboWith

func NewDubboWith(defaults *Dubbo, init bool) *Dubbo

NewDubboWith defaults as provided.

func (Dubbo) BuildStamp

func (f Dubbo) BuildStamp() string

BuildStamp accesses the current (last) build stamp for the function. Inbuilt functions return empty string.

func (*Dubbo) Built

func (f *Dubbo) Built() bool

Built returns true if the application is considered built. Note that this only considers the application as it exists on-disk at f.Root.

func (*Dubbo) CheckLabels

func (f *Dubbo) CheckLabels(ns string, client *Client) error

func (*Dubbo) EnsureDockerfile

func (f *Dubbo) EnsureDockerfile(cmd *cobra.Command) (err error)

func (*Dubbo) Initialized

func (f *Dubbo) Initialized() bool

Initialized returns if the function has been initialized. Any errors are considered failure (invalid or inaccessible root, config file, etc).

func (*Dubbo) Stamp

func (f *Dubbo) Stamp(oo ...stampOption) (err error)

Stamp a function as being built.

This is a performance optimization used when updates to the function are known to have no effect on its built container. This stamp is checked before certain operations, and if it has been updated, the build can be skipped. If in doubt, just use .Write only.

Updates the build stamp at ./dubbo/built (and the log at .dubbo/built.log) to reflect the current state of the filesystem. Note that the caller should call .Write first to flush any changes to the application in-memory to the filesystem prior to calling stamp.

The runtime data directory .dubbo is created in the application root if necessary.

func (*Dubbo) Validate

func (f *Dubbo) Validate() error

func (*Dubbo) Write

func (f *Dubbo) Write() (err error)

Write aka (save, serialize, marshal) the function to disk at its path. Only valid functions can be written. In order to retain built status (staleness checks), the file is only modified if the structure actually changes.

type Env

type Env struct {
	Name  *string `yaml:"name,omitempty" jsonschema:"pattern=^[-._a-zA-Z][-._a-zA-Z0-9]*$"`
	Value *string `yaml:"value,omitempty"`
}

type ErrNotInitialized

type ErrNotInitialized struct {
	Path string
}

ErrNotInitialized indicates that a function is uninitialized

func (ErrNotInitialized) Error

func (e ErrNotInitialized) Error() string

type ErrRunTimeout

type ErrRunTimeout struct {
	Timeout time.Duration
}

func (ErrRunTimeout) Error

func (e ErrRunTimeout) Error() string

type ErrRunnerNotImplemented

type ErrRunnerNotImplemented struct {
	Runtime string
}

ErrRunnerNotImplemented indicates the feature is not available for the requested runtime.

func (ErrRunnerNotImplemented) Error

func (e ErrRunnerNotImplemented) Error() string

type ErrRuntimeNotRecognized

type ErrRuntimeNotRecognized struct {
	Runtime string
}

ErrRuntimeNotRecognized indicates a runtime which is not in the set of those known.

func (ErrRuntimeNotRecognized) Error

func (e ErrRuntimeNotRecognized) Error() string

type Label

type Label struct {
	// Key consist of optional prefix part (ended by '/') and name part
	// Prefix part validation pattern: [a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*
	// Name part validation pattern: ([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]
	Key   *string `` /* 144-byte string literal not displayed */
	Value *string `yaml:"value,omitempty" jsonschema:"pattern=^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$"`
}

type Option

type Option func(*Client)

Option defines a function which when passed to the Client constructor optionally mutates private members at time of instantiation.

func WithBuilder

func WithBuilder(d Builder) Option

WithBuilder provides the concrete implementation of a builder.

func WithDeployer

func WithDeployer(d Deployer) Option

func WithKubeClient

func WithKubeClient(client *kube.CtlClient) Option

func WithPusher

func WithPusher(pusher Pusher) Option

func WithRepositoriesPath

func WithRepositoriesPath(path string) Option

WithRepositoriesPath sets the location on disk to use for extensible template repositories. Extensible template repositories are additional templates that exist on disk and are not built into the binary.

func WithRepository

func WithRepository(uri string) Option

WithRepository sets a specific URL to a Git repository from which to pull templates. This setting's existence precldes the use of either the inbuilt templates or any repositories from the extensible repositories path.

type Pusher

type Pusher interface {
	// Push the image of the function.
	// Returns Image Digest - SHA256 hash of the produced image
	Push(ctx context.Context, f *Dubbo) (string, error)
}

Pusher of function image to a registry.

type Repositories

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

Repositories manager

func (*Repositories) Add

func (r *Repositories) Add(name, uri string) (string, error)

Add a repository of the given name from the URI. Name, if not provided, defaults to the repo name (sans optional .git suffix). Returns the final name as added.

func (*Repositories) All

func (r *Repositories) All() (repos []Repository, err error)

All repositories under management The default repository is always first. If a path to custom repositories is defined, these are included next. If repositories is in single-repo mode, it will be the only repo returned.

func (*Repositories) Get

func (r *Repositories) Get(name string) (repo Repository, err error)

Get a repository by name, error if it does not exist.

func (*Repositories) List

func (r *Repositories) List() ([]string, error)

List all repositories the current configuration of the repo manager has defined.

func (*Repositories) Path

func (r *Repositories) Path() string

Path returns the currently active repositories path under management. Blank indicates that the system was not instantiated to use any repositories on disk.

func (*Repositories) Remove

func (r *Repositories) Remove(name string) error

Remove a repository of the given name from the repositories. (removes its directory in Path)

func (*Repositories) Rename

func (r *Repositories) Rename(from, to string) error

Rename a repository

type Repository

type Repository struct {
	// Name of the repository
	// This can be for instance:
	// directory name on FS or last part of git URL or arbitrary value defined by the Template author.
	Name string
	// Runtimes containing Templates loaded from the repo
	Runtimes []Runtime
	// contains filtered or unexported fields
}

Repository represents a collection of runtimes, each containing templates.

func NewRepository

func NewRepository(name, uri string) (r Repository, err error)

func (*Repository) Runtime

func (r *Repository) Runtime(name string) (runtime Runtime, err error)

Runtime of the given name within the repository.

func (*Repository) Template

func (r *Repository) Template(runtimeName, name string) (t Template, err error)

Template from repo for given runtime.

func (*Repository) Templates

func (r *Repository) Templates(runtimeName string) ([]Template, error)

Templates returns the set of all templates for a given runtime. If runtime not found, an empty list is returned.

func (*Repository) URL

func (r *Repository) URL() string

URL attempts to read the remote git origin URL of the repository. Best effort; returns empty string if the repository is not a git repo or the repo has been mutated beyond recognition on disk (ex: removing the origin remote)

func (*Repository) Write

func (r *Repository) Write(dest string) (err error)

Write all files in the repository to the given path.

type Runtime

type Runtime struct {
	// Name of the runtime
	Name string
	// Templates defined for the runtime
	Templates []Template
}

Runtime is a division of templates within a repository of templates for a given runtime (source language plus environmentally available services and libraries)

type Status

type Status int
const (
	Failed Status = iota
	Deployed
)

type Template

type Template interface {
	// Name of this template.
	Name() string
	// Runtime for which this template applies.
	Runtime() string
	// Repository within which this template is contained.  Value is set to the
	// currently effective name of the repository, which may vary. It is user-
	// defined when the repository is added, and can be set to "default" when
	// the client is loaded in single repo mode. I.e. not canonical.
	Repository() string
	// Fullname is a calculated field of [repo]/[name] used
	// to uniquely reference a template which may share a name
	// with one in another repository.
	Fullname() string
	// Write updates fields of function f and writes project files to path pointed by f.Root.
	Write(ctx context.Context, f *Dubbo) error
}

Template is a function project template. It can be used to instantiate new function project.

type Templates

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

Templates Manager

func (*Templates) Get

func (t *Templates) Get(runtime, fullname string) (Template, error)

func (*Templates) List

func (t *Templates) List(runtime string) ([]string, error)

List the full name of templates available for the runtime. Full name is the optional repository prefix plus the template's repository local name. Default templates grouped first sans prefix.

func (*Templates) Write

func (t *Templates) Write(f *Dubbo) error

Write a function's template to disk. Returns a function which may have been modified dependent on the content of the template (which can define default function fields, builders, build packs, etc)

Jump to

Keyboard shortcuts

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