Skip to content

Latest commit

 

History

History
174 lines (133 loc) · 3.8 KB

File metadata and controls

174 lines (133 loc) · 3.8 KB

12. Deployment Strategy

Status

Proposed

Context

CodeFlow needs a reliable, repeatable deployment process that supports:

  • Multiple environments (dev, staging, production)
  • Zero-downtime deployments
  • Rollback capabilities
  • Environment-specific configurations

Decision

We will implement a GitOps-based deployment strategy using the following components:

1. Infrastructure as Code (IaC)

# Example: Terraform module for ECS
module "codeflow_service" {
  source  = "terraform-aws-modules/ecs/aws//modules/service"
  version = "~> 5.0"

  name          = "codeflow-${var.environment}"
  cluster_arn   = aws_ecs_cluster.main.arn
  desired_count = var.desired_count

  container_definitions = {
    CodeFlow = {
      image = "${aws_ecr_repository.codeflow.repository_url}:${var.image_tag}"
      port_mappings = [
        {
          containerPort = 8000
          hostPort      = 8000
          protocol      = "tcp"
        }
      ]
      environment = [
        {
          name  = "ENVIRONMENT"
          value = var.environment
        },
        {
          name  = "LOG_LEVEL"
          value = var.log_level
        }
      ]
      secrets = [
        {
          name      = "DATABASE_URL"
          valueFrom = aws_ssm_parameter.database_url.arn
        }
      ]
    }
  }
}

2. CI/CD Pipeline

# .github/workflows/deploy.yml
name: Deploy

on:
  push:
    branches:
      - main
      - "release/**"
  workflow_dispatch:

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    environment: production

    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2

      - name: Login to ECR
        uses: aws-actions/amazon-ecr-login@v1

      - name: Build and push
        uses: docker/build-push-action@v4
        with:
          context: .
          push: true
          tags: |
            ${{ steps.login-ecr.outputs.registry }}/CodeFlow:${{ github.sha }}
            ${{ steps.login-ecr.outputs.registry }}/CodeFlow:latest

      - name: Deploy to ECS
        uses: aws-actions/amazon-ecs-deploy-task-definition@v1
        with:
          task-definition: task-definition.json
          service: codeflow-service
          cluster: codeflow-cluster
          wait-for-service-stability: true

3. Environment Strategy

3.1 Development

  • Deployment: On every push to feature branches
  • Infrastructure: Local Docker Compose or ECS Fargate
  • Data: Ephemeral or shared test database
  • Access: Public with authentication

3.2 Staging

  • Deployment: On merge to staging branch
  • Infrastructure: Same as production
  • Data: Anonymized production data
  • Access: Internal team only

3.3 Production

  • Deployment: Manual or automated from main branch
  • Infrastructure: Multi-AZ ECS Fargate
  • Data: Production database with backups
  • Access: Public with strict IAM policies

4. Rollback Strategy

  1. Automated Rollback

    • Health check failures
    • High error rates
    • Performance degradation
  2. Manual Rollback

    • Via CI/CD pipeline
    • Previous version promotion
    • Database rollback if needed
  3. Blue/Green Deployment

    • Zero-downtime deployments
    • Instant rollback capability
    • Traffic shifting between versions

Consequences

Positive

  • Consistent deployments
  • Reduced human error
  • Faster recovery from issues
  • Better change tracking

Negative

  • Initial setup complexity
  • Learning curve for team
  • Infrastructure overhead

Neutral

  • Documentation requirements
  • Training needs

Related Decisions