CI/CD Pipeline

Overview

CI/CD (Continuous Integration/Continuous Deployment) automates the build, test, and deploy process. This section guides you through setting up CI/CD for Lexi.

πŸ“Έ TODO: Add CI/CD pipeline diagram

CI/CD Architecture

Developer β†’ Git Push
    ↓
GitHub/GitLab
    ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                                   β”‚
β–Ό                                   β–Ό
GitHub Actions                  Amplify
β”‚                                   β”‚
β”œβ”€ Backend Workflow                 β”œβ”€ Auto-detect push
β”‚  β”œβ”€ Checkout code                 β”œβ”€ Build Next.js
β”‚  β”œβ”€ Setup Python                  β”œβ”€ Deploy to CDN
β”‚  β”œβ”€ SAM Build                     └─ Invalidate cache
β”‚  └─ SAM Deploy                    
β”‚                                   
└─ Frontend Workflow                
   β”œβ”€ Checkout code                 
   β”œβ”€ Setup Node.js                 
   β”œβ”€ Build Next.js                 
   └─ Trigger Amplify               

CI/CD Content

CI/CD is divided into 3 main parts:

  1. GitHub Actions - CI/CD automation

    • Setup GitHub repository
    • Configure secrets
    • Create workflows
    • Branch protection
    • Monitoring
  2. SAM Deployment - Backend deployment

    • SAM CLI setup
    • Build application
    • Deploy to AWS
    • Rollback strategy
    • Troubleshooting
  3. Amplify Auto-Deploy - Frontend deployment

    • Connect repository
    • Configure build settings
    • Environment variables
    • Custom domain
    • Branch deployments

Deployment Strategies

1. Backend Deployment (SAM)

Code Change β†’ GitHub
    ↓
GitHub Actions
    ↓
sam build
    ↓
sam deploy
    ↓
CloudFormation Update
    ↓
Lambda Functions Updated

Rollback: CloudFormation automatic rollback on failure

2. Frontend Deployment (Amplify)

Code Change β†’ GitHub
    ↓
Amplify Webhook
    ↓
npm ci
    ↓
npm run build
    ↓
Deploy to CDN
    ↓
Invalidate Cache

Rollback: Redeploy previous version

Workflow Triggers

Backend Workflow

on:
  push:
    branches: [main, develop]
    paths:
      - 'lexi-be/**'
  workflow_dispatch:  # Manual trigger

Frontend Workflow

on:
  push:
    branches: [main]
    paths:
      - 'lexi-fe/**'
  pull_request:
    branches: [main]

Environment Management

Development

  • Branch: develop
  • Backend: lexi-be-dev stack
  • Frontend: develop.d<APP_ID>.amplifyapp.com

Staging

  • Branch: staging
  • Backend: lexi-be-staging stack
  • Frontend: staging.d<APP_ID>.amplifyapp.com

Production

  • Branch: main
  • Backend: lexi-be stack
  • Frontend: main.d<APP_ID>.amplifyapp.com or custom domain

Monitoring Deployments

GitHub Actions

# View workflow runs
gh run list

# View specific run
gh run view <RUN_ID>

# View logs
gh run view <RUN_ID> --log

CloudFormation

# List stacks
aws cloudformation list-stacks --region <REGION>

# Describe stack events
aws cloudformation describe-stack-events \
  --stack-name lexi-be \
  --region <REGION>

Amplify

# List apps
aws amplify list-apps --region <REGION>

# List jobs
aws amplify list-jobs \
  --app-id <APP_ID> \
  --branch-name main \
  --region <REGION>

Best Practices

1. Automated Testing

# Add test step before deploy
- name: Run tests
  run: |
    cd lexi-be
    python -m pytest tests/    

2. Deployment Approval

# Require manual approval for production
environment:
  name: production
  url: https://lexi.example.com

3. Notifications

# Notify on failure
- name: Notify on failure
  if: failure()
  uses: 8398a7/action-slack@v3
  with:
    status: ${{ job.status }}
    webhook_url: ${{ secrets.SLACK_WEBHOOK }}

4. Rollback Strategy

  • Backend: CloudFormation automatic rollback
  • Frontend: Amplify redeploy previous version
  • Database: Backup before migration

Troubleshooting

Issue: Workflow failed

# Check workflow logs in GitHub Actions
# Common issues:
# - AWS credentials invalid
# - Build errors
# - Deployment timeout

Issue: Deployment slow

Optimization:

  • Use caching (npm, pip)
  • Parallel jobs
  • Optimize build commands

Issue: Rollback needed

# Backend
aws cloudformation cancel-update-stack \
  --stack-name lexi-be

# Frontend
# Redeploy previous version in Amplify Console

Checklist

After completing the CI/CD section, you should:

  • Understand Lexi’s CI/CD architecture
  • Know how to setup GitHub repository
  • Understand how to configure GitHub Secrets
  • Know how to create GitHub Actions workflows
  • Understand backend deployment with SAM
  • Understand frontend deployment with Amplify
  • Know how to monitor deployments
  • Understand rollback strategies
  • Understand environment management (dev, staging, production)

πŸ“Έ TODO: Add CI/CD pipeline diagram

πŸ“Έ TODO: Add screenshot of successful GitHub Actions workflow

Next Steps

You’ve completed the CI/CD section! Continue to Monitoring & Cost Optimization to learn monitoring and cost optimization.