SteelReed

Search

Search posts, questions…

6. DevOps & Operations

CI/CD for a Spring Boot backend: a GitHub Actions pipeline from commit to production

How CI, continuous delivery and continuous deployment differ; a GitHub Actions workflow for a Spring Boot 4 service on Java 25 (build, Testcontainers, static analysis, image build and scan, deploy); build once and promote, secrets and OIDC, pinning actions to a SHA, Flyway in the pipeline, rollback; Dependabot, Renovate and AI review as extra gates while a human still approves.

18 Nov 20268 min readMid

–

1. The problem

Tag v1.4.0, and the production job rebuilds the image, pulling in a new SNAPSHOT: 30% of requests return 500 although staging was green. Rolling back to the old digest takes 20 minutes and still fails, because a migration just renamed a column.

2. Key idea

The pipeline is the only road from commit to production. It breaks when what reaches production differs from what was tested, or when an automated step has no owner. The image from main is tagged sha-<commit>; a release only adds the label 1.4.0 to the same digest.

Failure point Symptom Root cause
Rebuilding per environment staging green, production broken production runs an image that was never tested
Drifting actions, dependencies a secret leaks into logs pinned by tag, updates nobody reads
Incompatible migration still broken after rollback the database doesn't roll back with the code
25-minute PR wait developers batch huge PRs no cache, repeated test setup, images built on PRs

2.1 Which gates block, which only advise?

Choice Use when Don't use when
Continuous delivery (approval button) you need to pick the moment: banking, payments the button is just ritual
Continuous deployment tests, monitoring, automatic rollback are trusted you can't yet measure failure rate and recovery time
Blocking gate (required status check) tests, new issues in new code, fixable severe CVEs style preferences, CVEs with no fix
AI review a first pass: obvious bugs, missing tests, leaked secrets replacing human approval
Bot auto-merge patch releases that passed every check majors, Spring Boot, the JDK, base images

3. In GitHub Actions

YAML
on:
  pull_request:
  push: { branches: [main], tags: ['v*.*.*'] }
permissions:
  contents: read                # jobs that need more ask for it
jobs:
  build-test:
    runs-on: ubuntu-24.04
    timeout-minutes: 20
    steps:
      # pin the SHA, keep the version in a comment so bots can update it
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - uses: actions/setup-java@v6
        with: { distribution: temurin, java-version: '25', cache: maven }
      - run: ./mvnw -B -ntp verify   # unit tests, Testcontainers, static analysis
  # image (main only): build, scan, push sha-<commit>
  # promote (tag): label the existing digest 1.4.0, no rebuild
  # deploy-*: staging or production environment, cloud login via OIDC

Other platforms: GitLab CI has environment and id_tokens for OIDC; Go or Node.js services just swap ./mvnw verify for go test ./... or npm ci && npm test.

Making the PR pipeline faster

Measure before optimizing. Five changes usually cut the most:

  • Maven cache (cache: maven): minutes of downloads become seconds.
  • Shared Testcontainers for the whole suite (static containers in a base class, Spring context reused): 40 PostgreSQL startups become one.
  • No image builds on PRs; on main, the Dockerfile copies the tested jar instead of running mvn package again.
  • Static analysis in a parallel job.
  • concurrency with cancel-in-progress to cancel stale runs on repeated pushes.

Dropping integration tests from PRs means SQL bugs only surface after merge, and a red main blocks the whole team. Bigger runners help little when most time is spent downloading and starting containers.

4. Working with AI

Hand to AI: drafting workflows and dependabot.yml, reading red job logs, summarizing changelogs in bot PRs, first-pass review of each PR.

Check yourself in AI-written code:

  • Workflow-level permissions: is contents: read; jobs that ask for more have a reason.
  • Every third-party uses: is pinned to a 40-character SHA; no pull_request_target checks out PR code.
  • Deploy jobs don't run docker build or mvnw package; they take a digest.
  • Secrets go through env:, never command arguments or echo.
  • Branch protection still requires a human approval; bots and AI don't count as reviewers.

5. Exercises

Exercise 1: Review a "faster" workflow

The AI changed the production job: "faster, no waiting for the promote job, still safe thanks to caching". Find the problems and fix them.

YAML
deploy-production:
  if: github.ref_type == 'tag'
  environment: production
  steps:
    - uses: actions/checkout@v7
    - uses: docker/build-push-action@v7
      with: { push: true, tags: "ghcr.io/acme/orders-service:latest", cache-from: type=gha }
    - uses: aquasecurity/[email protected]
    - run: kubectl -n orders set image deployment/orders-service app=ghcr.io/acme/orders-service:latest
Solution 1
  • Rebuilding in production: this isn't the digest tested on staging; caching makes builds faster, not identical. Keep the promote job that finds the digest by sha-<commit> and deploys by digest.
  • Deploying latest: a moving tag; rollback has nothing to return to.
  • Scanning after pushing, with no exit-code: '1': it blocks nothing.
  • Actions by tag: tags can be moved to other code; pin SHAs.
  • The job reads production secrets without its own permissions.

Check: compare the digest running in production (kubectl get deploy orders-service -o jsonpath='{..image}') with the one deployed to staging from the same commit.

Exercise 2: Review a column-rename migration

orders has customer_name, to be renamed full_name. 3 pods, rolling updates, one-version rollback. The AI writes ALTER TABLE orders RENAME COLUMN customer_name TO full_name; and says "no downtime, the statement is instant". Find the problem and rewrite the plan.

Solution 2

The statement is instant, but old pods still running (and the old version on rollback) break immediately because customer_name is gone. Split into three releases:

  1. Expand: ADD COLUMN full_name varchar(200); code writes both, reads COALESCE(full_name, customer_name). Rollback is safe.
  2. Migrate: backfill UPDATE orders SET full_name = customer_name WHERE full_name IS NULL in batches; code reads full_name and stops writing the old column.
  3. Contract: once no version reads customer_name, DROP COLUMN.

Summary

  • Build once, deploy by digest; a release only adds a label.
  • Secrets: OIDC, minimal permissions, actions pinned by SHA.
  • Migrations before rollout, expand → contract; rollback doesn't rewind the database.
  • Blocking gates for tests and new issues; bots and AI are secondary gates.
  • Measure before optimizing the pipeline.

Further reading: An AI-agent-friendly codebase.


Self-compiled notes from official documentation and hands-on practice.

Practice interview questions on this topic

All DevOps & Cloud questions →

Loading comments…
Next on the roadmapDeployment strategies: rolling, blue-green, canary, feature flags and zero downtime on Kubernetes