ai-playbook 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +146 -0
- package/agents/README.md +168 -0
- package/agents/SKILL.md +633 -0
- package/agents/architect/AGENT.md +44 -0
- package/agents/architect/README.md +5 -0
- package/agents/coder/AGENT.md +43 -0
- package/agents/coder/README.md +5 -0
- package/agents/debugger/AGENT.md +42 -0
- package/agents/debugger/README.md +6 -0
- package/agents/devops/AGENT.md +43 -0
- package/agents/devops/README.md +5 -0
- package/agents/documentation/AGENT.md +45 -0
- package/agents/documentation/README.md +5 -0
- package/agents/examples.md +550 -0
- package/agents/performance/AGENT.md +45 -0
- package/agents/performance/README.md +6 -0
- package/agents/planner/AGENT.md +44 -0
- package/agents/planner/README.md +6 -0
- package/agents/product-owner/AGENT.md +46 -0
- package/agents/product-owner/README.md +6 -0
- package/agents/refactorer/AGENT.md +44 -0
- package/agents/refactorer/README.md +6 -0
- package/agents/release-manager/AGENT.md +45 -0
- package/agents/release-manager/README.md +6 -0
- package/agents/researcher/AGENT.md +44 -0
- package/agents/researcher/README.md +6 -0
- package/agents/reviewer/AGENT.md +43 -0
- package/agents/reviewer/README.md +6 -0
- package/agents/security/AGENT.md +46 -0
- package/agents/security/README.md +6 -0
- package/agents/support/AGENT.md +45 -0
- package/agents/support/README.md +6 -0
- package/agents/tester/AGENT.md +46 -0
- package/agents/tester/README.md +5 -0
- package/bin/cli.js +186 -0
- package/commands/README.md +266 -0
- package/commands/build.md +135 -0
- package/commands/clean.md +126 -0
- package/commands/deploy-prod.md +171 -0
- package/commands/deploy-staging.md +147 -0
- package/commands/deps.md +169 -0
- package/commands/dev.md +132 -0
- package/commands/format.md +142 -0
- package/commands/lint.md +125 -0
- package/commands/migrate.md +159 -0
- package/commands/release.md +183 -0
- package/commands/rollback.md +152 -0
- package/commands/seed.md +178 -0
- package/commands/setup.md +109 -0
- package/commands/test.md +134 -0
- package/commands/validate.md +147 -0
- package/context/README.md +7 -0
- package/context/aem.md +47 -0
- package/context/architecture.md +51 -0
- package/context/bullminder.md +57 -0
- package/context/coding-style.md +42 -0
- package/context/communication.md +53 -0
- package/context/company.md +46 -0
- package/context/engineering.md +63 -0
- package/context/project-template.md +71 -0
- package/context/trading.md +52 -0
- package/hooks/README.md +326 -0
- package/hooks/code-review/README.md +6 -0
- package/hooks/code-review/check-coverage.md +101 -0
- package/hooks/custom/README.md +6 -0
- package/hooks/custom/project-specific-hooks.md +273 -0
- package/hooks/deployment/README.md +6 -0
- package/hooks/deployment/health-check.md +102 -0
- package/hooks/deployment/pre-deploy-check.md +84 -0
- package/hooks/documentation/README.md +6 -0
- package/hooks/documentation/update-changelog.md +146 -0
- package/hooks/post-task/README.md +5 -0
- package/hooks/post-task/run-tests.md +61 -0
- package/hooks/pre-commit/README.md +6 -0
- package/hooks/pre-commit/format.md +63 -0
- package/hooks/pre-commit/lint.md +62 -0
- package/hooks/pre-commit/type-check.md +78 -0
- package/hooks/pre-task/README.md +6 -0
- package/hooks/pre-task/check-branch.md +48 -0
- package/hooks/pre-task/validate-environment.md +48 -0
- package/hooks/security-check/README.md +6 -0
- package/hooks/security-check/dependency-audit.md +85 -0
- package/hooks/security-check/secrets-scan.md +77 -0
- package/hooks/test-before-finish/README.md +6 -0
- package/hooks/test-before-finish/run-all-tests.md +128 -0
- package/index.js +69 -0
- package/knowledge/README.md +33 -0
- package/knowledge/ai-agents.md +74 -0
- package/knowledge/decision-making.md +73 -0
- package/knowledge/documentation.md +67 -0
- package/knowledge/engineering-principles.md +65 -0
- package/knowledge/product-discovery.md +68 -0
- package/knowledge/security-privacy.md +54 -0
- package/knowledge/testing-quality.md +63 -0
- package/package.json +63 -0
- package/patterns/README.md +7 -0
- package/prompts/README.md +208 -0
- package/prompts/architect/README.md +96 -0
- package/prompts/architect/design-system.md +140 -0
- package/prompts/debugger/README.md +96 -0
- package/prompts/debugger/diagnose-issue.md +141 -0
- package/prompts/developer/README.md +129 -0
- package/prompts/developer/fix-bug.md +136 -0
- package/prompts/developer/implement-feature.md +133 -0
- package/prompts/product-owner/README.md +116 -0
- package/prompts/product-owner/define-feature.md +145 -0
- package/prompts/reviewer/README.md +91 -0
- package/prompts/reviewer/code-review.md +129 -0
- package/prompts/support/README.md +154 -0
- package/prompts/support/resolve-issue.md +124 -0
- package/roles/README.md +6 -0
- package/roles/design-architect/README.md +98 -0
- package/roles/design-architect/accessibility/README.md +33 -0
- package/roles/design-architect/accessibility/checklists.md +29 -0
- package/roles/design-architect/accessibility/examples.md +35 -0
- package/roles/design-architect/checklists.md +76 -0
- package/roles/design-architect/component-library/README.md +35 -0
- package/roles/design-architect/component-library/checklists.md +29 -0
- package/roles/design-architect/component-library/examples.md +35 -0
- package/roles/design-architect/design-system/README.md +35 -0
- package/roles/design-architect/design-system/checklists.md +27 -0
- package/roles/design-architect/design-system/examples.md +41 -0
- package/roles/design-architect/examples/README.md +31 -0
- package/roles/design-architect/examples/checklists.md +26 -0
- package/roles/design-architect/examples/examples.md +46 -0
- package/roles/design-architect/examples.md +90 -0
- package/roles/design-architect/figma/README.md +33 -0
- package/roles/design-architect/figma/checklists.md +27 -0
- package/roles/design-architect/figma/examples.md +38 -0
- package/roles/design-architect/responsibilities.md +73 -0
- package/roles/design-architect/responsive/README.md +34 -0
- package/roles/design-architect/responsive/checklists.md +26 -0
- package/roles/design-architect/responsive/examples.md +39 -0
- package/roles/design-architect/role.md +129 -0
- package/roles/design-architect/skill-map.md +42 -0
- package/roles/design-architect/triggers.md +110 -0
- package/roles/design-architect/ui/README.md +36 -0
- package/roles/design-architect/ui/checklists.md +29 -0
- package/roles/design-architect/ui/examples.md +28 -0
- package/roles/design-architect/usability/README.md +34 -0
- package/roles/design-architect/usability/checklists.md +28 -0
- package/roles/design-architect/usability/examples.md +31 -0
- package/roles/design-architect/ux/README.md +36 -0
- package/roles/design-architect/ux/checklists.md +28 -0
- package/roles/design-architect/ux/examples.md +37 -0
- package/roles/design-architect/wireframes/README.md +34 -0
- package/roles/design-architect/wireframes/checklists.md +25 -0
- package/roles/design-architect/wireframes/examples.md +32 -0
- package/roles/design-architect/workflow.md +80 -0
- package/roles/devops/README.md +101 -0
- package/roles/devops/ansible/README.md +6 -0
- package/roles/devops/checklists.md +413 -0
- package/roles/devops/ci-cd/README.md +169 -0
- package/roles/devops/ci-cd/checklists.md +289 -0
- package/roles/devops/ci-cd/examples.md +429 -0
- package/roles/devops/cloud-platforms/README.md +109 -0
- package/roles/devops/cost-optimization/README.md +131 -0
- package/roles/devops/disaster-recovery/README.md +118 -0
- package/roles/devops/docker/README.md +6 -0
- package/roles/devops/examples/README.md +6 -0
- package/roles/devops/examples.md +775 -0
- package/roles/devops/github-actions/README.md +6 -0
- package/roles/devops/helm/README.md +6 -0
- package/roles/devops/infrastructure-as-code/README.md +160 -0
- package/roles/devops/infrastructure-as-code/checklists.md +124 -0
- package/roles/devops/jenkins/README.md +6 -0
- package/roles/devops/kubernetes/README.md +150 -0
- package/roles/devops/kubernetes/checklists.md +192 -0
- package/roles/devops/kubernetes/examples.md +189 -0
- package/roles/devops/monitoring/README.md +93 -0
- package/roles/devops/networking/README.md +83 -0
- package/roles/devops/performance/README.md +104 -0
- package/roles/devops/responsibilities.md +95 -0
- package/roles/devops/role.md +130 -0
- package/roles/devops/security/README.md +126 -0
- package/roles/devops/skill-map.md +162 -0
- package/roles/devops/terraform/README.md +6 -0
- package/roles/devops/triggers.md +241 -0
- package/roles/devops/workflow.md +197 -0
- package/roles/qa/README.md +16 -0
- package/roles/qa/api-testing/README.md +6 -0
- package/roles/qa/automation/README.md +6 -0
- package/roles/qa/checklists.md +24 -0
- package/roles/qa/examples/README.md +6 -0
- package/roles/qa/examples.md +27 -0
- package/roles/qa/performance/README.md +6 -0
- package/roles/qa/playwright/README.md +6 -0
- package/roles/qa/responsibilities.md +16 -0
- package/roles/qa/role.md +47 -0
- package/roles/qa/selenium/README.md +6 -0
- package/roles/qa/skill-map.md +14 -0
- package/roles/qa/triggers.md +10 -0
- package/roles/qa/workflow.md +9 -0
- package/roles/software-architect/README.md +16 -0
- package/roles/software-architect/agents/README.md +6 -0
- package/roles/software-architect/ai-architecture/README.md +6 -0
- package/roles/software-architect/aws/README.md +6 -0
- package/roles/software-architect/azure/README.md +6 -0
- package/roles/software-architect/caching/README.md +6 -0
- package/roles/software-architect/checklists.md +25 -0
- package/roles/software-architect/cloud/README.md +6 -0
- package/roles/software-architect/database-design/README.md +6 -0
- package/roles/software-architect/diagrams/README.md +6 -0
- package/roles/software-architect/distributed-systems/README.md +7 -0
- package/roles/software-architect/docker/README.md +6 -0
- package/roles/software-architect/event-driven/README.md +7 -0
- package/roles/software-architect/examples/README.md +6 -0
- package/roles/software-architect/examples.md +22 -0
- package/roles/software-architect/gcp/README.md +6 -0
- package/roles/software-architect/kubernetes/README.md +6 -0
- package/roles/software-architect/messaging/README.md +6 -0
- package/roles/software-architect/rag/README.md +7 -0
- package/roles/software-architect/responsibilities.md +17 -0
- package/roles/software-architect/role.md +46 -0
- package/roles/software-architect/scalability/README.md +6 -0
- package/roles/software-architect/security/README.md +6 -0
- package/roles/software-architect/skill-map.md +15 -0
- package/roles/software-architect/system-design/README.md +6 -0
- package/roles/software-architect/triggers.md +10 -0
- package/roles/software-architect/vector-db/README.md +6 -0
- package/roles/software-architect/workflow.md +9 -0
- package/roles/software-developer/README.md +116 -0
- package/roles/software-developer/api/README.md +365 -0
- package/roles/software-developer/api/checklist.md +131 -0
- package/roles/software-developer/api/examples.md +459 -0
- package/roles/software-developer/authentication/README.md +26 -0
- package/roles/software-developer/authentication/checklists.md +22 -0
- package/roles/software-developer/authentication/examples.md +32 -0
- package/roles/software-developer/authorization/README.md +26 -0
- package/roles/software-developer/authorization/checklists.md +21 -0
- package/roles/software-developer/authorization/examples.md +27 -0
- package/roles/software-developer/backend/README.md +26 -0
- package/roles/software-developer/backend/checklists.md +21 -0
- package/roles/software-developer/backend/examples.md +21 -0
- package/roles/software-developer/cache/README.md +25 -0
- package/roles/software-developer/cache/checklists.md +21 -0
- package/roles/software-developer/cache/examples.md +22 -0
- package/roles/software-developer/checklists.md +122 -0
- package/roles/software-developer/code-review/README.md +23 -0
- package/roles/software-developer/code-review/checklists.md +22 -0
- package/roles/software-developer/code-review/examples.md +20 -0
- package/roles/software-developer/database/README.md +27 -0
- package/roles/software-developer/database/checklists.md +21 -0
- package/roles/software-developer/database/examples.md +27 -0
- package/roles/software-developer/debugging/README.md +24 -0
- package/roles/software-developer/debugging/checklists.md +20 -0
- package/roles/software-developer/debugging/examples.md +28 -0
- package/roles/software-developer/examples/README.md +22 -0
- package/roles/software-developer/examples/checklists.md +8 -0
- package/roles/software-developer/examples/examples.md +25 -0
- package/roles/software-developer/examples.md +378 -0
- package/roles/software-developer/frontend/README.md +76 -0
- package/roles/software-developer/frontend/accessibility/README.md +136 -0
- package/roles/software-developer/frontend/accessibility/best-practices.md +368 -0
- package/roles/software-developer/frontend/code-quality/README.md +136 -0
- package/roles/software-developer/frontend/code-quality/best-practices.md +309 -0
- package/roles/software-developer/frontend/components/README.md +65 -0
- package/roles/software-developer/frontend/components/best-practices.md +273 -0
- package/roles/software-developer/frontend/debugging/README.md +149 -0
- package/roles/software-developer/frontend/debugging/best-practices.md +329 -0
- package/roles/software-developer/frontend/examples/README.md +19 -0
- package/roles/software-developer/frontend/examples/checklists.md +8 -0
- package/roles/software-developer/frontend/examples/examples.md +17 -0
- package/roles/software-developer/frontend/logging-observability/README.md +196 -0
- package/roles/software-developer/frontend/logging-observability/best-practices.md +430 -0
- package/roles/software-developer/frontend/performance/README.md +99 -0
- package/roles/software-developer/frontend/performance/best-practices.md +350 -0
- package/roles/software-developer/frontend/state-management/README.md +85 -0
- package/roles/software-developer/frontend/state-management/best-practices.md +344 -0
- package/roles/software-developer/frontend/testing/README.md +114 -0
- package/roles/software-developer/frontend/testing/best-practices.md +272 -0
- package/roles/software-developer/fullstack/README.md +25 -0
- package/roles/software-developer/fullstack/checklists.md +19 -0
- package/roles/software-developer/fullstack/examples.md +14 -0
- package/roles/software-developer/graphql/README.md +24 -0
- package/roles/software-developer/graphql/checklists.md +20 -0
- package/roles/software-developer/graphql/examples.md +24 -0
- package/roles/software-developer/integration-tests/README.md +25 -0
- package/roles/software-developer/integration-tests/checklists.md +20 -0
- package/roles/software-developer/integration-tests/examples.md +18 -0
- package/roles/software-developer/java/README.md +24 -0
- package/roles/software-developer/java/checklists.md +16 -0
- package/roles/software-developer/java/examples.md +22 -0
- package/roles/software-developer/javascript/README.md +24 -0
- package/roles/software-developer/javascript/checklists.md +15 -0
- package/roles/software-developer/javascript/examples.md +18 -0
- package/roles/software-developer/logging/README.md +105 -0
- package/roles/software-developer/logging/checklists.md +48 -0
- package/roles/software-developer/logging/examples.md +135 -0
- package/roles/software-developer/messaging/README.md +24 -0
- package/roles/software-developer/messaging/checklists.md +21 -0
- package/roles/software-developer/messaging/examples.md +26 -0
- package/roles/software-developer/microservices/README.md +25 -0
- package/roles/software-developer/microservices/checklists.md +21 -0
- package/roles/software-developer/microservices/examples.md +21 -0
- package/roles/software-developer/node/README.md +25 -0
- package/roles/software-developer/node/checklists.md +15 -0
- package/roles/software-developer/node/examples.md +15 -0
- package/roles/software-developer/nosql/README.md +24 -0
- package/roles/software-developer/nosql/checklists.md +21 -0
- package/roles/software-developer/nosql/examples.md +20 -0
- package/roles/software-developer/observability/README.md +25 -0
- package/roles/software-developer/observability/checklists.md +21 -0
- package/roles/software-developer/observability/examples.md +22 -0
- package/roles/software-developer/performance/README.md +26 -0
- package/roles/software-developer/performance/checklists.md +20 -0
- package/roles/software-developer/performance/examples.md +20 -0
- package/roles/software-developer/python/README.md +25 -0
- package/roles/software-developer/python/checklists.md +15 -0
- package/roles/software-developer/python/examples.md +17 -0
- package/roles/software-developer/react/README.md +24 -0
- package/roles/software-developer/react/checklists.md +15 -0
- package/roles/software-developer/react/examples.md +22 -0
- package/roles/software-developer/refactoring/README.md +23 -0
- package/roles/software-developer/refactoring/checklists.md +21 -0
- package/roles/software-developer/refactoring/examples.md +11 -0
- package/roles/software-developer/responsibilities.md +58 -0
- package/roles/software-developer/role.md +127 -0
- package/roles/software-developer/skill-map.md +88 -0
- package/roles/software-developer/springboot/README.md +25 -0
- package/roles/software-developer/springboot/checklists.md +15 -0
- package/roles/software-developer/springboot/examples.md +21 -0
- package/roles/software-developer/sql/README.md +24 -0
- package/roles/software-developer/sql/checklists.md +22 -0
- package/roles/software-developer/sql/examples.md +20 -0
- package/roles/software-developer/testing/README.md +25 -0
- package/roles/software-developer/testing/checklists.md +21 -0
- package/roles/software-developer/testing/examples.md +19 -0
- package/roles/software-developer/triggers.md +550 -0
- package/roles/software-developer/typescript/README.md +25 -0
- package/roles/software-developer/typescript/checklists.md +15 -0
- package/roles/software-developer/typescript/examples.md +18 -0
- package/roles/software-developer/unit-tests/README.md +24 -0
- package/roles/software-developer/unit-tests/checklists.md +19 -0
- package/roles/software-developer/unit-tests/examples.md +22 -0
- package/roles/software-developer/workflow.md +196 -0
- package/roles/sre/README.md +16 -0
- package/roles/sre/alerts/README.md +6 -0
- package/roles/sre/availability/README.md +6 -0
- package/roles/sre/chaos/README.md +6 -0
- package/roles/sre/checklists.md +24 -0
- package/roles/sre/examples/README.md +6 -0
- package/roles/sre/examples.md +19 -0
- package/roles/sre/observability/README.md +6 -0
- package/roles/sre/reliability/README.md +6 -0
- package/roles/sre/responsibilities.md +16 -0
- package/roles/sre/role.md +46 -0
- package/roles/sre/skill-map.md +14 -0
- package/roles/sre/slos/README.md +6 -0
- package/roles/sre/triggers.md +10 -0
- package/roles/sre/workflow.md +9 -0
- package/roles/support-engineer/README.md +16 -0
- package/roles/support-engineer/checklists.md +24 -0
- package/roles/support-engineer/datadog/README.md +6 -0
- package/roles/support-engineer/examples/README.md +6 -0
- package/roles/support-engineer/examples.md +17 -0
- package/roles/support-engineer/incident-response/README.md +6 -0
- package/roles/support-engineer/kubernetes/README.md +6 -0
- package/roles/support-engineer/linux/README.md +6 -0
- package/roles/support-engineer/logs/README.md +6 -0
- package/roles/support-engineer/monitoring/README.md +6 -0
- package/roles/support-engineer/networking/README.md +6 -0
- package/roles/support-engineer/newrelic/README.md +6 -0
- package/roles/support-engineer/postmortem/README.md +6 -0
- package/roles/support-engineer/production/README.md +6 -0
- package/roles/support-engineer/responsibilities.md +16 -0
- package/roles/support-engineer/role.md +47 -0
- package/roles/support-engineer/root-cause-analysis/README.md +6 -0
- package/roles/support-engineer/runbooks/README.md +6 -0
- package/roles/support-engineer/skill-map.md +14 -0
- package/roles/support-engineer/splunk/README.md +6 -0
- package/roles/support-engineer/triggers.md +10 -0
- package/roles/support-engineer/troubleshooting/README.md +6 -0
- package/roles/support-engineer/workflow.md +9 -0
- package/setup.sh +204 -0
- package/skills/.claude/README.md +7 -0
- package/skills/README.md +21 -0
- package/skills/ai-agents/README.md +207 -0
- package/skills/ai-agents/examples.md +335 -0
- package/skills/ai-agents/skill.md +392 -0
- package/skills/architecture/README.md +198 -0
- package/skills/architecture/examples.md +316 -0
- package/skills/architecture/skill.md +189 -0
- package/skills/design-architecture/README.md +107 -0
- package/skills/design-architecture/examples.md +84 -0
- package/skills/design-architecture/skill.md +192 -0
- package/skills/devops/README.md +177 -0
- package/skills/devops/examples.md +376 -0
- package/skills/devops/skill.md +210 -0
- package/skills/documentation/README.md +182 -0
- package/skills/documentation/examples.md +364 -0
- package/skills/documentation/skill.md +200 -0
- package/skills/performance/README.md +177 -0
- package/skills/performance/examples.md +376 -0
- package/skills/performance/skill.md +199 -0
- package/skills/qa/README.md +106 -0
- package/skills/qa/examples.md +84 -0
- package/skills/qa/skill.md +384 -0
- package/skills/security/README.md +108 -0
- package/skills/security/examples.md +85 -0
- package/skills/security/skill.md +223 -0
- package/skills/software-development/README.md +239 -0
- package/skills/software-development/assessment.md +0 -0
- package/skills/software-development/checklists.md +0 -0
- package/skills/software-development/examples.md +375 -0
- package/skills/software-development/prompts.md +0 -0
- package/skills/software-development/skill.md +390 -0
- package/skills/software-development/templates/README.md +7 -0
- package/skills/software-development/templates/api-development.md +0 -0
- package/skills/software-development/templates/bug-fix.md +0 -0
- package/skills/software-development/templates/code-review.md +0 -0
- package/skills/software-development/templates/feature-implementation.md +0 -0
- package/skills/software-development/templates/llm-integration.md +0 -0
- package/skills/software-development/templates/performance-review.md +0 -0
- package/skills/software-development/templates/security-review.md +0 -0
- package/skills/software-development/templates/test-generation.md +0 -0
- package/skills/software-development/tools.md +0 -0
- package/skills/software-development/workflows.md +0 -0
- package/skills/sre/README.md +107 -0
- package/skills/sre/examples.md +379 -0
- package/skills/sre/skill.md +256 -0
- package/skills/support-engineering/README.md +107 -0
- package/skills/support-engineering/examples.md +85 -0
- package/skills/support-engineering/skill.md +103 -0
|
@@ -0,0 +1,775 @@
|
|
|
1
|
+
# Examples
|
|
2
|
+
|
|
3
|
+
This document provides concrete examples of DevOps work, architecture patterns, and
|
|
4
|
+
implementation approaches that demonstrate the expected quality and approach.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Infrastructure as Code Example
|
|
9
|
+
|
|
10
|
+
### Example: Terraform Module for AWS VPC with High Availability
|
|
11
|
+
|
|
12
|
+
**Purpose:** Demonstrates IaC best practices for networking infrastructure.
|
|
13
|
+
|
|
14
|
+
```hcl
|
|
15
|
+
# modules/networking/vpc/main.tf
|
|
16
|
+
terraform {
|
|
17
|
+
required_version = ">= 1.0"
|
|
18
|
+
required_providers {
|
|
19
|
+
aws = {
|
|
20
|
+
source = "hashicorp/aws"
|
|
21
|
+
version = "~> 5.0"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
provider "aws" {
|
|
27
|
+
region = var.aws_region
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
# VPC with DNS enabled for service discovery
|
|
31
|
+
resource "aws_vpc" "main" {
|
|
32
|
+
cidr_block = var.vpc_cidr
|
|
33
|
+
enable_dns_hostnames = true
|
|
34
|
+
enable_dns_support = true
|
|
35
|
+
|
|
36
|
+
tags = merge(var.tags, {
|
|
37
|
+
Name = "${var.environment}-vpc"
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
# Internet Gateway for public subnets
|
|
42
|
+
resource "aws_internet_gateway" "main" {
|
|
43
|
+
vpc_id = aws_vpc.main.id
|
|
44
|
+
|
|
45
|
+
tags = merge(var.tags, {
|
|
46
|
+
Name = "${var.environment}-igw"
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
# Public subnets across multiple availability zones
|
|
51
|
+
resource "aws_subnet" "public" {
|
|
52
|
+
count = length(var.public_subnets)
|
|
53
|
+
vpc_id = aws_vpc.main.id
|
|
54
|
+
cidr_block = var.public_subnets[count.index]
|
|
55
|
+
availability_zone = data.aws_availability_zones.available.names[count.index]
|
|
56
|
+
map_public_ip_on_launch = true
|
|
57
|
+
|
|
58
|
+
tags = merge(var.tags, {
|
|
59
|
+
Name = "${var.environment}-public-subnet-${count.index + 1}"
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
# Private subnets across multiple availability zones
|
|
64
|
+
resource "aws_subnet" "private" {
|
|
65
|
+
count = length(var.private_subnets)
|
|
66
|
+
vpc_id = aws_vpc.main.id
|
|
67
|
+
cidr_block = var.private_subnets[count.index]
|
|
68
|
+
availability_zone = data.aws_availability_zones.available.names[count.index]
|
|
69
|
+
|
|
70
|
+
tags = merge(var.tags, {
|
|
71
|
+
Name = "${var.environment}-private-subnet-${count.index + 1}"
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
# NAT Gateway for private subnet egress
|
|
76
|
+
resource "aws_nat_gateway" "main" {
|
|
77
|
+
count = length(var.public_subnets)
|
|
78
|
+
allocation_id = aws_eip.nat[count.index].id
|
|
79
|
+
subnet_id = aws_subnet.public[count.index].id
|
|
80
|
+
|
|
81
|
+
# NAT Gateway needs Internet Gateway to exist first
|
|
82
|
+
depends_on = [aws_internet_gateway.main]
|
|
83
|
+
|
|
84
|
+
tags = merge(var.tags, {
|
|
85
|
+
Name = "${var.environment}-nat-${count.index + 1}"
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
# Elastic IP for NAT Gateway
|
|
90
|
+
resource "aws_eip" "nat" {
|
|
91
|
+
count = length(var.public_subnets)
|
|
92
|
+
domain = "vpc"
|
|
93
|
+
|
|
94
|
+
tags = merge(var.tags, {
|
|
95
|
+
Name = "${var.environment}-eip-nat-${count.index + 1}"
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
# Route tables for public subnets
|
|
100
|
+
resource "aws_route_table" "public" {
|
|
101
|
+
vpc_id = aws_vpc.main.id
|
|
102
|
+
|
|
103
|
+
route {
|
|
104
|
+
cidr_block = "0.0.0.0/0"
|
|
105
|
+
gateway_id = aws_internet_gateway.main.id
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
tags = merge(var.tags, {
|
|
109
|
+
Name = "${var.environment}-public-rt"
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
# Route table associations for public subnets
|
|
114
|
+
resource "aws_route_table_association" "public" {
|
|
115
|
+
count = length(aws_subnet.public)
|
|
116
|
+
subnet_id = aws_subnet.public[count.index].id
|
|
117
|
+
route_table_id = aws_route_table.public.id
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
# Route tables for private subnets (one per AZ for high availability)
|
|
121
|
+
resource "aws_route_table" "private" {
|
|
122
|
+
count = length(var.private_subnets)
|
|
123
|
+
vpc_id = aws_vpc.main.id
|
|
124
|
+
|
|
125
|
+
route {
|
|
126
|
+
cidr_block = "0.0.0.0/0"
|
|
127
|
+
nat_gateway_id = aws_nat_gateway.main[count.index].id
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
tags = merge(var.tags, {
|
|
131
|
+
Name = "${var.environment}-private-rt-${count.index + 1}"
|
|
132
|
+
})
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
# Route table associations for private subnets
|
|
136
|
+
resource "aws_route_table_association" "private" {
|
|
137
|
+
count = length(aws_subnet.private)
|
|
138
|
+
subnet_id = aws_subnet.private[count.index].id
|
|
139
|
+
route_table_id = aws_route_table.private[count.index].id
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
# Data source for available AZs
|
|
143
|
+
data "aws_availability_zones" "available" {
|
|
144
|
+
state = "available"
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
```hcl
|
|
149
|
+
# modules/networking/vpc/variables.tf
|
|
150
|
+
variable "aws_region" {
|
|
151
|
+
description = "AWS region for VPC"
|
|
152
|
+
type = string
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
variable "vpc_cidr" {
|
|
156
|
+
description = "CIDR block for VPC"
|
|
157
|
+
type = string
|
|
158
|
+
default = "10.0.0.0/16"
|
|
159
|
+
|
|
160
|
+
validation {
|
|
161
|
+
condition = can(cidrhost(var.vpc_cidr, 0))
|
|
162
|
+
error_message = "vpc_cidr must be a valid CIDR block."
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
variable "public_subnets" {
|
|
167
|
+
description = "CIDR blocks for public subnets (one per AZ)"
|
|
168
|
+
type = list(string)
|
|
169
|
+
default = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
|
|
170
|
+
|
|
171
|
+
validation {
|
|
172
|
+
condition = length(var.public_subnets) >= 2
|
|
173
|
+
error_message = "At least 2 public subnets required for high availability."
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
variable "private_subnets" {
|
|
178
|
+
description = "CIDR blocks for private subnets (one per AZ)"
|
|
179
|
+
type = list(string)
|
|
180
|
+
default = ["10.0.11.0/24", "10.0.12.0/24", "10.0.13.0/24"]
|
|
181
|
+
|
|
182
|
+
validation {
|
|
183
|
+
condition = length(var.private_subnets) >= 2
|
|
184
|
+
error_message = "At least 2 private subnets required for high availability."
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
variable "environment" {
|
|
189
|
+
description = "Environment name (dev, staging, prod)"
|
|
190
|
+
type = string
|
|
191
|
+
default = "dev"
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
variable "tags" {
|
|
195
|
+
description = "Common tags to apply to all resources"
|
|
196
|
+
type = map(string)
|
|
197
|
+
default = {}
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
```hcl
|
|
202
|
+
# modules/networking/vpc/outputs.tf
|
|
203
|
+
output "vpc_id" {
|
|
204
|
+
description = "VPC ID"
|
|
205
|
+
value = aws_vpc.main.id
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
output "public_subnet_ids" {
|
|
209
|
+
description = "Public subnet IDs"
|
|
210
|
+
value = aws_subnet.public[*].id
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
output "private_subnet_ids" {
|
|
214
|
+
description = "Private subnet IDs"
|
|
215
|
+
value = aws_subnet.private[*].id
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
output "nat_gateway_ips" {
|
|
219
|
+
description = "NAT Gateway Elastic IPs"
|
|
220
|
+
value = aws_eip.nat[*].public_ip
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
**Key Patterns Demonstrated:**
|
|
225
|
+
- Modular design for reusability
|
|
226
|
+
- High availability across multiple AZs
|
|
227
|
+
- Clear variable naming and documentation
|
|
228
|
+
- Input validation for correctness
|
|
229
|
+
- Resource tagging for cost tracking and management
|
|
230
|
+
- Proper dependency management
|
|
231
|
+
- Security-first (private subnets, NAT gateways)
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## Kubernetes Deployment Example
|
|
236
|
+
|
|
237
|
+
### Example: Helm Chart for Stateless Application with Auto-scaling
|
|
238
|
+
|
|
239
|
+
**Purpose:** Demonstrates Kubernetes deployment best practices with monitoring and high availability.
|
|
240
|
+
|
|
241
|
+
```yaml
|
|
242
|
+
# chart/templates/deployment.yaml
|
|
243
|
+
apiVersion: apps/v1
|
|
244
|
+
kind: Deployment
|
|
245
|
+
metadata:
|
|
246
|
+
name: {{ include "myapp.fullname" . }}
|
|
247
|
+
labels:
|
|
248
|
+
{{- include "myapp.labels" . | nindent 4 }}
|
|
249
|
+
spec:
|
|
250
|
+
replicas: {{ .Values.replicaCount }}
|
|
251
|
+
strategy:
|
|
252
|
+
type: RollingUpdate
|
|
253
|
+
rollingUpdate:
|
|
254
|
+
maxSurge: 1
|
|
255
|
+
maxUnavailable: 0
|
|
256
|
+
selector:
|
|
257
|
+
matchLabels:
|
|
258
|
+
{{- include "myapp.selectorLabels" . | nindent 6 }}
|
|
259
|
+
template:
|
|
260
|
+
metadata:
|
|
261
|
+
annotations:
|
|
262
|
+
prometheus.io/scrape: "true"
|
|
263
|
+
prometheus.io/port: "{{ .Values.service.metricsPort }}"
|
|
264
|
+
prometheus.io/path: "/metrics"
|
|
265
|
+
labels:
|
|
266
|
+
{{- include "myapp.selectorLabels" . | nindent 8 }}
|
|
267
|
+
spec:
|
|
268
|
+
securityContext:
|
|
269
|
+
runAsNonRoot: true
|
|
270
|
+
runAsUser: 1000
|
|
271
|
+
containers:
|
|
272
|
+
- name: {{ .Chart.Name }}
|
|
273
|
+
securityContext:
|
|
274
|
+
allowPrivilegeEscalation: false
|
|
275
|
+
readOnlyRootFilesystem: true
|
|
276
|
+
capabilities:
|
|
277
|
+
drop:
|
|
278
|
+
- ALL
|
|
279
|
+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
|
|
280
|
+
imagePullPolicy: {{ .Values.image.pullPolicy }}
|
|
281
|
+
ports:
|
|
282
|
+
- name: http
|
|
283
|
+
containerPort: {{ .Values.service.port }}
|
|
284
|
+
protocol: TCP
|
|
285
|
+
- name: metrics
|
|
286
|
+
containerPort: {{ .Values.service.metricsPort }}
|
|
287
|
+
protocol: TCP
|
|
288
|
+
|
|
289
|
+
# Health checks for kubernetes orchestration
|
|
290
|
+
livenessProbe:
|
|
291
|
+
httpGet:
|
|
292
|
+
path: /health/live
|
|
293
|
+
port: http
|
|
294
|
+
initialDelaySeconds: 30
|
|
295
|
+
periodSeconds: 10
|
|
296
|
+
timeoutSeconds: 5
|
|
297
|
+
failureThreshold: 3
|
|
298
|
+
|
|
299
|
+
readinessProbe:
|
|
300
|
+
httpGet:
|
|
301
|
+
path: /health/ready
|
|
302
|
+
port: http
|
|
303
|
+
initialDelaySeconds: 10
|
|
304
|
+
periodSeconds: 5
|
|
305
|
+
timeoutSeconds: 3
|
|
306
|
+
failureThreshold: 2
|
|
307
|
+
|
|
308
|
+
# Resource requests and limits
|
|
309
|
+
resources:
|
|
310
|
+
requests:
|
|
311
|
+
cpu: {{ .Values.resources.requests.cpu }}
|
|
312
|
+
memory: {{ .Values.resources.requests.memory }}
|
|
313
|
+
limits:
|
|
314
|
+
cpu: {{ .Values.resources.limits.cpu }}
|
|
315
|
+
memory: {{ .Values.resources.limits.memory }}
|
|
316
|
+
|
|
317
|
+
# Environment configuration from ConfigMap
|
|
318
|
+
env:
|
|
319
|
+
- name: LOG_LEVEL
|
|
320
|
+
valueFrom:
|
|
321
|
+
configMapKeyRef:
|
|
322
|
+
name: {{ include "myapp.fullname" . }}-config
|
|
323
|
+
key: log_level
|
|
324
|
+
|
|
325
|
+
# Secrets from Kubernetes secrets (never hardcoded)
|
|
326
|
+
- name: DATABASE_PASSWORD
|
|
327
|
+
valueFrom:
|
|
328
|
+
secretKeyRef:
|
|
329
|
+
name: {{ include "myapp.fullname" . }}-secrets
|
|
330
|
+
key: db_password
|
|
331
|
+
|
|
332
|
+
# Temporary volume for application logs
|
|
333
|
+
volumeMounts:
|
|
334
|
+
- name: tmp
|
|
335
|
+
mountPath: /tmp
|
|
336
|
+
- name: logs
|
|
337
|
+
mountPath: /var/log/app
|
|
338
|
+
|
|
339
|
+
volumes:
|
|
340
|
+
- name: tmp
|
|
341
|
+
emptyDir: {}
|
|
342
|
+
- name: logs
|
|
343
|
+
emptyDir: {}
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
```yaml
|
|
347
|
+
# chart/templates/hpa.yaml
|
|
348
|
+
apiVersion: autoscaling/v2
|
|
349
|
+
kind: HorizontalPodAutoscaler
|
|
350
|
+
metadata:
|
|
351
|
+
name: {{ include "myapp.fullname" . }}
|
|
352
|
+
labels:
|
|
353
|
+
{{- include "myapp.labels" . | nindent 4 }}
|
|
354
|
+
spec:
|
|
355
|
+
scaleTargetRef:
|
|
356
|
+
apiVersion: apps/v1
|
|
357
|
+
kind: Deployment
|
|
358
|
+
name: {{ include "myapp.fullname" . }}
|
|
359
|
+
minReplicas: {{ .Values.autoscaling.minReplicas }}
|
|
360
|
+
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
|
|
361
|
+
metrics:
|
|
362
|
+
- type: Resource
|
|
363
|
+
resource:
|
|
364
|
+
name: cpu
|
|
365
|
+
target:
|
|
366
|
+
type: Utilization
|
|
367
|
+
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
|
|
368
|
+
- type: Resource
|
|
369
|
+
resource:
|
|
370
|
+
name: memory
|
|
371
|
+
target:
|
|
372
|
+
type: Utilization
|
|
373
|
+
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
|
|
374
|
+
behavior:
|
|
375
|
+
scaleDown:
|
|
376
|
+
stabilizationWindowSeconds: 300
|
|
377
|
+
policies:
|
|
378
|
+
- type: Percent
|
|
379
|
+
value: 50
|
|
380
|
+
periodSeconds: 15
|
|
381
|
+
scaleUp:
|
|
382
|
+
stabilizationWindowSeconds: 60
|
|
383
|
+
policies:
|
|
384
|
+
- type: Percent
|
|
385
|
+
value: 100
|
|
386
|
+
periodSeconds: 15
|
|
387
|
+
- type: Pods
|
|
388
|
+
value: 2
|
|
389
|
+
periodSeconds: 15
|
|
390
|
+
selectPolicy: Max
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
```yaml
|
|
394
|
+
# chart/values.yaml
|
|
395
|
+
replicaCount: 3
|
|
396
|
+
|
|
397
|
+
image:
|
|
398
|
+
repository: myapp
|
|
399
|
+
tag: "1.0.0"
|
|
400
|
+
pullPolicy: IfNotPresent
|
|
401
|
+
|
|
402
|
+
service:
|
|
403
|
+
port: 8080
|
|
404
|
+
metricsPort: 9090
|
|
405
|
+
|
|
406
|
+
resources:
|
|
407
|
+
requests:
|
|
408
|
+
cpu: 100m
|
|
409
|
+
memory: 128Mi
|
|
410
|
+
limits:
|
|
411
|
+
cpu: 500m
|
|
412
|
+
memory: 512Mi
|
|
413
|
+
|
|
414
|
+
autoscaling:
|
|
415
|
+
enabled: true
|
|
416
|
+
minReplicas: 3
|
|
417
|
+
maxReplicas: 10
|
|
418
|
+
targetCPUUtilizationPercentage: 70
|
|
419
|
+
targetMemoryUtilizationPercentage: 80
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
**Key Patterns Demonstrated:**
|
|
423
|
+
- Security best practices (non-root user, read-only filesystem, dropped capabilities)
|
|
424
|
+
- Health checks for self-healing
|
|
425
|
+
- Resource requests/limits for reliability
|
|
426
|
+
- Horizontal pod autoscaling based on metrics
|
|
427
|
+
- Environment variables from ConfigMaps
|
|
428
|
+
- Secrets management (not hardcoded)
|
|
429
|
+
- Monitoring annotations for Prometheus integration
|
|
430
|
+
- Rolling update strategy
|
|
431
|
+
|
|
432
|
+
---
|
|
433
|
+
|
|
434
|
+
## CI/CD Pipeline Example
|
|
435
|
+
|
|
436
|
+
### Example: GitHub Actions Pipeline
|
|
437
|
+
|
|
438
|
+
**Purpose:** Demonstrates automated testing, security scanning, and deployment workflow.
|
|
439
|
+
|
|
440
|
+
```yaml
|
|
441
|
+
# .github/workflows/deploy.yml
|
|
442
|
+
name: Build, Test, and Deploy
|
|
443
|
+
|
|
444
|
+
on:
|
|
445
|
+
push:
|
|
446
|
+
branches:
|
|
447
|
+
- main
|
|
448
|
+
- develop
|
|
449
|
+
pull_request:
|
|
450
|
+
branches:
|
|
451
|
+
- main
|
|
452
|
+
|
|
453
|
+
env:
|
|
454
|
+
REGISTRY: ghcr.io
|
|
455
|
+
IMAGE_NAME: ${{ github.repository }}
|
|
456
|
+
|
|
457
|
+
jobs:
|
|
458
|
+
build:
|
|
459
|
+
runs-on: ubuntu-latest
|
|
460
|
+
permissions:
|
|
461
|
+
contents: read
|
|
462
|
+
packages: write
|
|
463
|
+
|
|
464
|
+
steps:
|
|
465
|
+
- uses: actions/checkout@v4
|
|
466
|
+
|
|
467
|
+
- name: Set up Docker Buildx
|
|
468
|
+
uses: docker/setup-buildx-action@v3
|
|
469
|
+
|
|
470
|
+
- name: Log in to Container Registry
|
|
471
|
+
if: github.event_name != 'pull_request'
|
|
472
|
+
uses: docker/login-action@v3
|
|
473
|
+
with:
|
|
474
|
+
registry: ${{ env.REGISTRY }}
|
|
475
|
+
username: ${{ github.actor }}
|
|
476
|
+
password: ${{ secrets.GITHUB_TOKEN }}
|
|
477
|
+
|
|
478
|
+
- name: Extract metadata
|
|
479
|
+
id: meta
|
|
480
|
+
uses: docker/metadata-action@v5
|
|
481
|
+
with:
|
|
482
|
+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
483
|
+
tags: |
|
|
484
|
+
type=ref,event=branch
|
|
485
|
+
type=semver,pattern={{version}}
|
|
486
|
+
type=sha,prefix={{branch}}-
|
|
487
|
+
|
|
488
|
+
- name: Build and push Docker image
|
|
489
|
+
uses: docker/build-push-action@v5
|
|
490
|
+
with:
|
|
491
|
+
context: .
|
|
492
|
+
push: ${{ github.event_name != 'pull_request' }}
|
|
493
|
+
tags: ${{ steps.meta.outputs.tags }}
|
|
494
|
+
labels: ${{ steps.meta.outputs.labels }}
|
|
495
|
+
cache-from: type=gha
|
|
496
|
+
cache-to: type=gha,mode=max
|
|
497
|
+
|
|
498
|
+
test:
|
|
499
|
+
runs-on: ubuntu-latest
|
|
500
|
+
needs: build
|
|
501
|
+
|
|
502
|
+
steps:
|
|
503
|
+
- uses: actions/checkout@v4
|
|
504
|
+
|
|
505
|
+
- name: Set up Go
|
|
506
|
+
uses: actions/setup-go@v4
|
|
507
|
+
with:
|
|
508
|
+
go-version: '1.21'
|
|
509
|
+
cache: 'go'
|
|
510
|
+
|
|
511
|
+
- name: Run unit tests
|
|
512
|
+
run: go test -v -race -coverprofile=coverage.out ./...
|
|
513
|
+
|
|
514
|
+
- name: Upload coverage to Codecov
|
|
515
|
+
uses: codecov/codecov-action@v3
|
|
516
|
+
with:
|
|
517
|
+
files: ./coverage.out
|
|
518
|
+
flags: unittests
|
|
519
|
+
fail_ci_if_error: true
|
|
520
|
+
|
|
521
|
+
security-scan:
|
|
522
|
+
runs-on: ubuntu-latest
|
|
523
|
+
needs: build
|
|
524
|
+
|
|
525
|
+
steps:
|
|
526
|
+
- uses: actions/checkout@v4
|
|
527
|
+
|
|
528
|
+
- name: Run Trivy vulnerability scanner
|
|
529
|
+
uses: aquasecurity/trivy-action@master
|
|
530
|
+
with:
|
|
531
|
+
scan-type: 'fs'
|
|
532
|
+
scan-ref: '.'
|
|
533
|
+
format: 'sarif'
|
|
534
|
+
output: 'trivy-results.sarif'
|
|
535
|
+
|
|
536
|
+
- name: Upload Trivy results to GitHub Security tab
|
|
537
|
+
uses: github/codeql-action/upload-sarif@v3
|
|
538
|
+
with:
|
|
539
|
+
sarif_file: 'trivy-results.sarif'
|
|
540
|
+
|
|
541
|
+
- name: Check for high severity vulnerabilities
|
|
542
|
+
run: |
|
|
543
|
+
if grep -q "HIGH\|CRITICAL" trivy-results.sarif; then
|
|
544
|
+
echo "High/Critical vulnerabilities found"
|
|
545
|
+
exit 1
|
|
546
|
+
fi
|
|
547
|
+
|
|
548
|
+
deploy-staging:
|
|
549
|
+
runs-on: ubuntu-latest
|
|
550
|
+
needs: [test, security-scan]
|
|
551
|
+
if: github.ref == 'refs/heads/develop' && github.event_name == 'push'
|
|
552
|
+
|
|
553
|
+
steps:
|
|
554
|
+
- uses: actions/checkout@v4
|
|
555
|
+
|
|
556
|
+
- name: Deploy to staging
|
|
557
|
+
run: |
|
|
558
|
+
echo "Deploying to staging environment..."
|
|
559
|
+
# Use kubectl or deployment tool to deploy
|
|
560
|
+
kubectl set image deployment/myapp myapp=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} \
|
|
561
|
+
-n staging \
|
|
562
|
+
--record
|
|
563
|
+
kubectl rollout status deployment/myapp -n staging
|
|
564
|
+
|
|
565
|
+
deploy-production:
|
|
566
|
+
runs-on: ubuntu-latest
|
|
567
|
+
needs: [test, security-scan]
|
|
568
|
+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
|
|
569
|
+
environment:
|
|
570
|
+
name: production
|
|
571
|
+
url: https://myapp.example.com
|
|
572
|
+
|
|
573
|
+
steps:
|
|
574
|
+
- uses: actions/checkout@v4
|
|
575
|
+
|
|
576
|
+
- name: Deploy to production
|
|
577
|
+
run: |
|
|
578
|
+
echo "Deploying to production environment..."
|
|
579
|
+
kubectl set image deployment/myapp myapp=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} \
|
|
580
|
+
-n production \
|
|
581
|
+
--record
|
|
582
|
+
kubectl rollout status deployment/myapp -n production
|
|
583
|
+
|
|
584
|
+
- name: Run smoke tests
|
|
585
|
+
run: |
|
|
586
|
+
./scripts/smoke-tests.sh https://myapp.example.com
|
|
587
|
+
|
|
588
|
+
- name: Notify deployment
|
|
589
|
+
if: always()
|
|
590
|
+
uses: 8398a7/action-slack@v3
|
|
591
|
+
with:
|
|
592
|
+
status: ${{ job.status }}
|
|
593
|
+
text: "Production deployment ${{ job.status }}"
|
|
594
|
+
webhook_url: ${{ secrets.SLACK_WEBHOOK }}
|
|
595
|
+
```
|
|
596
|
+
|
|
597
|
+
**Key Patterns Demonstrated:**
|
|
598
|
+
- Automated build pipeline with Docker
|
|
599
|
+
- Unit tests with coverage reporting
|
|
600
|
+
- Security scanning (Trivy, dependency checking)
|
|
601
|
+
- Separate staging and production deployments
|
|
602
|
+
- Approval gates for production (environment)
|
|
603
|
+
- Smoke tests after deployment
|
|
604
|
+
- Notifications for team awareness
|
|
605
|
+
- Proper secret handling (GitHub secrets)
|
|
606
|
+
|
|
607
|
+
---
|
|
608
|
+
|
|
609
|
+
## Monitoring & Alerting Example
|
|
610
|
+
|
|
611
|
+
### Example: Prometheus + Grafana Dashboard
|
|
612
|
+
|
|
613
|
+
**Purpose:** Demonstrates observability setup with meaningful metrics and alerting.
|
|
614
|
+
|
|
615
|
+
```yaml
|
|
616
|
+
# prometheus-values.yaml
|
|
617
|
+
prometheus:
|
|
618
|
+
prometheusSpec:
|
|
619
|
+
retention: 30d
|
|
620
|
+
|
|
621
|
+
# Service monitors for scraping targets
|
|
622
|
+
serviceMonitorSelectorNilUsesHelmValues: false
|
|
623
|
+
podMonitorSelectorNilUsesHelmValues: false
|
|
624
|
+
|
|
625
|
+
# Persistent storage
|
|
626
|
+
storageSpec:
|
|
627
|
+
volumeClaimTemplate:
|
|
628
|
+
spec:
|
|
629
|
+
accessModes: ["ReadWriteOnce"]
|
|
630
|
+
resources:
|
|
631
|
+
requests:
|
|
632
|
+
storage: 50Gi
|
|
633
|
+
|
|
634
|
+
# Resource requests
|
|
635
|
+
resources:
|
|
636
|
+
requests:
|
|
637
|
+
cpu: 500m
|
|
638
|
+
memory: 2Gi
|
|
639
|
+
limits:
|
|
640
|
+
cpu: 2
|
|
641
|
+
memory: 4Gi
|
|
642
|
+
|
|
643
|
+
# Alert rules
|
|
644
|
+
alertmanager:
|
|
645
|
+
enabled: true
|
|
646
|
+
config:
|
|
647
|
+
route:
|
|
648
|
+
group_by: ['alertname', 'cluster']
|
|
649
|
+
group_wait: 10s
|
|
650
|
+
group_interval: 10s
|
|
651
|
+
repeat_interval: 12h
|
|
652
|
+
receiver: 'default'
|
|
653
|
+
routes:
|
|
654
|
+
- match:
|
|
655
|
+
severity: critical
|
|
656
|
+
receiver: 'critical'
|
|
657
|
+
continue: true
|
|
658
|
+
- match:
|
|
659
|
+
severity: warning
|
|
660
|
+
receiver: 'warning'
|
|
661
|
+
|
|
662
|
+
receivers:
|
|
663
|
+
- name: 'default'
|
|
664
|
+
slack_configs:
|
|
665
|
+
- api_url: '${SLACK_WEBHOOK_URL}'
|
|
666
|
+
channel: '#alerts'
|
|
667
|
+
|
|
668
|
+
- name: 'critical'
|
|
669
|
+
pagerduty_configs:
|
|
670
|
+
- service_key: '${PAGERDUTY_KEY}'
|
|
671
|
+
slack_configs:
|
|
672
|
+
- api_url: '${SLACK_WEBHOOK_URL}'
|
|
673
|
+
channel: '#critical-alerts'
|
|
674
|
+
|
|
675
|
+
# Grafana dashboards
|
|
676
|
+
grafana:
|
|
677
|
+
persistence:
|
|
678
|
+
enabled: true
|
|
679
|
+
size: 10Gi
|
|
680
|
+
|
|
681
|
+
datasources:
|
|
682
|
+
datasources.yaml:
|
|
683
|
+
apiVersion: 1
|
|
684
|
+
datasources:
|
|
685
|
+
- name: Prometheus
|
|
686
|
+
type: prometheus
|
|
687
|
+
url: http://prometheus-operated:9090
|
|
688
|
+
```
|
|
689
|
+
|
|
690
|
+
```yaml
|
|
691
|
+
# prometheus-rules.yaml
|
|
692
|
+
groups:
|
|
693
|
+
- name: kubernetes.rules
|
|
694
|
+
interval: 30s
|
|
695
|
+
rules:
|
|
696
|
+
|
|
697
|
+
# Availability SLO alerts
|
|
698
|
+
- alert: ServiceUnavailable
|
|
699
|
+
expr: up{job="myapp"} == 0
|
|
700
|
+
for: 1m
|
|
701
|
+
labels:
|
|
702
|
+
severity: critical
|
|
703
|
+
annotations:
|
|
704
|
+
summary: "Service {{ $labels.instance }} is down"
|
|
705
|
+
description: "Service has been down for more than 1 minute"
|
|
706
|
+
|
|
707
|
+
# Resource utilization alerts
|
|
708
|
+
- alert: HighCPUUsage
|
|
709
|
+
expr: |
|
|
710
|
+
(sum(rate(container_cpu_usage_seconds_total{pod=~"myapp-.*"}[5m])) by (pod)
|
|
711
|
+
/ sum(container_spec_cpu_quota{pod=~"myapp-.*"} / container_spec_cpu_period{pod=~"myapp-.*"}) by (pod))
|
|
712
|
+
> 0.8
|
|
713
|
+
for: 5m
|
|
714
|
+
labels:
|
|
715
|
+
severity: warning
|
|
716
|
+
annotations:
|
|
717
|
+
summary: "High CPU usage for pod {{ $labels.pod }}"
|
|
718
|
+
|
|
719
|
+
- alert: HighMemoryUsage
|
|
720
|
+
expr: |
|
|
721
|
+
(sum(container_memory_usage_bytes{pod=~"myapp-.*"}) by (pod)
|
|
722
|
+
/ sum(container_spec_memory_limit_bytes{pod=~"myapp-.*"}) by (pod))
|
|
723
|
+
> 0.8
|
|
724
|
+
for: 5m
|
|
725
|
+
labels:
|
|
726
|
+
severity: warning
|
|
727
|
+
annotations:
|
|
728
|
+
summary: "High memory usage for pod {{ $labels.pod }}"
|
|
729
|
+
|
|
730
|
+
# Disk space alerts
|
|
731
|
+
- alert: DiskSpaceLow
|
|
732
|
+
expr: |
|
|
733
|
+
(node_filesystem_avail_bytes{mountpoint="/"} / node_filesystem_size_bytes{mountpoint="/"})
|
|
734
|
+
< 0.1
|
|
735
|
+
for: 5m
|
|
736
|
+
labels:
|
|
737
|
+
severity: critical
|
|
738
|
+
annotations:
|
|
739
|
+
summary: "Disk space low on {{ $labels.instance }}"
|
|
740
|
+
|
|
741
|
+
# Application error rate alerts
|
|
742
|
+
- alert: HighErrorRate
|
|
743
|
+
expr: |
|
|
744
|
+
(sum(rate(http_requests_total{status=~"5.."}[5m])) by (job)
|
|
745
|
+
/ sum(rate(http_requests_total[5m])) by (job))
|
|
746
|
+
> 0.05
|
|
747
|
+
for: 5m
|
|
748
|
+
labels:
|
|
749
|
+
severity: warning
|
|
750
|
+
annotations:
|
|
751
|
+
summary: "High error rate for {{ $labels.job }}"
|
|
752
|
+
```
|
|
753
|
+
|
|
754
|
+
**Key Patterns Demonstrated:**
|
|
755
|
+
- Long-term metrics retention for capacity planning
|
|
756
|
+
- Service monitoring with auto-discovery
|
|
757
|
+
- Persistent storage for metrics
|
|
758
|
+
- Multi-channel alerting (Slack, PagerDuty)
|
|
759
|
+
- SLO-focused alerts (availability, latency, error rates)
|
|
760
|
+
- Resource utilization alerts
|
|
761
|
+
- Meaningful alert thresholds and durations
|
|
762
|
+
- Clear alert messages with context
|
|
763
|
+
|
|
764
|
+
---
|
|
765
|
+
|
|
766
|
+
## Summary
|
|
767
|
+
|
|
768
|
+
These examples demonstrate:
|
|
769
|
+
|
|
770
|
+
1. **Infrastructure as Code:** Modular, reusable, well-documented, secure
|
|
771
|
+
2. **Kubernetes Deployments:** High availability, auto-scaling, security-first
|
|
772
|
+
3. **CI/CD Pipelines:** Automated testing, security scanning, safe deployments
|
|
773
|
+
4. **Monitoring:** SLO-focused alerts, meaningful metrics, multi-channel notifications
|
|
774
|
+
|
|
775
|
+
Use these as templates when designing new infrastructure, deployments, or monitoring systems.
|