1
---
2
name: gem-devops-guidelines
3
description: Design or review infrastructure, deployment, CI/CD, Docker, Kubernetes, health checks, rollback, feature flags, production readiness, and mobile release workflows. Use for DevOps, platform, container, pipeline, or release tasks.
4
---
5
6
# DevOps Guidelines
7
8
## When to Use
9
10
Use for DevOps, platform, container, pipeline, or release tasks - any work that touches infrastructure, deployment, CI/CD, Docker, Kubernetes, health checks, rollback, feature flags, production readiness, or mobile release workflows.
11
12
## Numbered Workflow
13
14
1. **Assess** - identify workload type, target provider/environment, acceptance criteria, and risk level.
15
2. **Classify** - select applicable sections (deployment strategy, Docker, K8s, CI/CD, health, config, rollback, feature flags, mobile) based on workload/provider/environment.
16
3. **Plan** - for each selected section, define concrete steps, validation checks, and rollback triggers.
17
4. **Apply** - execute the plan, running validation at each gate (lint -> typecheck -> unit -> integration -> preview -> smoke).
18
5. **Verify** - confirm health endpoints, monitoring, rollback capability, and documented outcome.
19
6. **Rollback-ready** - ensure a tested rollback path exists before declaring success.
20
21
## Edge Cases
22
23
- Idempotent re-run: workflow must be safe to execute multiple times without side effects.
24
- Missing credentials: fail fast with clear error; never proceed with partial auth.
25
- Workload without health endpoint: deploy but flag as incomplete; require health endpoint before production promotion.
26
- Image digest pinning: always pin by digest (`image@sha256:...`) not tag for production.
27
- Phased rollout rollback: if canary/blue-green rollout fails, revert traffic split instantly; do not wait for full rollback.
28
29
---
30
31
Apply only sections relevant to workload/provider/environment/acceptance criteria. Skip Docker, Kubernetes, mobile, production, rollback, health, feature-flag, security checks when not applicable.
32
33
## Deployment strategy
34
35
- Rolling (default): gradual, zero-downtime replacement.
36
- Blue-green: duplicate environments, atomic cutover, instant rollback, 2x infra.
37
- Canary: route small % first; requires traffic splitting.
38
39
## Docker
40
41
- Applies to containerized workloads only. Pin base-image tags (`node:22-alpine`); NEVER `:latest`.
42
- Multi-stage builds + non-root user. Copy deps first for caching.
43
- `.dockerignore`: `node_modules`, `.git`, tests. Define `HEALTHCHECK` + resource limits.
44
45
## Kubernetes
46
47
Configure startup, readiness, liveness probes with workload-appropriate initial delays/thresholds. Applies to containerized workloads only.
48
49
## CI/CD
50
51
- PR: lint -> typecheck -> unit -> integration -> preview.
52
- Main: build -> staging -> smoke -> production.
53
54
## Health and shutdown
55
56
- Applies to HTTP/network services with health endpoints only. Simple: `GET /health` -> `{ "status": "ok" }`.
57
- Detailed: dependencies, uptime, version.
58
- Services MUST expose meaningful health + gracefully handle `SIGTERM` when workload requires it and exposes a health endpoint.
59
60
## Configuration
61
62
Use environment variables (Twelve-Factor), separated by environment. Validate at startup + fail fast. NEVER commit secrets or hard-code `NODE_ENV=production`.
63
64
## Rollback
65
66
- Kubernetes: `kubectl rollout undo`.
67
- Vercel: `vercel rollback`.
68
- Docker: redeploy previous pinned image.
69
70
## Feature Flags
71
72
- Lifecycle: create -> enable -> 5% -> 25% -> 50% -> 100% -> remove flag + dead code.
73
- Every flag MUST have owner, rollback trigger, and configured expiration (default: 30 days; configurable per platform).
74
75
## Checklists
76
77
- Pre-deploy: passing tests, code review, env vars, migrations, rollback plan.
78
- Post-deploy: healthy, monitored, old pods terminated, outcome documented.
79
- Production: passing tests; no hardcoded secrets; JSON logs; meaningful health; pinned versions; validated env vars; resource limits; TLS; CVE scan; CORS; rate limiting; CSP/HSTS/X-Frame-Options; tested rollback; runbook; on-call.
80
- Apply security/CVE checks to executable or security-sensitive workloads.
81
82
## Mobile Deployment
83
84
- EAS: `eas build:configure`; `eas build -p ios|android --profile preview`; `eas update --branch production`; `--auto-submit`.
85
- Fastlane: iOS `match`/`cert`/`sigh`/`pilot`; Android Gradle/`supply`.
86
- Credentials in env/secret storage, never Git. Automate iOS signing with `fastlane match`; use `keytool` + Google Play App Signing for Android.
87
- TestFlight: internal instant; external 90 days/100 testers. Google Play: internal/beta/production. Expect 1-7 days review.
88
- Rollback: EAS `eas update:rollback`; native release -> revert build; store release -> reduce phased rollout.
89