$npx -y skills add tranhieutt/software_development_department --skill devops-deployDesigns and executes CI/CD pipelines, GitOps workflows, deployment automation, and cloud infrastructure deployment including Docker, AWS Lambda, SAM, Terraform, and GitHub Actions. Use when building or improving CI/CD pipelines, containerizing applications, creating deployment ru
| 1 | # DevOps Deploy |
| 2 | |
| 3 | ## Production checklist (always verify) |
| 4 | |
| 5 | - [ ] Env vars via Secrets Manager — never hardcoded |
| 6 | - [ ] Health check endpoint responding |
| 7 | - [ ] Structured JSON logs with `request_id` |
| 8 | - [ ] Rate limiting configured |
| 9 | - [ ] CORS restricted to authorized domains |
| 10 | - [ ] Lambda timeout appropriate (10–30s) |
| 11 | - [ ] CloudWatch alarms for errors and latency |
| 12 | - [ ] Rollback plan documented |
| 13 | - [ ] Load test before launch |
| 14 | |
| 15 | ## Docker: multi-stage Python |
| 16 | |
| 17 | ```dockerfile |
| 18 | FROM python:3.11-slim AS builder |
| 19 | WORKDIR /app |
| 20 | COPY requirements.txt . |
| 21 | RUN pip install --no-cache-dir --user -r requirements.txt |
| 22 | |
| 23 | FROM python:3.11-slim |
| 24 | WORKDIR /app |
| 25 | COPY --from=builder /root/.local /root/.local |
| 26 | COPY . . |
| 27 | ENV PATH=/root/.local/bin:$PATH |
| 28 | ENV PYTHONUNBUFFERED=1 |
| 29 | EXPOSE 8000 |
| 30 | HEALTHCHECK --interval=30s --timeout=3s CMD curl -f http://localhost:8000/health || exit 1 |
| 31 | CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] |
| 32 | ``` |
| 33 | |
| 34 | ## Docker Compose (local dev) |
| 35 | |
| 36 | ```yaml |
| 37 | services: |
| 38 | app: |
| 39 | build: . |
| 40 | ports: ["8000:8000"] |
| 41 | environment: |
| 42 | - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY} |
| 43 | volumes: |
| 44 | - .:/app |
| 45 | depends_on: [db, redis] |
| 46 | db: |
| 47 | image: postgres:15 |
| 48 | environment: |
| 49 | POSTGRES_DB: app |
| 50 | POSTGRES_USER: app |
| 51 | POSTGRES_PASSWORD: ${DB_PASSWORD} |
| 52 | volumes: |
| 53 | - pgdata:/var/lib/postgresql/data |
| 54 | redis: |
| 55 | image: redis:7-alpine |
| 56 | volumes: |
| 57 | pgdata: |
| 58 | ``` |
| 59 | |
| 60 | ## SAM template (Lambda + DynamoDB) |
| 61 | |
| 62 | ```yaml |
| 63 | AWSTemplateFormatVersion: '2010-09-09' |
| 64 | Transform: AWS::Serverless-2016-10-31 |
| 65 | |
| 66 | Globals: |
| 67 | Function: |
| 68 | Timeout: 30 |
| 69 | Runtime: python3.11 |
| 70 | Environment: |
| 71 | Variables: |
| 72 | DYNAMODB_TABLE: !Ref AppTable |
| 73 | |
| 74 | Resources: |
| 75 | AppFunction: |
| 76 | Type: AWS::Serverless::Function |
| 77 | Properties: |
| 78 | CodeUri: src/ |
| 79 | Handler: lambda_function.handler |
| 80 | MemorySize: 512 |
| 81 | Policies: |
| 82 | - DynamoDBCrudPolicy: |
| 83 | TableName: !Ref AppTable |
| 84 | |
| 85 | AppTable: |
| 86 | Type: AWS::DynamoDB::Table |
| 87 | Properties: |
| 88 | BillingMode: PAY_PER_REQUEST |
| 89 | AttributeDefinitions: |
| 90 | - AttributeName: userId |
| 91 | AttributeType: S |
| 92 | KeySchema: |
| 93 | - AttributeName: userId |
| 94 | KeyType: HASH |
| 95 | TimeToLiveSpecification: |
| 96 | AttributeName: ttl |
| 97 | Enabled: true |
| 98 | ``` |
| 99 | |
| 100 | ```bash |
| 101 | # SAM commands |
| 102 | sam build |
| 103 | sam deploy --guided # first time (creates samconfig.toml) |
| 104 | sam deploy # subsequent |
| 105 | sam deploy --no-confirm-changeset --no-fail-on-empty-changeset |
| 106 | sam logs -n AppFunction --tail |
| 107 | ``` |
| 108 | |
| 109 | ## GitHub Actions: test + security + deploy |
| 110 | |
| 111 | ```yaml |
| 112 | name: Deploy |
| 113 | on: |
| 114 | push: |
| 115 | branches: [main] |
| 116 | |
| 117 | jobs: |
| 118 | test: |
| 119 | runs-on: ubuntu-latest |
| 120 | steps: |
| 121 | - uses: actions/checkout@v4 |
| 122 | - uses: actions/setup-python@v5 |
| 123 | with: { python-version: "3.11" } |
| 124 | - run: pip install -r requirements.txt |
| 125 | - run: pytest tests/ -v --cov=src --cov-report=xml |
| 126 | |
| 127 | security: |
| 128 | runs-on: ubuntu-latest |
| 129 | steps: |
| 130 | - uses: actions/checkout@v4 |
| 131 | - run: pip install bandit safety |
| 132 | - run: bandit -r src/ -ll |
| 133 | - run: safety check -r requirements.txt |
| 134 | |
| 135 | deploy: |
| 136 | needs: [test, security] |
| 137 | if: github.ref == 'refs/heads/main' |
| 138 | runs-on: ubuntu-latest |
| 139 | steps: |
| 140 | - uses: actions/checkout@v4 |
| 141 | - uses: aws-actions/setup-sam@v2 |
| 142 | - uses: aws-actions/configure-aws-credentials@v4 |
| 143 | with: |
| 144 | aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 145 | aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 146 | aws-region: us-east-1 |
| 147 | - run: sam build |
| 148 | - run: sam deploy --no-confirm-changeset |
| 149 | ``` |
| 150 | |
| 151 | ## Health check endpoint (FastAPI) |
| 152 | |
| 153 | ```python |
| 154 | import time, os |
| 155 | from fastapi import FastAPI |
| 156 | |
| 157 | app = FastAPI() |
| 158 | START_TIME = time.time() |
| 159 | |
| 160 | @app.get("/health") |
| 161 | async def health(): |
| 162 | return { |
| 163 | "status": "healthy", |
| 164 | "uptime_seconds": time.time() - START_TIME, |
| 165 | "version": os.environ.get("APP_VERSION", "unknown"), |
| 166 | } |
| 167 | ``` |
| 168 | |
| 169 | ## Pipeline Design |
| 170 | |
| 171 | ### Standard Pipeline Stages |
| 172 | |
| 173 | ``` |
| 174 | [Build] -> [Test] -> [Security Scan] -> [Package] -> [Deploy Staging] -> [Integration Test] -> [Approval] -> [Deploy Prod] -> [Verify] |
| 175 | ``` |
| 176 | |
| 177 | | Stage | Actions | Failure Policy | |
| 178 | |-------|---------|----------------| |
| 179 | | Build | Co |