Skip to content

Instantly share code, notes, and snippets.

@nejdetkadir
Created January 3, 2025 07:59
Show Gist options
  • Save nejdetkadir/703e7d7154c6f3c04c147f556fc0634c to your computer and use it in GitHub Desktop.
Save nejdetkadir/703e7d7154c6f3c04c147f556fc0634c to your computer and use it in GitHub Desktop.

Application Deployment Flow

This document outlines the deployment flows for both staging and production environments.

Staging Deployment Flow (Push to Main Branch)

graph TD
    A[Push to Main Branch] --> B[Build Application]
    B --> C[Run Tests]
    C --> D{Tests Pass?}
    D -->|Yes| E[Configure AWS Credentials]
    D -->|No| F[Pipeline Fails]
    E --> G[Build Docker Image]
    G --> H[Push to AWS ECR]
    H --> I[Create New Task Definition]
    I --> J[Update ECS Service]
    J --> K[Start Rolling Update]
    K --> L[Load Balancer Health Check]
    L --> M{Health Check Pass?}
    M -->|Yes| N[Replace Old Tasks]
    M -->|No| O[Rollback to Previous Version]
    N --> P[Application Live on Staging]
Loading

Production Deployment Flow (Release Published)

graph TD
    A[Release Published] --> B[Build Application]
    B --> C[Run Tests]
    C --> D{Tests Pass?}
    D -->|Yes| E[Push to AWS ECR]
    D -->|No| F[Pipeline Fails]
    E --> G[Configure AWS Production Credentials]
    G --> H[Create New Task Definition]
    H --> I[Update ECS Service]
    I --> J[Start Rolling Update]
    J --> K[Load Balancer Health Check]
    K --> L{Health Check Pass?}
    L -->|Yes| M[Replace Old Tasks]
    L -->|No| N[Rollback to Previous Version]
    M --> O[Application Live on Production]
Loading

Deployment Process Details

Staging Environment

  1. Developer pushes code to the main branch
  2. GitHub Actions triggers the staging pipeline
  3. Application is built using .NET 8.0
  4. All tests are executed
  5. On successful tests:
    • AWS staging credentials are configured
    • Docker image is built
    • Image is pushed to AWS ECR staging registry
  6. Post-ECR Deployment Process:
    • New task definition is created in ECS with the latest image
    • ECS service is updated with the new task definition
    • Rolling update process begins:
      • New tasks are started with the new task definition
      • Application Load Balancer starts health checks on new tasks
      • Health check endpoint is monitored for successful responses
      • If health checks pass, old tasks are gradually terminated
      • If health checks fail, automatic rollback to previous version
    • Load Balancer continues routing traffic to healthy tasks
    • Deployment is considered complete when all tasks are replaced

Production Environment

  1. A new release is published
  2. GitHub Actions triggers the production pipeline
  3. Application is built using .NET 8.0
  4. All tests are executed
  5. On successful tests:
    • AWS production credentials are configured
    • Docker image is built
    • Image is pushed to AWS ECR production registry
  6. Post-ECR Deployment Process:
    • New task definition is created in ECS with the latest image
    • ECS service is updated with the new task definition
    • Rolling update process begins:
      • New tasks are started with the new task definition
      • Application Load Balancer starts health checks on new tasks
      • Health check endpoint is monitored for successful responses
      • If health checks pass, old tasks are gradually terminated
      • If health checks fail, automatic rollback to previous version
    • Load Balancer continues routing traffic to healthy tasks
    • Deployment is considered complete when all tasks are replaced

Infrastructure Components

  • AWS ECR (Elastic Container Registry) - For storing Docker images
  • AWS ECS (Elastic Container Service) - For running containerized applications
  • GitHub Actions - CI/CD pipeline orchestration
  • Application Load Balancer (ALB):
    • Performs health checks on container instances
    • Routes traffic to healthy tasks
    • Supports rolling updates with zero downtime
  • ECS Task Definition:
    • Defines container specifications
    • Configures health check parameters
    • Specifies resource requirements
  • ECS Service:
    • Manages task lifecycle
    • Handles rolling updates
    • Maintains desired task count
    • Integrates with Load Balancer

Health Check Configuration

  • Path: /health
  • Protocol: HTTPS
  • Healthy threshold: 3 consecutive successes
  • Unhealthy threshold: 2 consecutive failures
  • Timeout: 5 seconds
  • Interval: 30 seconds
  • Success codes: 200-299
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment