Documentation
¶
Overview ¶
Package adapter defines the contract between anyship and a deploy target.
Index ¶
- Variables
- func BuildsFromSource(s *spec.Spec) bool
- func Buildx(ctx context.Context, env *Env, needed bool, prefix string) (Dependency, []Finding)
- func DecodeOptions(raw json.RawMessage, into any) error
- func ExitCode(err error) (int, bool)
- func HasErrors(findings []Finding) bool
- func NotInstalled(err error) bool
- func Older(version, min string) bool
- func OptionsHint(target, needs string) string
- func Probe(ctx context.Context, env *Env, opts ExecOptions, name string, args ...string) (string, string, error)
- func VersionIn(text string) string
- type Action
- type Adapter
- type Checkup
- type Dependency
- type DestroyOptions
- type Destroyer
- type Doctor
- type Env
- type ExecOptions
- type File
- type Finding
- type Floor
- type Level
- type LogOptions
- type LogReader
- type Op
- type Plan
- type Registry
- type Result
- type ServiceSelector
- type ServiceStatus
- type Status
- type StatusReader
Constants ¶
This section is empty.
Variables ¶
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.
var Floors = []Floor{KubectlFloor, BuildxFloor, GCloudFloor, AWSFloor, WranglerFloor}
Floors lists every floor, for documentation and its test.
Functions ¶
func BuildsFromSource ¶ added in v0.7.0
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
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 NotInstalled ¶ added in v0.7.0
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
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
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.
Types ¶
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
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.
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 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.
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.
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 Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds the adapters available to the CLI.
func NewRegistry ¶
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.