Documentation
¶
Overview ¶
Package projectfile reads and writes runr.yaml, the project file of a RunR project directory, and turns it into API payloads.
Index ¶
- Constants
- Variables
- func CollectFiles(dir string, extraIgnore []string) ([]runr.File, error)
- func Diff(want runr.ConfigInput, have runr.ProjectConfig) (runr.ConfigInput, []string)
- func DiffStrategy(want runr.DeployStrategyInput, have runr.DeployStrategySettings) (runr.DeployStrategyInput, []string)
- func Find(dir string) (string, error)
- func Ignored(rel string, patterns []string) bool
- func Slug(name string) string
- func ValidateCanarySteps(steps []int) error
- func ValidateHealthPath(path string) error
- func ValidateName(name string) error
- type BlueGreen
- type Canary
- type Deploy
- type Dev
- type File
- func (f *File) Config() runr.ConfigInput
- func (f *File) DeployStrategy() *runr.DeployStrategyInput
- func (f *File) Dir() string
- func (f *File) HandlerName() string
- func (f *File) MainFile() string
- func (f *File) Marshal() ([]byte, error)
- func (f *File) Normalize()
- func (f *File) Path() string
- func (f *File) Primary() string
- func (f *File) QueueStream() string
- func (f *File) TriggerSpecs() []runr.TriggerSpec
- func (f *File) TriggerType() string
- func (f *File) Validate() error
- func (f *File) Warnings() []string
- type Global
- type Network
- type Resources
- type Scale
- type ScheduleRow
- type Trigger
- type TriggerEntry
- type ValidationError
Constants ¶
const FileName = "runr.yaml"
FileName is the project file name; runr.yml is accepted as well.
Variables ¶
var DefaultIgnore = []string{ ".git", ".hg", ".svn", ".runr", ".idea", ".vscode", ".DS_Store", "Thumbs.db", "node_modules", "vendor", "__pycache__", "*.pyc", ".venv", "venv", ".env", ".env.*", ".gitignore", ".runrignore", FileName, "runr.yml", }
DefaultIgnore are never uploaded.
var ErrNotFound = errors.New("no runr.yaml found (run `runr init` or pass --project)")
ErrNotFound means no runr.yaml was found.
Functions ¶
func CollectFiles ¶
CollectFiles returns the files of a faas project directory as the API stores them: a flat set (each file becomes a ConfigMap key), UTF-8 text, at most runr.MaxCodeBytes in total.
func Diff ¶
func Diff(want runr.ConfigInput, have runr.ProjectConfig) (runr.ConfigInput, []string)
Diff returns the part of want that differs from the server config, and the names of the changed fields. Environment variables merge: keys in want replace, other server keys stay.
func DiffStrategy ¶ added in v0.6.0
func DiffStrategy(want runr.DeployStrategyInput, have runr.DeployStrategySettings) (runr.DeployStrategyInput, []string)
DiffStrategy returns the part of want that differs from the project's settings, and the names of the changed settings (strategy, blue_green.health_path, canary.steps, …).
func Ignored ¶
Ignored reports whether a slash-separated relative path matches one of the patterns. A pattern without "/" matches any path element; with "/" it matches the whole path.
func ValidateCanarySteps ¶ added in v0.6.0
ValidateCanarySteps checks canary steps: 1 to 10 strictly increasing percentages of 1-100.
func ValidateHealthPath ¶ added in v0.6.0
ValidateHealthPath checks the path of blue-green health checks: it starts with / and has no spaces (at most 255 characters).
func ValidateName ¶
ValidateName checks a project name against the API's slug rule.
Types ¶
type BlueGreen ¶ added in v0.6.0
type BlueGreen struct {
AutoPromote *bool `yaml:"auto_promote,omitempty"`
HealthPath *string `yaml:"health_path,omitempty"`
HealthChecks *int `yaml:"health_checks,omitempty"`
KeepPreviousMinutes *int `yaml:"keep_previous_minutes,omitempty"`
// contains filtered or unexported fields
}
BlueGreen are the blue-green options of runr.yaml. Unset fields keep the project's value; health_path: null (or "") clears the path, so readiness alone decides.
type Canary ¶ added in v0.6.0
type Canary struct {
Steps []int `yaml:"steps,omitempty"`
IntervalMinutes *int `yaml:"interval_minutes,omitempty"`
ErrorRateThreshold *float64 `yaml:"error_rate_threshold,omitempty"`
P95ThresholdMs *int `yaml:"p95_threshold_ms,omitempty"`
// contains filtered or unexported fields
}
Canary are the canary options of runr.yaml. Unset fields keep the project's value; a threshold set to null is not checked.
type Deploy ¶ added in v0.6.0
type Deploy struct {
// Strategy is direct, blue-green or canary (blue_green and bluegreen are accepted).
Strategy string `yaml:"strategy,omitempty"`
BlueGreen *BlueGreen `yaml:"blue_green,omitempty"`
// BlueGreenAlias is the section spelled blue-green; Normalize moves it to BlueGreen.
BlueGreenAlias *BlueGreen `yaml:"blue-green,omitempty"`
Canary *Canary `yaml:"canary,omitempty"`
}
Deploy is the deploy section of runr.yaml: the project's deploy strategy and its options. `runr deploy` applies what it sets before deploying (PUT deploy-strategy, only what differs from the project's settings); a git push applies it as well.
deploy:
strategy: canary # direct | blue-green | canary
blue_green: { auto_promote: true, health_path: /healthz, health_checks: 3, keep_previous_minutes: 15 }
canary: { steps: [10, 50, 100], interval_minutes: 5, error_rate_threshold: 5, p95_threshold_ms: 800 }
type File ¶
type File struct {
// Name of the project; its slug names the service and the default URL.
Name string `yaml:"name"`
// Type is faas (function, several files), xaas (single-file script) or caas (container).
Type string `yaml:"type"`
// Runtime and RuntimeVersion of faas/xaas projects (python, nodejs, go, php, …).
Runtime string `yaml:"runtime,omitempty"`
RuntimeVersion string `yaml:"runtime_version,omitempty"`
// Region name or id; may be omitted when exactly one region is available. In a global
// project it is the primary region (default: the first of global.regions).
Region string `yaml:"region,omitempty"`
// Global makes the project a global project: it runs in every region of global.regions
// behind one global host name (docs/global-projects.md).
Global *Global `yaml:"global,omitempty"`
Description string `yaml:"description,omitempty"`
// Handler: faas "file.function" (main.handler → main.py, def handler); xaas the function name.
Handler string `yaml:"handler,omitempty"`
// File is the script of an xaas project (main.py).
File string `yaml:"file,omitempty"`
// Image, Command, Args and Ports of a caas project.
Image string `yaml:"image,omitempty"`
Command []string `yaml:"command,omitempty"`
Args []string `yaml:"args,omitempty"`
Ports []int `yaml:"ports,omitempty"`
Resources *Resources `yaml:"resources,omitempty"`
Scale *Scale `yaml:"scale,omitempty"`
Trigger *Trigger `yaml:"trigger,omitempty"`
// Deploy sets the deploy strategy (direct, blue-green, canary) and its options (deploy.go).
Deploy *Deploy `yaml:"deploy,omitempty"`
// Triggers is the project's whole trigger list (docs/triggers.md), applied with PUT
// /projects/{project}/triggers on deploy; it replaces trigger.
Triggers []TriggerEntry `yaml:"triggers,omitempty"`
// Env holds non-secret environment variables. Secrets are set with `runr env set --secret`.
Env map[string]string `yaml:"env,omitempty"`
// Network is who reaches the project: its access mode and the projects allowed to call it
// on the region's internal network (docs/internal-network.md).
Network *Network `yaml:"network,omitempty"`
// Ignore lists extra glob patterns of files that are not uploaded.
Ignore []string `yaml:"ignore,omitempty"`
// Dev configures `runr dev`.
Dev *Dev `yaml:"dev,omitempty"`
// contains filtered or unexported fields
}
File is runr.yaml.
func (*File) Config ¶
func (f *File) Config() runr.ConfigInput
Config returns the config the file asks for. Unset fields stay nil (server defaults).
func (*File) DeployStrategy ¶ added in v0.6.0
func (f *File) DeployStrategy() *runr.DeployStrategyInput
DeployStrategy returns what the deploy section sets as a partial update of the project's deploy strategy; nil without a deploy section or when it sets nothing.
func (*File) HandlerName ¶
HandlerName is the function the wrapper calls.
func (*File) MainFile ¶
MainFile is the file that holds the handler: faas "main.handler" → main.py, xaas File.
func (*File) Normalize ¶
func (f *File) Normalize()
Normalize fills defaults that do not change meaning.
func (*File) Primary ¶ added in v0.6.0
Primary returns the primary region of a global project: region when set, else the first of global.regions.
func (*File) QueueStream ¶ added in v0.6.0
QueueStream returns the Redis stream of the queue trigger ("" without one).
func (*File) TriggerSpecs ¶ added in v0.6.0
func (f *File) TriggerSpecs() []runr.TriggerSpec
TriggerSpecs returns `triggers:` as the API's list (PUT /projects/{project}/triggers); nil when the file has no trigger list.
func (*File) TriggerType ¶
TriggerType returns how the function is invoked: the trigger type, http by default. With a trigger list it is http when the list serves HTTP (http, workflow), schedule for a schedule alone, and queue otherwise (the event gateway delivers every event as a CloudEvent POST, like a queue message).
type Global ¶ added in v0.6.0
type Global struct {
// Regions are region names or ids, two or more; the primary region (region) among them.
Regions []string `yaml:"regions"`
// Mode is ha (default: the primary region, the others when it is unhealthy) or proximity
// (the healthy region closest to the client).
Mode string `yaml:"mode,omitempty"`
}
Global lists the regions of a global project and how DNS picks one of them.
type Network ¶ added in v0.6.0
type Network struct {
Access string `yaml:"access,omitempty"`
AllowCIDRs []string `yaml:"allow_cidrs,omitempty"`
Callers []string `yaml:"callers,omitempty"`
}
Network: Access is public (default), allowlist (the public URL answers AllowCIDRs only) or internal (no public URL). Callers, when given, is the whole allow list: project names of the organization or internal names <project>.<organization>.
type Resources ¶
type Resources struct {
CPU string `yaml:"cpu,omitempty"`
MemoryMB int `yaml:"memory_mb,omitempty"`
TimeoutSeconds int `yaml:"timeout_seconds,omitempty"`
}
Resources are the container limits.
type Scale ¶
type Scale struct {
Min *int `yaml:"min,omitempty"`
Max *int `yaml:"max,omitempty"`
ToZero *bool `yaml:"to_zero,omitempty"`
// Schedule is the timed warmer: from the moment a row's cron expression fires (in the
// organization's time zone) at least Min containers stay warm until the next row fires; it
// replaces scale.min while set. Absent leaves the server's schedule alone, [] turns it off.
Schedule *[]ScheduleRow `yaml:"schedule,omitempty"`
}
Scale is the autoscaling range.
type ScheduleRow ¶ added in v0.6.0
ScheduleRow is one row of scale.schedule.
type Trigger ¶
type Trigger struct {
Type string `yaml:"type"`
Schedule string `yaml:"schedule,omitempty"`
Queue string `yaml:"queue,omitempty"`
}
Trigger says what starts the code: http (default), schedule (cron) or queue (Redis stream).
type TriggerEntry ¶ added in v0.6.0
type TriggerEntry struct {
Type string `yaml:"type"`
Name string `yaml:"name,omitempty"`
Enabled *bool `yaml:"enabled,omitempty"`
Config map[string]any `yaml:",inline"`
// contains filtered or unexported fields
}
TriggerEntry is one entry of `triggers:`. Type, name and enabled are fields of the trigger; every other key goes into its config (cron, timezone, stream, verify, hmac, topic, events, delivery, …), checked against the API's trigger schema (triggers.schema.json). The shorthands of `trigger:` work too: schedule → cron (type schedule), queue → stream (type queue). Secrets (a webhook's signing secret) are set with `runr triggers update NAME --secret`, never in runr.yaml.
func (*TriggerEntry) UnmarshalYAML ¶ added in v0.6.0
func (t *TriggerEntry) UnmarshalYAML(n *yaml.Node) error
UnmarshalYAML reads an entry the way the API reads it: type and name as strings, enabled as a boolean (true / false, 1 / 0, "1" / "0"), every other key as config.
type ValidationError ¶
type ValidationError struct {
Problems []string
}
ValidationError lists every problem of a project file.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string