TExcelTAD
Home › GitOps: Argo CD & Flux › Environment Promotion by Commit

Environment Promotion by Commit

In GitOps, deploying to an environment means changing that environment's folder. Promotion is the same thing with a rule attached: a version reaches production only after it has run in staging. This lesson builds that flow in Git and looks at who (or what) makes the commits.

The flow

text
CI (app repo)          linkly-deploy (main)                      agents
--------------         ------------------------------------      --------------------------
build 1.5.0     ──PR──> apps/linkly/staging: tag 1.5.0     ──>   staging syncs 1.5.0
                       (auto-merged, or merged by on-call)        tests / soak time / metrics
                ──PR──> apps/linkly/production: tag 1.5.0  ──>   production syncs 1.5.0
                       (needs approval from CODEOWNERS)
rollback:              git revert <promotion commit>        ──>   production back to 1.4.0

The production change is a separate commit, so it can have its own reviewers, its own time, and its own revert.

Promotion as Git commits

This session runs the whole cycle: a release to staging, a promotion to production by copying the staging tag with yq, a look at exactly what the promotion changed, and a rollback by git revert:

bash · try it yourself
git init -q linkly-deploy && cd linkly-deploy
mkdir -p apps/linkly/staging apps/linkly/production
printf 'image:\n  tag: 1.4.0\nreplicaCount: 1\nlogLevel: debug\n' > apps/linkly/staging/values.yaml
printf 'image:\n  tag: 1.4.0\nreplicaCount: 3\n' > apps/linkly/production/values.yaml
git add . && git commit -qm "linkly 1.4.0 in staging and production"

yq -i '.image.tag = "1.5.0"' apps/linkly/staging/values.yaml
git commit -qam "staging: linkly 1.5.0"

# staging looked good: copy exactly the staging tag, nothing else
yq -i '.image.tag = load("apps/linkly/staging/values.yaml").image.tag' apps/linkly/production/values.yaml
git commit -qam "production: promote linkly 1.5.0 from staging"
git show --stat --format='%h %s' HEAD
git diff HEAD~1 -- apps/linkly/production

# 1.5.0 misbehaves in production: undo only the promotion
git revert --no-edit HEAD >/dev/null
git log --oneline
echo "production now: $(yq .image.tag apps/linkly/production/values.yaml), staging still: $(yq .image.tag apps/linkly/staging/values.yaml)"
fd8b880 production: promote linkly 1.5.0 from staging

 apps/linkly/production/values.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/apps/linkly/production/values.yaml b/apps/linkly/production/values.yaml
index a9884d5..22cd830 100644
--- a/apps/linkly/production/values.yaml
+++ b/apps/linkly/production/values.yaml
@@ -1,3 +1,3 @@
 image:
-  tag: 1.4.0
+  tag: 1.5.0
 replicaCount: 3
a2b9339 Revert "production: promote linkly 1.5.0 from staging"
fd8b880 production: promote linkly 1.5.0 from staging
c373fcc staging: linkly 1.5.0
8f3e712 linkly 1.4.0 in staging and production
production now: 1.4.0, staging still: 1.5.0

The revert touches only production; staging keeps 1.5.0 so the team can debug it there. Notice what the promotion did not copy: replicaCount and logLevel stay environment-specific. Promote versions, not whole folders.

What to promote

Promote Keep per environment
image tag or digest replicas, resources, autoscaling
chart version hostnames, log level
config that is part of the release (a new feature flag's default) secrets, database endpoints

A good layout makes the promotable part small: one image.tag line, or one chart version line. If a promotion needs edits in ten files, the environments are not structured around what moves.

Who makes the promotion commit

Approach How Fits
CI job in the app repo after the image push, open a PR against linkly-deploy (gh pr create, or GitLab's API) bumping staging; a later job or a person bumps production most teams; see Build, Scan, Push, Deploy
agent-side image automation the agent watches the registry and commits new tags itself staging auto-updates (Flux Image Automation, Argo CD Image Updater)
promotion tools Kargo (from the Argo CD creators) models stages and promotes "freight" between them with verification steps many environments, strict gates
a person edit, PR, review, merge production with change approval

A promotion gate, modelled

A production promotion should only be proposed when staging is actually running the candidate, synced and healthy, for long enough. This model checks those conditions against fixed status snapshots (in a real setup they come from argocd app get -o json or Flux status conditions):

python · try it yourself
SOAK_MINUTES = 30

def can_promote(candidate, staging):
    reasons = []
    if staging["image"] != candidate:
        reasons.append(f"staging runs {staging['image']}, not {candidate}")
    if staging["sync"] != "Synced":
        reasons.append(f"staging is {staging['sync']}")
    if staging["health"] != "Healthy":
        reasons.append(f"staging is {staging['health']}")
    if staging["healthy_minutes"] < SOAK_MINUTES:
        reasons.append(f"healthy for {staging['healthy_minutes']} min, need {SOAK_MINUTES}")
    if staging["error_rate"] > 0.01:
        reasons.append(f"error rate {staging['error_rate']:.1%} > 1.0%")
    return reasons

snapshots = [
    ("10:05", {"image": "1.5.0", "sync": "OutOfSync", "health": "Progressing", "healthy_minutes": 0, "error_rate": 0.0}),
    ("10:20", {"image": "1.5.0", "sync": "Synced", "health": "Healthy", "healthy_minutes": 12, "error_rate": 0.002}),
    ("10:45", {"image": "1.5.0", "sync": "Synced", "health": "Healthy", "healthy_minutes": 37, "error_rate": 0.002}),
]
for time, status in snapshots:
    blockers = can_promote("1.5.0", status)
    print(time, "PROMOTE: open PR for production" if not blockers else "wait: " + "; ".join(blockers))
10:05 wait: staging is OutOfSync; staging is Progressing; healthy for 0 min, need 30
10:20 wait: healthy for 12 min, need 30
10:45 PROMOTE: open PR for production

Test yourself

Why should a production promotion be its own commit rather than part of the staging change?

  1. Git requires it
  2. It can be reviewed, timed and reverted independently of staging
  3. Agents only read the last commit
  4. It makes the repository smaller

During a promotion, which value should normally be copied from staging to production?

  1. replicaCount
  2. The image tag (or digest)
  3. The hostname
  4. The log level

Production misbehaves after a promotion. What does git revert of the promotion commit change?

  1. Both staging and production
  2. Only the production values, back to the previous version
  3. Nothing until someone runs kubectl
  4. It deletes the production folder