deploy

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 modules, 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 deploy holds the decisions a deploy makes — which app, which platform, which plan, which org — so the CLI and the MCP server make them the same way. Rendering stays with the caller.

Index

Constants

View Source
const FallbackEnvironment = "development"

FallbackEnvironment is the environment every organization starts with as its default, used when the organization's own default cannot be read.

View Source
const GoShipDatabaseServer = "goship"

GoShipDatabaseServer is the server a database is created on when the person asks for GoShip's own PostgreSQL by that word. The API resolves it, to whatever GoShip server the environment uses, so it is sent as it is and never looked up among the organization's own servers.

Variables

View Source
var Build = func(ctx context.Context, client *portal.Client, a BuildArgs, r Reporter) error {
	in := portal.DeployRequest{Message: a.Message}
	if a.Dockerfile != "" {
		content, err := os.ReadFile(filepath.Join(a.Dir, a.Dockerfile))
		if err != nil {
			return fmt.Errorf("reading %s: %w", a.Dockerfile, err)
		}
		in.Dockerfile = string(content)
	}

	pr, pw := io.Pipe()
	sent := &countingWriter{w: pw}
	go func() {
		_, _, err := archive.Write(a.Dir, sent)
		pw.CloseWithError(err)
	}()
	in.Archive = pr

	r.Begin("upload")
	uploaded := false
	err := client.Deploy(ctx, a.Target.Org, a.Target.Project, a.Target.Environment, a.Name, in, func(ev portal.ReleaseEvent) error {

		if !uploaded {
			uploaded = true
			r.Done("upload", FormatBytes(sent.n.Load()))
		}
		return r.Event(ev)
	})
	pr.CloseWithError(err)
	return err
}

Build packs the project and uploads it, reporting the build to r as it runs. It is a package var so a test can assert what a deploy asks to be built.

View Source
var DeployImage = func(ctx context.Context, client *portal.Client, a ImageArgs, r Reporter) error {
	return client.DeployImage(ctx, a.Target.Org, a.Target.Project, a.Target.Environment, a.Name,
		portal.ImageDeployRequest{Image: a.Image, Message: a.Message}, r.Event)
}

DeployImage asks GoShip to release a prebuilt image, reporting the release to r as it runs. It is a package var, like Build, so a test can assert what a deploy asks to be released.

View Source
var ErrNoOrg = errors.New("no organization selected")

ErrNoOrg is returned when nothing selects an organization and the app exists in none of the caller's. The caller words the remedy, since it differs between a terminal and an agent.

View Source
var ErrNoProject = errors.New("no project selected")

ErrNoProject is ErrNoOrg for the project: the organization is known, the app is in none of its projects and it has more than one to choose from.

View Source
var ProjectFiles = []string{"goship.yaml", "goship.yml", ".goship.yaml", ".goship.yml"}

ProjectFiles are the optional config names, in the order they are tried. Nothing requires one: every value in it can be passed as a flag or inferred.

Functions

func BillingNote added in v0.15.0

func BillingNote(at *time.Time, now time.Time) string

BillingNote says when billing starts for a resource an invited trial holds unbilled, or "" when it holds nothing (at is nil). A start already past is a trial that ended before GoShip moved the resource to its plan.

func ChoosePlan

func ChoosePlan(ctx context.Context, client *portal.Client, t Target) (portal.Plan, error)

ChoosePlan picks the plan for an app being created in t's environment when none was named: the plan the environment's cluster marks as its default, else the first unbilled one in the order the API lists them. Only a plan nothing is billed for is safe to select on the user's behalf; otherwise the choice costs money and is theirs.

func DatabasePlacement added in v0.19.0

func DatabasePlacement(ctx context.Context, client *portal.Client, t Target, ref string) (server *portal.DatabaseServer, fromEnvironment bool, err error)

DatabasePlacement says where a new database goes when the person named ref as its server: nil for GoShip's PostgreSQL, else the organization's server. "goship" is GoShip's by name. An empty ref is the environment's default server, which may be one of the organization's own; fromEnvironment reports that the answer came from there, in which case the API is sent no server and resolves the same default itself.

func DetectDockerfile

func DetectDockerfile(dir string) string

DetectDockerfile reports the container file in dir, if any. It is the fallback when no platform marker matches: a project carrying both a go.mod and a Dockerfile is a Go app that happens to ship one, and is built by the platform unless --dockerfile says otherwise.

func DetectPlatform

func DetectPlatform(dir string) (platform, evidence string)

DetectPlatform guesses the platform from the files in dir, returning the platform and the file that gave it away. Empty when nothing matches.

func ElsewhereError

func ElsewhereError(name string, current Target, found []Target, forbidden bool) error

ElsewhereError says where the app was found instead. current has an empty Org when nothing was selected, and an empty Project when only the project is missing.

func EnvironmentSlugs added in v0.14.0

func EnvironmentSlugs(ctx context.Context, client *portal.Client, org string) ([]string, error)

EnvironmentSlugs are the slugs of org's environments, in the portal's order. Every project exists in every one of them.

func FormatBytes

func FormatBytes(n int64) string

FormatBytes renders a size the way the upload step shows it.

func KnownPlatforms

func KnownPlatforms() string

func ParseEnvFile

func ParseEnvFile(path string) (map[string]string, error)

ParseEnvFile reads a dotenv-style file: KEY=VALUE per line, # comments and blank lines ignored, surrounding quotes stripped.

func PlanTable

func PlanTable(plans []portal.Plan) string

PlanTable lists plans one per line, for an error that asks the user to pick.

func Price

func Price(p portal.Plan) string

Price is a plan's monthly price as the catalogue shows it.

func PublicURL

func PublicURL(a *portal.App) string

PublicURL is the address to show after a deploy: a custom domain when the app has one, otherwise the platform address it always has.

func ResizeReconnectHint added in v0.14.0

func ResizeReconnectHint(dashboard, org, clusterID string, err error) error

ResizeReconnectHint turns a resize refused because the cloud account must be reconnected into an error that links the dashboard's resize page for the cluster.

func ResolveCloudAccount added in v0.14.0

func ResolveCloudAccount(ctx context.Context, client *portal.Client, org, ref string) (*portal.CloudAccount, error)

ResolveCloudAccount turns what a person types into the account the API keys on. It matches, in order: the id, then an exact label, then the provider name — but only when exactly one account uses that provider.

func ResolveCluster added in v0.14.0

func ResolveCluster(ctx context.Context, client *portal.Client, org, ref string) (string, error)

ResolveCluster turns what a person types into the id of a cluster org can use: its own or a shared one. An id always wins; a name must be unique among them, and two clusters of that name are refused, naming both.

func ResolveDatabaseServer added in v0.9.0

func ResolveDatabaseServer(ctx context.Context, client *portal.Client, t Target, ref string) (*portal.DatabaseServer, error)

ResolveDatabaseServer turns what a person types — the server's name, usually — into the server, which carries the id the API wants. Servers belong to the organization. An id always wins; a name must be unique.

func ResolveEnvironment added in v0.14.0

func ResolveEnvironment(ctx context.Context, t Target, c EnvironmentChoice, orgs OrgLister) (string, error)

ResolveEnvironment is the environment t acts on, t's org and project being resolved: what c picks, else the organization's default from orgs (GET /orgs), which is only asked when nothing picked one. No selection is not an error, and nothing it returns stops a command that only reads. When the org list cannot answer it returns FallbackEnvironment together with why: a guess that a command which creates or changes something must refuse with UnknownDefaultError. An org the list does not carry, or carries without a default, is FallbackEnvironment too; the call that follows answers for it.

func ResolveProjectDomain added in v0.22.0

func ResolveProjectDomain(ctx context.Context, client *portal.Client, t Target, ref string) (*portal.ProjectDomain, error)

ResolveProjectDomain turns what a person types, the domain name or its id, into the project domain, which carries the id the API wants.

func SignalFiles

func SignalFiles() string

func UnknownDefaultError added in v0.14.0

func UnknownDefaultError(org string, err error) error

UnknownDefaultError refuses to act in an environment nobody chose when org's default could not be read (err, from ResolveEnvironment).

Types

type BuildArgs

type BuildArgs struct {
	Target                         Target
	Name, Dir, Dockerfile, Message string
}

BuildArgs is what the build step needs.

type EnvironmentChoice added in v0.14.0

type EnvironmentChoice struct {
	// Explicit is what the command was told: --environment, or an agent's
	// environment argument.
	Explicit string
	// File is the project file in the working directory, nil when there is
	// none. Its environment: speaks only for the org and project the file
	// names, as its project: does.
	File *Project
	// Selected is the caller's standing choice for a target: GOSHIP_ENVIRONMENT,
	// else the environment saved for the project. Nil when there is none.
	Selected func(Target) string
}

EnvironmentChoice is what may pick a target's environment, in the order it is asked.

func (EnvironmentChoice) Chosen added in v0.14.0

func (c EnvironmentChoice) Chosen(t Target) string

Chosen is the environment something picked for t, or "" when nothing did. t may be partial: a file that names an org or project speaks only for a target that has the same one.

type ImageArgs added in v0.18.0

type ImageArgs struct {
	Target               Target
	Name, Image, Message string
}

ImageArgs is what an image deploy needs.

type Options

type Options struct {
	Dir string
	// App is the app name; the directory's name by default.
	App string
	// Org is the organization already chosen by the caller, or empty to let
	// the app's existing home decide.
	Org string
	// Project is the project already chosen by the caller, or empty to let the
	// app's existing home decide.
	Project string
	// Environment is the environment already chosen by the caller, or empty
	// to let the project file, then SelectedEnvironment, then the
	// organization's default decide.
	Environment string
	// SelectedEnvironment is the caller's standing choice for a target
	// (GOSHIP_ENVIRONMENT, or the environment saved for the project), asked
	// after the project file. Optional.
	SelectedEnvironment func(Target) string
	// Orgs is the caller's org list when it already holds one; client.Orgs
	// otherwise. Either way a deploy asks for it at most once.
	Orgs OrgLister

	Platform   string
	Plan       string
	Dockerfile string
	// Image is a container image to deploy instead of building Dir. It
	// excludes Platform and Dockerfile, and Dir may then be empty: nothing is
	// read from it.
	Image   string
	Message string
	// Env is applied as private variables before the build, on top of the
	// project file's.
	Env map[string]string
}

Options is what a deploy is told. Everything but Dir is optional: the rest comes from the project file in Dir, then from the files present.

type OrgLister added in v0.14.0

type OrgLister func(context.Context) ([]portal.Org, error)

OrgLister answers GET /orgs. A caller that already holds the list passes its own, so a command asks once.

type Project

type Project struct {
	App string `yaml:"app"`
	// Org pins the organization for the project, so a repo that belongs to one
	// org does not depend on whatever `goship org use` was last pointed at.
	Org string `yaml:"org"`
	// ProjectSlug pins the project inside the organization.
	ProjectSlug string `yaml:"project"`
	// Environment pins the environment inside the project; the
	// organization's default when unset. Env, not this, is the variables.
	Environment string `yaml:"environment"`
	Platform    string `yaml:"platform"`
	Plan        string `yaml:"plan"`
	// Node is no longer used: the environment decides the cluster an app
	// runs on. It is read only to say so, and goes in a later release.
	Node string            `yaml:"node"`
	Env  map[string]string `yaml:"env"`
	// Dockerfile names a container file to build from instead of letting a
	// platform build the source. Mutually exclusive with platform.
	Dockerfile string `yaml:"dockerfile"`
}

Project is the optional config in a project root. Flags win over it.

func LoadProject

func LoadProject(dir string) (*Project, string, error)

LoadProject reads the first config file that exists, returning its name so messages can say which one was used. A directory with none is not an error.

type Reporter

type Reporter interface {
	Header(format string, args ...any)
	Note(format string, args ...any)
	Begin(key string)
	Done(key, detail string)
	Event(ev portal.ReleaseEvent) error
}

Reporter hears a deploy as it goes. The CLI draws it; an agent buffers it.

type Result

type Result struct {
	App         string        `json:"app"`
	Org         string        `json:"org"`
	Project     string        `json:"project"`
	Environment string        `json:"environment"`
	Platform    string        `json:"platform,omitempty"`
	Plan        string        `json:"plan,omitempty"`
	Created     bool          `json:"created"`
	Version     string        `json:"version,omitempty"`
	URL         string        `json:"url,omitempty"`
	Duration    time.Duration `json:"-"`
	// BillingStartsAt is when billing starts for the app, which an invited
	// trial holds unbilled until then; absent otherwise.
	BillingStartsAt *time.Time `json:"billing_starts_at,omitempty"`
}

Result is what a finished deploy reports.

func Run

func Run(ctx context.Context, client *portal.Client, o Options, r Reporter) (*Result, error)

Run deploys o.Dir: says where it deploys to, creates the app when it does not exist, applies the variables, uploads the source and follows the release. Errors from the release itself are *portal.OperationError, so a caller can tell a build that failed from a request that was refused.

type Target added in v0.5.0

type Target struct{ Org, Project, Environment string }

Target is the organization, project and environment a command acts on.

func AppElsewhere added in v0.5.0

func AppElsewhere(ctx context.Context, client *portal.Client, orgs OrgLister, current Target, name string) []Target

AppElsewhere looks for an app of the same name in the caller's other projects. Deploy creates whatever it cannot find, so without this a wrong --org or --project silently produces a second app of the same name somewhere else instead of deploying the one the user meant. The same name in another environment of the current project is that environment's app, which is what environments are for, so it does not count.

Best effort: a failure here must not block a legitimate create, so errors return no matches rather than propagating.

func FindApp added in v0.5.0

func FindApp(ctx context.Context, client *portal.Client, orgs OrgLister, org, project, env, name string) ([]Target, error)

FindApp lists every place the caller can reach that holds an app called name: a project of org (of all their organizations, from orgs, when org is empty) in an environment. An env narrows the search to that environment; an empty one searches every environment of the organization. A project slug narrows it to projects of that name: a project or environment someone asked for is never swapped for another. An organization whose environments or projects the caller's role cannot list holds nothing they can reach, and is left out rather than failing the search of the others.

func (Target) String added in v0.5.0

func (t Target) String() string

String is "org/project", with "/environment" when one is set.

Jump to

Keyboard shortcuts

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