Documentation
¶
Overview ¶
Package spec defines anyship.json: 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 ¶
const ( // Version is the spec format version this package reads and writes. Version = 1 // Filename is the conventional spec file name. Filename = "anyship.json" )
const ( NamePattern = `^[a-z][a-z0-9-]{0,62}$` SecretNamePattern = `^[A-Z][A-Z0-9_]*$` SizePattern = `^\d+(GB|TB)$` )
Variables ¶
This section is empty.
Functions ¶
func JSONSchema ¶
JSONSchema returns a JSON Schema for anyship.json, so editors can validate and autocomplete it via "$schema". Cross-field rules (unknown resources and the like) are only enforced by Validate.
Types ¶
type HealthCheck ¶
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 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 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"`
Volumes []Volume `json:"volumes,omitempty"`
Replicas int `json:"replicas,omitempty" jsonschema:"minimum=1"`
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 ¶
EdgeIncompatible reports whether the service is known not to run on edge runtimes.
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 {
Schema string `json:"$schema,omitempty"`
Version int `json:"version"`
Name string `json:"name" jsonschema_description:"Lowercase letters, digits and dashes, starting with a letter."`
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."`
}
func Parse ¶
Parse decodes, normalizes and validates a spec. Unknown fields are rejected so typos surface instead of being ignored.
func (Spec) JSONSchemaExtend ¶
func (Spec) JSONSchemaExtend(s *jsonschema.Schema)
JSONSchemaExtend adds the constraints struct tags can't express.
func (*Spec) Normalize ¶
func (s *Spec) Normalize()
Normalize fills in defaults so adapters never have to.
func (*Spec) ServiceNames ¶
ServiceNames returns the service names in a stable order.
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)