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 ¶
var Stages = []Stage{BeforeMigrate, AfterMigrate, BeforeTraffic, AfterTraffic}
Stages are the stages a program may implement, in the pipeline's order.
Functions ¶
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
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 (*Facts) Substitution ¶
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 Hooks ¶
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.
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.