spec

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: Apache-2.0 Imports: 10 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.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

View Source
const (
	// Version is the spec format version this package reads and writes.
	Version = 1
	// Filename is the conventional spec file name.
	Filename = "anyship.json"
)
View Source
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

func JSONSchema() ([]byte, error)

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 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"`
}

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 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"`
	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

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.

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

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