deployhook

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 8 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 deployhook is the contract between an application's hooks program and the deploy pipeline bedrock renders for it. A hook is the application's own work at a fixed point of a deploy: a check against a dependency after the migrations, a check against the new revision before traffic moves to it, a smoke test after. An application writes its hooks as a Go program at cmd/deployment/hooks, beside the migrate command:

func main() {
	deployhook.Main(deployhook.Hooks{
		BeforeTraffic: checkNextRevision,
		AfterTraffic:  smokeTest,
	})
}

bedrock reads which stages the program implements from that literal, renders a pipeline step for each, and checks that the Dockerfile builds the program into the image as /hooks. The pipeline's image build takes /hooks out of the image it built, and each hook step runs it with the stage as its argument and the pipeline's facts in its environment, on the build worker as the build's deploy identity, in the checkout: the same place a hook script (infrastructure/hooks/<stage>.sh) runs, so a program and scripts mix, one or the other per stage.

Only the stages after the image build take a program, because the program comes out of the image: before-build (the image does not exist yet) and after-down (a teardown builds no image) take a script. A hook has no database and no application secrets, and it never starts the application's job process (cmd/jobs): work that needs the application's runtime is the running service's, which starts the job of its own build. A backfill after a release is an endpoint on the service, called once traffic moved.

Index

Constants

This section is empty.

Variables

Stages are the stages a program may implement, in the pipeline's order.

Functions

func Main

func Main(h Hooks)

Main runs the stage its one argument names with the facts in the environment, and exits: 0 when the hook succeeds, 1 when it fails (the build stops at the stage), 2 when the program is run without a stage it implements. The context ends when the step is stopped.

func Run

func Run(ctx context.Context, h Hooks, s Stage, f *Facts) error

Run runs the hook for the stage, refusing a stage the program does not implement.

Types

type Facts

type Facts struct {
	// App and Environment are the application and the environment deployed to (_APP,
	// _ENV).
	App         string
	Environment string
	// Version is what the process reports (a release tag, or pr<N>@<commit>), and
	// Release the image's release name (the tag, or pr<N>-<commit>).
	Version string
	Release string
	// Image and ImageDigest are the image this build deploys (IMAGE, IMAGE_DIGEST).
	Image       string
	ImageDigest string
	// PullRequest is the pull request's number in a pull-request build, 0 in a release
	// build. SharedDB says a pull request runs against the environment's database, and
	// ReloadDB that its own database is recreated this build.
	PullRequest int
	SharedDB    bool
	ReloadDB    bool
	// RunMigrations says the migrate job runs in this build.
	RunMigrations bool
	// NextURL is the new revision's public URL through the load balancer before traffic
	// moves (empty in a pull-request build, whose environment is its own), and
	// RevisionURLs the tagged run.app URL of the new revision by region, which the
	// services answer from inside the project alone. Both are set from before-traffic on.
	NextURL      string
	RevisionURLs map[string]string
	// contains filtered or unexported fields
}

Facts are what the pipeline knows about the build, as the hook steps pass them in the environment: the pipeline's facts and every substitution of the build.

func FactsFrom

func FactsFrom(lookup func(string) string) (*Facts, error)

FactsFrom reads the facts through lookup, os.Getenv in a hook step.

func (*Facts) Substitution

func (f *Facts) Substitution(name string) string

Substitution is a substitution of the build by name (_HOSTNAME, a declared _NAME), or any fact the pipeline exports; empty when the build has none.

type Func

type Func func(ctx context.Context, f *Facts) error

Func is one hook: it does the stage's work and answers an error to stop the build.

type Hooks

type Hooks struct {
	BeforeMigrate Func
	AfterMigrate  Func
	BeforeTraffic Func
	AfterTraffic  Func
}

Hooks are an application's hooks, one function per stage it implements; a stage left nil has none. bedrock reads the stages from the literal passed to Main, so a program builds it in one place, keyed by field.

func (Hooks) For

func (h Hooks) For(s Stage) Func

For is the hook for the stage, nil when the program implements none.

type Stage

type Stage string

Stage is one point of the deploy sequence a hooks program may implement.

const (
	// BeforeMigrate runs after the image is built (Facts.ImageDigest names it) and
	// before the migrate job.
	BeforeMigrate Stage = "before-migrate"
	// AfterMigrate runs once the schema is migrated, before the service deploys: a check
	// against a dependency the release needs, a notice to another system that the schema
	// moved. Work on the data is the job process's, started by the running service.
	AfterMigrate Stage = "after-migrate"
	// BeforeTraffic runs with the new revision deployed in every region and the old one
	// still serving; Facts.NextURL reaches the new one. A failure stops the build with the
	// old revision serving.
	BeforeTraffic Stage = "before-traffic"
	// AfterTraffic runs once traffic moved: a smoke test, a cache warm. A failure stops the
	// build before the deployment record, so the next environment's gate never sees the
	// release.
	AfterTraffic Stage = "after-traffic"
)

The stages a program may implement, in the pipeline's order.

Jump to

Keyboard shortcuts

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