Lifecycle Hooks

Sometimes a deploy needs to do a little more than stand up infrastructure — seed a database, warm a cache, ping a Slack channel with the new URL. Gothic gives you two optional lifecycle hooks you declare right in gothic.config.go: BeforeDeploy and AfterDeploy. They are plain top-level Go functions with no receiver.
BeforeDeploy fires before anything in AWS is touched, so returning an error cleanly cancels the whole deploy. AfterDeploy fires once everything is live and receives the stack outputs (CloudFront domain, bucket name, Lambda ARN) in gctx.Outputs. Neither hook fires on a delete.
import (
"context"
"fmt"
gothic "github.com/gothicframework/core/config"
)
// BeforeDeploy runs synchronously BEFORE tofu apply. Return an error to abort.
func BeforeDeploy(ctx context.Context, gctx *gothic.GothicContext) error {
fmt.Println("About to deploy stage:", gctx.Stage)
return nil
}
// AfterDeploy runs AFTER apply + S3 sync. gctx.Outputs is populated.
func AfterDeploy(ctx context.Context, gctx *gothic.GothicContext) error {
fmt.Println("Live at:", gctx.Outputs["cloudfront_domain_name"])
return nil
}Note: hooks run in an isolated compiled subprocess — Gothic copies your gothic.config.go into a throwaway module and runs it, passing the context as JSON. Any mutation you make to gctx flows back into the deploy pipeline, and your hook code never runs inside the CLI process itself.
Everything is configured. Time to ship it with the deploy commands!
