Start with the release, then choose the tools
Before opening a workflow file, write down what a safe release means for the application. Which checks must pass? Who can approve production? What tells the team that the release is healthy? How do you return to the previous version?
For a small service, a useful first design is deliberately simple: validate a pull request, build an image from a reviewed commit, test and scan that image, then promote the same artifact through staging and production. Each stage should answer a specific question rather than add another green tick.
Keep the credential boundary small
Treat third-party actions and workflow inputs as part of the application’s attack surface. Prefer minimal default token permissions, pin third-party actions to a full commit SHA, and grant extra access only to jobs that require it. Avoid putting untrusted input directly into shell scripts.
Keep pull-request validation separate from privileged deployment work. A contribution should be testable without receiving production credentials. Use workload identity where supported, with trust conditions scoped to the intended repository and deployment context.
# Starting point: read-only repository access.
# Grant deployment permissions only in the deployment job.
permissions:
contents: readBuild once and promote deliberately
Record the commit, image digest, and scan result together. Rebuilding separately for production can introduce a different artifact from the one that passed staging. Promoting a known digest makes the release easier to explain and investigate.
Define what should block a release and who owns exceptions. A scanner that produces hundreds of ignored findings creates noise. A smaller set of actionable gates, with owners and expiry dates for exceptions, is easier to maintain.
Make rollback a deliverable
A previous image is useful only when it can still run against the current database and configuration. Plan backward-compatible schema changes and rehearse the recovery procedure in a non-production environment.
The pipeline is ready for handoff when another engineer can identify the deployed version, read the health signals, and follow a recovery runbook without asking the original author.
- A release links to a reviewed commit and immutable artifact.
- Production access is restricted to the deployment context.
- Post-release checks cover errors, latency, and application health.
- The rollback procedure includes database and configuration constraints.
Further reading
Project references and official documentation for further reading: