spec

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: Apache-2.0 Imports: 15 Imported by: 1 module, 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 spec defines anyship.yaml: a platform-neutral description of what an app needs (processes, ports, disks, databases, secrets), not how a given platform provides it. Adapters translate it into platform config and either satisfy each need or report that they can't.

Index

Constants

View Source
const (
	// APIVersion is the manifest version this package reads and writes.
	APIVersion = "anyship/v1alpha1"
	// Kind is the manifest kind for an app.
	Kind = "App"
	// Filename is the conventional spec file name.
	Filename = "anyship.yaml"
	// LegacyFilename is the spec file name anyship used up to v0.2.x.
	LegacyFilename = "anyship.json"
	// ChangelogURL is where the move from anyship.json to anyship.yaml is described.
	ChangelogURL = "https://github.com/j75689/anyship/blob/main/CHANGELOG.md"
	// SchemaURL is where editors find the JSON Schema for anyship.yaml.
	SchemaURL = "https://raw.githubusercontent.com/j75689/anyship/main/schema/anyship.schema.json"
)
View Source
const (
	NamePattern       = `^[a-z][a-z0-9-]{0,62}$`
	SecretNamePattern = `^[A-Z][A-Z0-9_]*$`
	SizePattern       = `^\d+(GB|TB)$`
	MemoryPattern     = `^([1-9]\d{0,5})(MB|GB)$`
	// DomainPattern matches a fully qualified domain name. It accepts either
	// case, because Normalize lowercases domains; wildcards are left out on
	// purpose, since no target attaches them.
	DomainPattern = `^(?:[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?\.)+[A-Za-z]{2,63}$`
)

Variables

This section is empty.

Functions

func ExpandServiceURLs added in v0.4.0

func ExpandServiceURLs(value string, url func(service string) string) string

ExpandServiceURLs replaces every reference in an env value with the URL the function gives for the service.

func JSONSchema

func JSONSchema() ([]byte, error)

JSONSchema returns a JSON Schema for anyship.yaml, so editors can validate and autocomplete it (see the yaml-language-server comment Marshal writes). Cross-field rules (unknown resources and the like) are only enforced by Validate.

func Marshal added in v0.3.0

func Marshal(s *Spec) ([]byte, error)

Marshal renders a spec as anyship.yaml, with a schema hint for editors.

func ServiceRefs added in v0.4.0

func ServiceRefs(value string) []string

ServiceRefs lists the services an env value refers to.

Types

type Build

type Build struct {
	Command string `json:"command,omitempty"`
	// Output is the build output directory, relative to the service path.
	Output string `json:"output,omitempty" jsonschema_description:"Build output directory, relative to the service path."`
}

type Cron

type Cron struct {
	Schedule string `json:"schedule"`
	// Command runs on process-based platforms. Edge platforms invoke their
	// scheduled handler instead.
	Command string `json:"command,omitempty"`
	// Path is called on the service when the schedule fires, on platforms
	// that schedule HTTP calls.
	Path string `` /* 155-byte string literal not displayed */
	// Method is the HTTP method for Path; POST when empty.
	Method string `` /* 150-byte string literal not displayed */
}

Cron is one schedule of a service. An entry names what runs when it fires: a command, or a path of the service to call over HTTP. An entry with neither fires the platform's own handler, as edge runtimes do.

type Exposure

type Exposure string
const (
	ExposurePublic Exposure = "public"
	// ExposureInternal ports are reachable only by other services of the spec.
	ExposureInternal Exposure = "internal"
)

type HealthCheck

type HealthCheck struct {
	Path    string `json:"path,omitempty"`
	Command string `json:"command,omitempty"`
}

type Manifest added in v0.3.0

type Manifest struct {
	APIVersion string   `json:"apiVersion"`
	Kind       string   `json:"kind"`
	Metadata   Metadata `json:"metadata"`
	Spec       *Spec    `json:"spec"`
}

Manifest is the file format, a Kubernetes-style envelope around the app.

func (Manifest) JSONSchemaExtend added in v0.3.0

func (Manifest) JSONSchemaExtend(s *jsonschema.Schema)

JSONSchemaExtend adds the constraints struct tags can't express.

type Metadata added in v0.3.0

type Metadata struct {
	Name string `json:"name" jsonschema_description:"Lowercase letters, digits and dashes, starting with a letter."`
}

func (Metadata) JSONSchemaExtend added in v0.3.0

func (Metadata) JSONSchemaExtend(s *jsonschema.Schema)

type NotFoundError added in v0.3.1

type NotFoundError struct {
	Path string
}

NotFoundError is what Load returns when there is no spec file. It carries the absolute path that was tried: "anyship.yaml" alone does not say which directory the caller was looking in.

func (*NotFoundError) Error added in v0.3.1

func (e *NotFoundError) Error() string

func (*NotFoundError) Unwrap added in v0.3.1

func (e *NotFoundError) Unwrap() error

type Port

type Port struct {
	Name     string   `json:"name,omitempty"`
	Port     int      `json:"port" jsonschema:"minimum=1,maximum=65535"`
	Protocol Protocol `json:"protocol,omitempty" jsonschema:"enum=http,enum=tcp,enum=udp,enum=tcp+udp"`
	Exposure Exposure `json:"exposure,omitempty" jsonschema:"enum=public,enum=internal"`
}

type Protocol

type Protocol string
const (
	// ProtocolHTTP ports can sit behind a platform's HTTP router.
	ProtocolHTTP   Protocol = "http"
	ProtocolTCP    Protocol = "tcp"
	ProtocolUDP    Protocol = "udp"
	ProtocolTCPUDP Protocol = "tcp+udp"
)

type Resource

type Resource struct {
	Type ResourceType `json:"type" jsonschema:"enum=postgres,enum=mysql,enum=sqlite,enum=redis,enum=bucket,enum=kv"`
	// External means the resource already exists outside anyship; adapters only wire it up.
	External bool `json:"external,omitempty"`
}

type ResourceType

type ResourceType string
const (
	ResourcePostgres ResourceType = "postgres"
	ResourceMySQL    ResourceType = "mysql"
	ResourceSQLite   ResourceType = "sqlite"
	ResourceRedis    ResourceType = "redis"
	ResourceBucket   ResourceType = "bucket"
	ResourceKV       ResourceType = "kv"
)

type Runtime

type Runtime struct {
	Language  string `json:"language,omitempty"`
	Framework string `json:"framework,omitempty"`
	// EdgeCompatible is false when the code relies on APIs edge runtimes
	// (e.g. Cloudflare Workers) don't provide; nil when unknown.
	EdgeCompatible *bool `json:"edgeCompatible,omitempty"`
}

type Secret

type Secret struct {
	// Generate asks anyship to generate the value instead of asking for it.
	Generate    string `json:"generate,omitempty" jsonschema:"enum=hex32"`
	Description string `json:"description,omitempty"`
}

type Service

type Service struct {
	Kind ServiceKind `json:"kind" jsonschema:"enum=static,enum=server,enum=worker"`
	// Path is the source directory, relative to the spec file.
	Path       string `json:"path,omitempty" jsonschema_description:"Source directory, relative to the spec file. Defaults to \".\"."`
	Image      string `json:"image,omitempty"`
	Dockerfile string `json:"dockerfile,omitempty"`
	Build      *Build `json:"build,omitempty"`
	// Start is the command that starts the process.
	Start string `json:"start,omitempty" jsonschema_description:"Command that starts the process."`
	// Entry is a module exporting a fetch handler, for edge runtimes. Relative to Path.
	Entry string `json:"entry,omitempty" jsonschema_description:"Module exporting a fetch handler, for edge runtimes. Relative to path."`
	Ports []Port `json:"ports,omitempty"`
	// Domains are the custom domains this service answers on. A target that
	// can't attach them says so instead of dropping them.
	Domains  []string `` /* 170-byte string literal not displayed */
	Volumes  []Volume `json:"volumes,omitempty"`
	Replicas int      `json:"replicas,omitempty" jsonschema:"minimum=1"`
	// Memory and CPU are what one instance of the service needs. A target
	// that can't size a service says so instead of dropping them.
	Memory      string            `json:"memory,omitempty" jsonschema_description:"Memory one instance needs, like \"512MB\" or \"4GB\"."`
	CPU         float64           `json:"cpu,omitempty" jsonschema_description:"CPUs one instance needs, like 0.5, 1 or 2."`
	Env         map[string]string `json:"env,omitempty"`
	Secrets     []string          `json:"secrets,omitempty" jsonschema_description:"Names of top-level secrets this service receives."`
	Uses        []string          `json:"uses,omitempty" jsonschema_description:"Names of top-level resources this service binds to."`
	Cron        []Cron            `json:"cron,omitempty"`
	Runtime     *Runtime          `json:"runtime,omitempty"`
	HealthCheck *HealthCheck      `json:"healthCheck,omitempty"`
	DependsOn   []string          `json:"dependsOn,omitempty"`
}

func (*Service) EdgeIncompatible

func (svc *Service) EdgeIncompatible() bool

EdgeIncompatible reports whether the service is known not to run on edge runtimes.

func (*Service) Framework

func (svc *Service) Framework() string

Framework returns the detected framework, if any.

func (Service) JSONSchemaExtend added in v0.3.0

func (Service) JSONSchemaExtend(s *jsonschema.Schema)

func (*Service) MemoryMB added in v0.4.0

func (s *Service) MemoryMB() int

MemoryMB is Memory in megabytes, or 0 when the service doesn't set it. Sizes are binary, as container platforms count them: 1GB is 1024MB.

func (*Service) RefersTo added in v0.4.0

func (s *Service) RefersTo() []string

RefersTo names the services the service's env refers to, each once, in name order.

type ServiceKind

type ServiceKind string
const (
	// KindStatic is built files served as-is.
	KindStatic ServiceKind = "static"
	// KindServer is a process (or edge handler) that answers requests.
	KindServer ServiceKind = "server"
	// KindWorker is a long-running background process with no inbound traffic.
	KindWorker ServiceKind = "worker"
)

type Spec

type Spec struct {
	Name      string               `json:"-"`
	Services  map[string]*Service  `json:"services"`
	Resources map[string]*Resource `json:"resources,omitempty"`
	Secrets   map[string]*Secret   `json:"secrets,omitempty"`
	// Targets holds per-platform overrides keyed by adapter name. Each adapter
	// decodes and validates its own block.
	Targets map[string]json.RawMessage `json:"targets,omitempty" jsonschema_description:"Per-platform overrides keyed by adapter name."`
}

Spec is the app: what adapters deploy. Name comes from metadata.name.

func Load

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

Load reads and parses a spec file.

func Parse

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

Parse decodes, normalizes and validates a spec from YAML (or JSON, which is YAML too). Unknown fields are rejected so typos surface instead of being ignored.

func (*Spec) DeployOrder added in v0.3.0

func (s *Spec) DeployOrder() []string

DeployOrder lists services so each comes after the services it depends on. Services in a dependency cycle come last, in name order.

func (Spec) JSONSchemaExtend

func (Spec) JSONSchemaExtend(s *jsonschema.Schema)

func (*Spec) Normalize

func (s *Spec) Normalize()

Normalize fills in defaults so adapters never have to.

func (*Spec) ServiceNames

func (s *Spec) ServiceNames() []string

ServiceNames returns the service names in a stable order.

func (*Spec) Validate

func (s *Spec) Validate() []string

Validate checks a normalized spec and returns every problem found, in a stable order. It returns nil for a valid spec.

type ValidationError

type ValidationError struct {
	Problems []string
}

ValidationError lists every problem found in a spec.

func (*ValidationError) Error

func (e *ValidationError) Error() string

type Volume

type Volume struct {
	Name      string `json:"name"`
	MountPath string `json:"mountPath"`
	Size      string `json:"size" jsonschema_description:"Size like \"20GB\" or \"2TB\"."`
	Class     string `json:"class,omitempty" jsonschema:"enum=standard,enum=nvme"`
}

func (Volume) JSONSchemaExtend

func (Volume) JSONSchemaExtend(s *jsonschema.Schema)

Jump to

Keyboard shortcuts

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