projectfile

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const FileName = "runr.yaml"

FileName is the project file name; runr.yml is accepted as well.

Variables

View Source
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.

View Source
var ErrNotFound = errors.New("no runr.yaml found (run `runr init` or pass --project)")

ErrNotFound means no runr.yaml was found.

Functions

func CollectFiles

func CollectFiles(dir string, extraIgnore []string) ([]runr.File, error)

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

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

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 Find

func Find(dir string) (string, error)

Find looks for runr.yaml in dir and its parents.

func Ignored

func Ignored(rel string, patterns []string) bool

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 Slug

func Slug(name string) string

Slug derives the slug the API gives a project name (Laravel Str::slug for ASCII names).

func ValidateCanarySteps added in v0.6.0

func ValidateCanarySteps(steps []int) error

ValidateCanarySteps checks canary steps: 1 to 10 strictly increasing percentages of 1-100.

func ValidateHealthPath added in v0.6.0

func ValidateHealthPath(path string) error

ValidateHealthPath checks the path of blue-green health checks: it starts with / and has no spaces (at most 255 characters).

func ValidateName

func ValidateName(name string) error

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.

func (*BlueGreen) UnmarshalYAML added in v0.6.0

func (b *BlueGreen) UnmarshalYAML(n *yaml.Node) error

UnmarshalYAML rejects unknown keys and remembers the keys set to null.

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.

func (*Canary) UnmarshalYAML added in v0.6.0

func (c *Canary) UnmarshalYAML(n *yaml.Node) error

UnmarshalYAML rejects unknown keys and remembers the keys set to null.

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 Dev

type Dev struct {
	Port int               `yaml:"port,omitempty"`
	Env  map[string]string `yaml:"env,omitempty"`
}

Dev configures the local runner.

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 Load

func Load(path string) (*File, error)

Load reads and validates a project file.

func Parse

func Parse(data []byte) (*File, error)

Parse decodes and validates runr.yaml content.

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) Dir

func (f *File) Dir() string

Dir returns the project directory.

func (*File) HandlerName

func (f *File) HandlerName() string

HandlerName is the function the wrapper calls.

func (*File) MainFile

func (f *File) MainFile() string

MainFile is the file that holds the handler: faas "main.handler" → main.py, xaas File.

func (*File) Marshal

func (f *File) Marshal() ([]byte, error)

Marshal renders a project file.

func (*File) Normalize

func (f *File) Normalize()

Normalize fills defaults that do not change meaning.

func (*File) Path

func (f *File) Path() string

Path returns the file the project was loaded from.

func (*File) Primary added in v0.6.0

func (f *File) Primary() string

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

func (f *File) QueueStream() string

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

func (f *File) TriggerType() string

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).

func (*File) Validate

func (f *File) Validate() error

Validate checks the file without contacting the API.

func (*File) Warnings added in v0.6.0

func (f *File) Warnings() []string

Warnings are what Normalize left out or the API ignores without refusing the file: trigger next to triggers, secrets in a trigger entry, config keys a trigger type does not have.

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

type ScheduleRow struct {
	Cron string `yaml:"cron"`
	Min  int    `yaml:"min"`
}

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

Jump to

Keyboard shortcuts

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