Documentation
¶
Overview ¶
Package render writes an application stack from the derived model: every file the stack is made of, rendered from an embedded template, and which of them the tool owns.
A file has a tier. An owned file is rewritten on every render: the stack's .tf files and its README say what the code declares and nothing a person keeps by hand, and so do the pipeline files Cloud Build reads at the application root (cloudbuild.yaml, cloudbuild-sweep.yaml). A seeded file is written once, when absent, and never again: terraform.tfvars holds the placement values a person fills in per environment, the stack's .gitignore keeps the per-environment backend caches and saved plans out of the repository, the Dockerfile at the application root is the image build a person takes over from its first shape, with the .dockerignore beside it that keeps a local build's context small, and release-please's configuration and manifest at the root start the application's releases at 0.1.0. Files the tool never writes (the lock file, the placement) have no tier here.
Index ¶
- Constants
- Variables
- func Execute(name string, src []byte, data any) ([]byte, error)
- func Formatted(name string, content []byte) []byte
- func IsHCL(name string) bool
- func Key(name string) string
- func OneLine(s string) string
- func Parses(name string, content []byte) error
- func Quote(s string) string
- func QuoteList(items []string) string
- func SubstitutionNames() ([]string, error)
- type File
- type Tier
- type UndeclaredVariable
- type Written
Constants ¶
const ( SignInCountVariable = "cloud_armor_sign_in_count" SignInIntervalVariable = "cloud_armor_sign_in_interval" )
The sign-in throttle's threshold, as terraform.tfvars sets it: the POSTs one client address may make to a sign-in route in the interval before its further ones answer 429, and the interval in seconds. The defaults are chosen for a login page: a person types a handful of attempts in a minute and an office behind one address a few dozen at its busiest, so neither meets thirty, while a password guessed from one address is held to thirty tries a minute; a minute holds a guessing script to the count and keeps a person who met it waiting little.
const ( ReleasePleaseConfig = release.PleaseConfig ReleasePleaseManifest = release.PleaseManifest )
release-please's two files at the application root, which the stack's release trigger reads (release.PleaseConfig, release.PleaseManifest): its configuration, and the manifest holding the last released version. Both are seeded, the configuration with initial-version 0.1.0 and the manifest at 0.0.0, so the first release pull request proposes 0.1.0; from then on release-please moves the manifest and the configuration is the application's.
const ( CheckTrigger = "check" StackTrigger = "pr-stack" ReleaseTrigger = "release" )
The trigger-held jobs of the stack (cloud-build.tf): the check-and-plan trigger, which runs on every push to a pull request and reports the check a merge waits for, and the pull-request stack trigger, which runs on the /gcbrun comment beside the preview. Their steps are the trigger's own text, so a pull request cannot change them, and the deploy package names each trigger and its steps by these when it says that a build runs under an older bedrock's steps.
const ImageHome = "/home/nonroot"
ImageHome is the working directory of the runtime image, where the bundles and the schema sit (Dockerfile): each site's bundle variable names its directory under it, the stack's per service in the sites layout (bedrock check holds it to the Procfile's) and the image's ENV in the flat layout.
const (
OperationsWorkflow = "operations.yml"
)
The GitHub workflow bedrock renders at the application root: the operations workflow, which starts a restore of an environment (bedrock restore dispatches it by this name).
Variables ¶
var ( CheckTriggerSteps = []string{fetchBedrockStep, buildBedrockCommitStep, checkStackStep, planEnvironmentsStep, refreshStackStep} StackTriggerSteps = []string{fetchBedrockStep, buildBedrockCommitStep, checkStackStep, applyStackStep} // ReleaseTriggerSteps are the release trigger's steps, in order. ReleaseTriggerSteps = []string{fetchBedrockStep, buildBedrockCommitStep, releaseStep} )
CheckTriggerSteps are the check-and-plan trigger's step ids, in order, and StackTriggerSteps the pull-request stack trigger's.
var ReleaseFiles = []string{ReleasePleaseConfig, ReleasePleaseManifest}
ReleaseFiles are release-please's files, which bedrock check refuses an application without: without them no release is cut, and nothing reaches an environment.
var Retired = []string{path.Join(workflowsDir, "release-please.yml")}
Retired are the files an earlier bedrock rendered at the application root and this one does not, relative to the root: bedrock render removes each it finds, and bedrock check reports one still committed. The release workflow (release-please.yml) ran release-please in GitHub Actions with the release app's key in an organization secret; the stack's release trigger runs it in Cloud Build now, with the key in Secret Manager.
Functions ¶
func Execute ¶ added in v0.1.3
Execute renders the template src as the file name (the template's name without its extension) from data. An HCL file's values are written as the place each lands in takes them, and the file is formatted and must parse; any other file is the template's output as it is.
func Formatted ¶
Formatted returns content as tofu fmt writes it when name is an HCL file (.tf or .tfvars), so that a rendered file passes tofu fmt -check whatever a template's own spacing: a block's trailing comments align on its longest line, which a value of varying width (an environment list, a release actor) moves. Any other file is returned as it is.
func IsHCL ¶ added in v0.1.3
IsHCL reports whether the file is one OpenTofu parses as HCL: a .tf or a .tfvars.
func Key ¶ added in v0.1.3
Key writes a map's key: the name as it is where HCL takes it as an identifier, and a string literal otherwise, so a key from a placement's own words never ends the map.
func OneLine ¶ added in v0.1.3
OneLine is the text on one line, each line break a space: how the render's Go code writes a value into a line comment it builds itself.
func Parses ¶ added in v0.1.3
Parses refuses a rendered OpenTofu file that does not parse, with the file, the line and the parser's own sentence: tofu would refuse the whole stack at its first step, after the check that compares the files with the render had passed them. The file is bedrock's to write so that it parses, whatever the code and the placement hold, so the refusal says whose defect it is and quotes the line, which is in no file to look at.
func Quote ¶ added in v0.1.3
Quote writes s as an HCL string literal, quotes and all, as HCL's own writer writes a string: a double quote, a backslash, a line break and a tab as their escapes, ${ and %{ as $${ and %%{, and a character that does not print by its code point. It is how the render's Go code writes a string where a template takes HCL as it is.
func QuoteList ¶ added in v0.1.3
QuoteList writes the strings as an HCL list of string literals on one line.
func SubstitutionNames ¶
SubstitutionNames reads the pipeline's contract off cloud-build.tf's template: the keys of local.substitutions, in the template's order. The resolve command tells the declared substitutions of a build apart by it.
Types ¶
type File ¶
type File struct {
// Path is the file's path relative to the stack directory, or to the application
// root when Root is set.
Path string
Tier Tier
// Root is true for a file that lives at the application root (the directory
// holding go.mod, the repository's root), where Cloud Build and the image build
// read it, rather than in the stack directory.
Root bool
// Content is the rendered text.
Content []byte
}
File is one rendered file of the stack.
type Tier ¶
type Tier int
Tier says whether the tool owns a file or only seeds it.
type UndeclaredVariable ¶
type UndeclaredVariable struct {
// Path is the referencing file, as the caller named it.
Path string
// Line is the reference's line (1-based).
Line int
// Name is the variable's name, without the var. prefix.
Name string
}
UndeclaredVariable is a reference to an input variable (var.<name>) in one of a stack's .tf files that no variable "<name>" block among them declares. tofu refuses a plan over it ("Reference to undeclared input variable"), so the render tests hold every template to the declarations and bedrock check refuses one in a committed stack, a person's files included.
func UndeclaredVariables ¶
func UndeclaredVariables(files map[string][]byte) []UndeclaredVariable
UndeclaredVariables finds every input variable the .tf files reference that none of them declares, by file and then by line, over the files' contents by path. A line that is a comment whole is not read; a reference anywhere else is, a string or a heredoc included, since a template's prose names only variables the stack has. One name referenced twice on a line is one finding.
type Written ¶
type Written struct {
// Owned counts the owned files written into the stack directory.
Owned int
// Pipeline lists the owned files written at the application root.
Pipeline []string
// Seeded lists the seeded files created, and Kept the ones left as they were.
Seeded []string
Kept []string
// Removed lists the retired files found at the application root and removed.
Removed []string
}
Written reports what a write did.