Skip to main content

Overview

The Risk Legion backend is deployed to AWS EC2 using Docker containers, with automated CI/CD via GitHub Actions.

Architecture

CI/CD Pipeline

The pipeline (.github/workflows/backend-deploy.yml) runs on pushes to main and staging:

Jobs

  1. Setup - Prepare environment
  2. Test - Lint, type-check, run tests
  3. Build - Build and push Docker image to GHCR
  4. Deploy - SSH to EC2 and deploy container

Triggers

Docker Configuration

Dockerfile

docker-compose.yml

Deployment Steps

1. EC2 Instance Setup

2. Configure nginx

Enable the site:

3. SSL Certificate

4. Deploy Container

GitHub Actions Configuration

Required Secrets

Environment-Specific Deployment

Health Verification

After deployment, verify health:

Rollback Procedure

Quick Rollback

Via GitHub Actions

Re-run a previous successful deployment:
  1. Go to Actions → workflow runs
  2. Find successful deployment
  3. Click “Re-run all jobs”

Scaling

Horizontal Scaling

Add more EC2 instances behind a load balancer:
  1. Create Application Load Balancer (ALB)
  2. Create target group
  3. Add EC2 instances to target group
  4. Point domain to ALB

Vertical Scaling

Upgrade EC2 instance size:

Troubleshooting

  • Container might not be running
  • Check if port 8000 is accessible
  • Verify nginx configuration
  • Check GitHub Actions logs
  • Verify EC2 SSH connectivity
  • Check disk space on EC2
  • Check container resource usage: docker stats
  • Review slow queries in logs
  • Consider scaling up instance