Diff Config Files Before Deploying โ Catch Infrastructure Changes Early
Comparing configuration files before deployment catches unintended changes that could cause production incidents. Here is the workflow.
One of the most common causes of production incidents is a configuration mismatch. You think staging and production are identical, but someone changed a setting weeks ago and forgot to propagate it. Diffing config files before every deployment is a habit that catches these issues before they cause outages.
What to compare before deploying
The configs most likely to diverge between environments:
- Application config files (
config.json,app.yaml) - Nginx or Apache configuration
- Docker Compose files
- Kubernetes manifests
- Environment variable files (
.env.stagingvs.env.production) - Database migration scripts
Automating config comparison in CI
# Compare current config against what's deployed # Using jq to normalize JSON before comparing (ignores key ordering) staging_config=$(cat config.staging.json | jq -S .) current_config=$(cat config.json | jq -S .) if [ "$staging_config" != "$current_config" ]; then echo "WARNING: Config mismatch detected!" diff <(echo "$staging_config") <(echo "$current_config") exit 1 fi
Diffing Kubernetes configs
# See what would change if you apply a manifest kubectl diff -f deployment.yaml # Compare resources between namespaces kubectl get deployment myapp -n staging -o yaml > staging.yaml kubectl get deployment myapp -n production -o yaml > prod.yaml diff staging.yaml prod.yaml
Diffing nginx configs
# On the server diff /etc/nginx/sites-enabled/mysite.conf /path/to/repo/nginx/mysite.conf # Test config validity before deploying nginx -t -c /path/to/new/nginx.conf
Structured config formats need normalization
JSON objects don't have a defined key order, so two functionally identical configs can produce diff noise. Always normalize before comparing: sort JSON keys, strip comments from YAML, ignore blank lines. Tools like jq -S (sort keys) help here.
For quick manual comparison, paste both configs into our Diff Checker and scan the differences before you deploy.