Skip to content
nexovia
All insights

DevOps

CI/CD pipeline best practices: a checklist for a healthy pipeline

A healthy pipeline tests every pull request, builds one image and promotes it unchanged, and makes rollback a routine action. This is the checklist we use when we review one.

The Nexovia team · · 4 min read

What a healthy pipeline looks like

CI/CD pipeline best practices come down to three properties. Every change is checked before it merges. One artifact is built once and moves unchanged from staging to production. Deploys and rollbacks are routine actions that anyone on the team can run. The rest of this checklist is how to get there, with examples from GitHub Actions; the same ideas apply to GitLab CI and other tools.

Tests on every pull request

A workflow triggered by the pull_request event runs lint, type checks, unit tests and a build. In the repository settings, branch protection marks those checks as required, so a red pull request cannot be merged. Integration tests get a real database: GitHub Actions can start PostgreSQL as a service container next to the job.

Speed decides whether people respect the pipeline. To keep feedback fast:

  • Cache dependencies. The setup-node action can cache npm, pnpm or Yarn packages between runs.
  • Split lint, tests and build into parallel jobs.
  • Use a concurrency group with cancel-in-progress, so a new push cancels the run for the previous commit.
  • Run the slow end-to-end suite on a small set of critical flows, and the full suite on main or nightly.

Build once, promote the same image

On merge to main, the pipeline builds one Docker image, tags it with the Git commit SHA and pushes it to a registry such as GitHub Container Registry. Staging deploys that image. Production later deploys the same image, not a rebuild. What you tested is what you ship.

Two rules make this work. Configuration comes from environment variables at runtime and is never baked into the image. And nothing deploys the floating latest tag, because it tells you nothing about what is running. One trap for Next.js teams: variables prefixed with NEXT_PUBLIC_ are inlined at build time, so they have to be identical across environments or be loaded at runtime another way.

Preview environments

A preview environment gives every pull request its own URL, so a reviewer, a designer or a product manager can click through the change before it merges. Platforms such as Vercel do this out of the box for frontends. For a full stack, the pipeline deploys the pull request's image to a temporary environment, and a second workflow, triggered when the pull request closes, removes it.

Give previews a seeded database, never a copy of production with personal data. Previews are also the right target for end-to-end tests: Playwright runs against the preview URL and reports in the pull request.

Database migrations

Migrations live in the repository and run as an explicit pipeline step before the new version receives traffic. They do not run by hand, and they do not run at application startup, where several replicas would race each other.

Write every migration to be compatible with the version of the code that is already running. The pattern is expand and contract: add the new column as nullable, deploy code that writes to both columns, backfill, and remove the old column in a later release. It takes more steps, and it is the reason a code rollback stays safe.

Secrets

Secrets never belong in the repository or in the image. Four habits cover most of the risk:

  • Store pipeline secrets as encrypted GitHub Actions secrets, scoped to an environment. A production environment can require approval from a reviewer before a job runs.
  • Authenticate to AWS or Google Cloud with OpenID Connect. The workflow receives short-lived credentials, and there is no long-lived access key to leak.
  • Pin third-party actions to a full commit SHA, since such an action runs inside your job, next to your secrets.
  • Load application secrets at runtime from a secret manager, and rotate them on a schedule.

Rollbacks and deploy frequency

Because every image is tagged with its commit, a rollback is a deploy of the previous tag. We add a manually triggered workflow, using workflow_dispatch with the image tag as input, and we run it on staging from time to time so that nobody discovers how it works during an incident. After each deploy, a health check and a short smoke test decide whether the release stays.

Deploy frequency is the best single indicator of pipeline health. Teams that deploy small changes every day have small problems. Teams that deploy once a month ship a month of risk at once. If releasing a feature to users has to wait, hide it behind a feature flag and keep deploying. Even a small Israeli startup with three developers can run all of this from a handful of workflow files.

Keep reading

Strategy

MVP tech stack: how a startup should choose

An MVP's stack has one job: let a small team ship the product and change it quickly. Here is what we look at when choosing, what we buy ready-made and what we deliberately leave for later.

· 5 min read

Design, build and ship your project

Describe it in three lines. We reply with specific questions and a first take on how to proceed.