adapter

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 14 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 adapter defines the contract between anyship and a deploy target.

Index

Constants

This section is empty.

Variables

View Source
var (
	// KubectlFloor: deploys prune what the spec dropped with
	// --prune-allowlist, which kubectl 1.26 renamed from --prune-whitelist.
	KubectlFloor = Floor{Tool: "kubectl", Min: "1.26", Feature: "`apply --prune-allowlist`",
		Hint: "Install a newer kubectl: https://kubernetes.io/docs/tasks/tools/"}
	// BuildxFloor: images are built with `docker buildx build
	// --metadata-file`, whose digest anyship deploys by; buildx 0.6.0 added it.
	BuildxFloor = Floor{Tool: "docker buildx", Min: "0.6.0", Feature: "`--metadata-file`",
		Hint: "Update Docker Desktop, or the buildx plugin: https://github.com/docker/buildx#installing"}
	// GCloudFloor: every Cloud Run deploy sets or clears the startup probe
	// with --startup-probe, GA in `gcloud run deploy` since 515.0.0.
	GCloudFloor = Floor{Tool: "gcloud", Min: "515.0.0", Feature: "`gcloud run deploy --startup-probe`",
		Hint: "Update it with `gcloud components update`, or with the package manager that installed it."}
	// AWSFloor: aws services are ECS Express Mode services, whose
	// *-express-gateway-service commands came with aws CLI 2.32.2.
	AWSFloor = Floor{Tool: "aws CLI", Min: "2.32.2", Feature: "the ECS Express Mode commands (`aws ecs create-express-gateway-service`)",
		Hint: "Update the aws CLI: https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html"}
	// WranglerFloor: anyship renders wrangler.jsonc, which wrangler reads
	// without --experimental-json-config since 3.91.0. Node.js has no floor:
	// each wrangler checks the Node.js it runs on, and says so.
	WranglerFloor = Floor{Tool: "wrangler", Min: "3.91.0", Feature: "`wrangler.jsonc`",
		Hint: "Update the project's wrangler: `npm install --save-dev wrangler@latest`."}
)

The version floors: the oldest version of each tool that has a feature anyship uses, and only where it uses one. Each was taken from the tool's own changelog. Keep them here, and list a new one in Floors; the README names every floor, which a test checks.

Floors lists every floor, for documentation and its test.

Functions

func BuildsFromSource added in v0.7.0

func BuildsFromSource(s *spec.Spec) bool

BuildsFromSource reports whether a container target would build an image for some service of s, which takes Docker with buildx on this machine.

func Buildx added in v0.7.0

func Buildx(ctx context.Context, env *Env, needed bool, prefix string) (Dependency, []Finding)

Buildx checks for docker buildx, which the container targets build with, and its version. Codes start with prefix, such as GCP: a missing buildx is <prefix>_PREFLIGHT_DOCKER, an error when needed (a service builds from source) and a warning otherwise; an old one is <prefix>_PREFLIGHT_VERSION.

func DecodeOptions added in v0.3.1

func DecodeOptions(raw json.RawMessage, into any) error

DecodeOptions decodes a target's block of anyship.yaml into its options, strictly: an unknown field is an error, so a typo surfaces as a finding. A value of the wrong shape is reported in the file's terms ("port must be a whole number, not a string"), as yamljson.Problems.

func ExitCode

func ExitCode(err error) (int, bool)

ExitCode returns the exit status carried by an error from Env.Exec.

func HasErrors

func HasErrors(findings []Finding) bool

HasErrors reports whether any finding blocks apply.

func NotInstalled added in v0.7.0

func NotInstalled(err error) bool

NotInstalled reports whether an error from Env.Exec means the command isn't on this machine at all, as opposed to running and failing.

func Older added in v0.7.0

func Older(version, min string) bool

Older reports whether version is older than min, comparing dotted numbers ("1.24.3" < "1.26"); a missing part counts as 0. It is false when either can't be read.

func OptionsHint added in v0.3.1

func OptionsHint(target, needs string) string

OptionsHint is the hint for a target block that is missing or wrong: where the block lives in anyship.yaml, the fields it needs written the way they appear in the file, and where the rest are documented. Adapters share it so their hints read alike.

func Probe added in v0.7.0

func Probe(ctx context.Context, env *Env, opts ExecOptions, name string, args ...string) (string, string, error)

Probe runs a command with an empty stdin and returns its trimmed stdout and stderr, so nothing reaches the terminal or waits on it. It runs in env.Dir unless opts.Dir names another directory.

func VersionIn added in v0.7.0

func VersionIn(text string) string

VersionIn picks the first version number out of a tool's output.

Types

type Action

type Action struct {
	Op Op `json:"op"`
	// Kind is what is acted on, e.g. "worker", "D1", "build".
	Kind   string `json:"kind"`
	Name   string `json:"name"`
	Detail string `json:"detail,omitempty"`
}

type Adapter

type Adapter interface {
	Name() string
	Description() string
	Plan(ctx context.Context, s *spec.Spec, env *Env) (*Plan, error)
	Apply(ctx context.Context, p *Plan, s *spec.Spec, env *Env) (*Result, error)
}

Adapter is a deploy target. Plan must be side-effect free: it only inspects the spec and reports what Apply would do. Apply must refuse a plan with errors.

type Checkup added in v0.7.0

type Checkup struct {
	Dependencies []Dependency
	Findings     []Finding
}

Checkup is what Doctor reports: the dependencies, and a finding for each one that is missing or not logged in.

type Dependency added in v0.7.0

type Dependency struct {
	Name string `json:"name"`
	// Need says what the target uses it for.
	Need    string `json:"need"`
	Found   bool   `json:"found"`
	Version string `json:"version,omitempty"`
	// Min is the oldest version anyship works with, when it needs a
	// feature that older ones lack.
	Min string `json:"min,omitempty"`
	// Login is who the tool is logged in as, or the context it points at,
	// for tools that have one.
	Login string `json:"login,omitempty"`
}

Dependency is one command-line tool a target drives on this machine, as Doctor found it.

type DestroyOptions

type DestroyOptions struct {
	// Volumes also deletes persistent data: volumes, secrets and deployment files.
	Volumes bool
}

type Destroyer

type Destroyer interface {
	// DestroySummary describes what Destroy would remove, for confirmation.
	// It must not touch the target.
	DestroySummary(s *spec.Spec, opts DestroyOptions) ([]string, error)
	Destroy(ctx context.Context, s *spec.Spec, env *Env, opts DestroyOptions) (*Result, error)
}

Destroyer is implemented by adapters that can remove a deployment.

type Doctor added in v0.7.0

type Doctor interface {
	Doctor(ctx context.Context, s *spec.Spec, env *Env) Checkup
}

Doctor is implemented by adapters that can check this machine for a target: which of the tools it drives are installed, their versions and their logins. It runs only those tools, never a deploy or a change, and works without a spec; with one (s may be nil) it reads the target's options, such as a gcloud configuration or an aws profile.

type Env

type Env struct {
	// Dir is the directory containing anyship.yaml.
	Dir string
	// OutDir is scratch space for generated platform config, e.g. <Dir>/.anyship/<target>.
	// It is write-only: anyship keeps no state, so adapters must never read it
	// back to learn what is deployed. Ask the platform instead.
	OutDir string
	DryRun bool
	// Services limits a deploy to these spec services, by name; empty means all
	// of them. Only an adapter that implements ServiceSelector is given any.
	// The spec still holds every service, so the adapter can leave the others'
	// resources alone.
	Services []string
	Logf     func(format string, args ...any)
	// Exec runs a command with inherited stdio (unless opts.Stdin is set) and
	// returns an error if it fails; NotInstalled tells a missing command apart.
	Exec func(ctx context.Context, opts ExecOptions, name string, args ...string) error
	// LookupEnv reads the deployer's environment, e.g. for secret values.
	LookupEnv func(key string) (string, bool)
}

Env is what an adapter may use to touch the outside world.

func (*Env) Selected added in v0.7.0

func (e *Env) Selected(service string) bool

Selected reports whether a run deploys the named service.

type ExecOptions

type ExecOptions struct {
	Dir string
	// Shell runs the command through the system shell (for user-supplied build commands).
	Shell bool
	// Stdin, when set, is streamed to the command instead of the terminal's stdin.
	Stdin io.Reader
	// Stdout, when set, captures the command's output instead of showing it.
	Stdout io.Writer
	// Stderr, when set, takes the command's error output instead of the
	// terminal, e.g. io.Discard for probes whose failure is reported anyway.
	Stderr io.Writer
	// Env adds KEY=VALUE entries to the deployer's environment for this command.
	Env []string
}

type File

type File struct {
	// Path is absolute.
	Path     string `json:"path"`
	Contents []byte `json:"-"`
}

type Finding

type Finding struct {
	Level Level `json:"level"`
	// Code is a stable identifier such as CF_VOLUMES, safe to match on in tests and docs.
	Code    string `json:"code"`
	Message string `json:"message"`
	Service string `json:"service,omitempty"`
	File    string `json:"file,omitempty"`
	Hint    string `json:"hint,omitempty"`
}

Finding is something an adapter or the detector wants the user to know.

func Missing added in v0.7.0

func Missing(missing Finding, tool string, err error) Finding

Missing is the finding for a tool whose version command failed: missing itself when the tool isn't installed, or the same code saying it doesn't run, and why, when it is; the install hint gives way to one about that.

type Floor added in v0.7.0

type Floor struct {
	// Tool names the tool in messages.
	Tool string
	Min  string
	// Feature is what anyship needs that older versions lack.
	Feature string
	// Hint says how to get a newer version.
	Hint string
}

Floor is the oldest version of a tool that has a feature anyship uses.

func (Floor) Check added in v0.7.0

func (f Floor) Check(version, code string) []Finding

Check warns under code when version is older than the floor. It is a warning, not an error: a version string anyship misreads must not block a deploy. An unknown version passes.

type Level

type Level string
const (
	// Error blocks apply.
	Error   Level = "error"
	Warning Level = "warning"
	Info    Level = "info"
)

type LogOptions

type LogOptions struct {
	// Service limits output to one service; empty means all of them.
	Service string
	Follow  bool
	// Tail is the number of recent lines per service; 0 means the adapter's default.
	Tail int
	// Since is a duration such as "10m" or an RFC 3339 / YYYY-MM-DD timestamp.
	Since      string
	Timestamps bool
}

LogOptions selects which runtime logs to show.

type LogReader

type LogReader interface {
	Logs(ctx context.Context, s *spec.Spec, env *Env, opts LogOptions) error
}

LogReader is implemented by adapters that can show a deployment's runtime logs. Logs streams to the terminal and returns when done, or when ctx is cancelled while following. Options the platform can't honor are errors.

type Op

type Op string
const (
	OpCreate Op = "create"
	OpRun    Op = "run"
	OpDeploy Op = "deploy"
	OpNote   Op = "note"
)

type Plan

type Plan struct {
	Target   string    `json:"target"`
	Findings []Finding `json:"findings"`
	Actions  []Action  `json:"actions"`
	Files    []File    `json:"files"`
	// Data is adapter-private state handed from Plan to Apply.
	Data any `json:"-"`
}

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry holds the adapters available to the CLI.

func NewRegistry

func NewRegistry(adapters ...Adapter) (*Registry, error)

func (*Registry) Get

func (r *Registry) Get(name string) (Adapter, error)

func (*Registry) List

func (r *Registry) List() []Adapter

func (*Registry) Names

func (r *Registry) Names() []string

type Result

type Result struct {
	OK bool
	// Findings are what Apply learned on the target, such as preflight checks.
	Findings []Finding
	Messages []string
}

type ServiceSelector added in v0.7.0

type ServiceSelector interface {
	SelectsServices()
}

ServiceSelector is implemented by adapters that can deploy some of a spec's services and leave the rest untouched: what those services own (access, schedules, URLs others refer to) is kept.

type ServiceStatus

type ServiceStatus struct {
	Name string `json:"name"`
	// State is "running" when every instance runs, "missing" when none
	// exist, or the platform's state of the first instance that doesn't run
	// (such as "exited" or "restarting").
	State string `json:"state"`
	// Health is "healthy", "unhealthy" or "starting"; empty without a health check.
	Health  string   `json:"health,omitempty"`
	Running int      `json:"running"`
	Desired int      `json:"desired"`
	Ports   []string `json:"ports,omitempty"`
	// Detail is the platform's own description, e.g. "Up 2 hours".
	Detail string `json:"detail,omitempty"`
	// URL is where the service answers from outside the platform, when it
	// has such an address; "pending" while the platform is still assigning one.
	URL string `json:"url,omitempty"`
	// Since is when the running instances last changed, in RFC 3339.
	Since string `json:"since,omitempty"`
	// Restarts counts the restarts of the current instances; nil when the
	// platform doesn't report it.
	Restarts *int `json:"restarts,omitempty"`
	// Image is what runs, by digest when the platform knows it.
	Image string `json:"image,omitempty"`
	// Events are the platform's latest warnings about the service, newest
	// first, at most five.
	Events []string `json:"events,omitempty"`
}

type Status

type Status struct {
	Target string `json:"target"`
	// Location says where the deployment lives, e.g. "deploy@host:anyship/app".
	Location string          `json:"location"`
	Deployed bool            `json:"deployed"`
	Services []ServiceStatus `json:"services"`
}

Status is what is currently running for a spec on a target.

func (*Status) Healthy

func (s *Status) Healthy() bool

Healthy reports whether every service runs as desired and none is unhealthy.

type StatusReader

type StatusReader interface {
	Status(ctx context.Context, s *spec.Spec, env *Env) (*Status, error)
}

StatusReader is implemented by adapters that can report what is running.

Jump to

Keyboard shortcuts

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