CI/CD Pipeline
This document covers the continuous integration and deployment pipeline for iHospita HMS.
Pipeline Overview
┌──────────────────────────────────────────────────────────────────┐
│ CI/CD PIPELINE │
├──────────────────────────────────────────────────────────────────┤
│ │
│ 1. Code Push │
│ │ │
│ ▼ │
│ 2. Lint & Type Check │
│ │ │
│ ▼ │
│ 3. Unit Tests │
│ │ │
│ ▼ │
│ 4. Build │
│ │ │
│ ▼ │
│ 5. Integration Tests │
│ │ │
│ ▼ │
│ 6. Build Docker Images │
│ │ │
│ ▼ │
│ 7. Push to Registry │
│ │ │
│ ▼ │
│ 8. Deploy to Staging │
│ │ │
│ ▼ │
│ 9. E2E Tests │
│ │ │
│ ▼ │
│ 10. Deploy to Production (manual approval) │
│ │
└──────────────────────────────────────────────────────────────────┘
GitHub Actions Workflow
Main CI/CD Workflow
# .github/workflows/ci-cd.yml
name: CI/CD Pipeline
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
env:
NODE_VERSION: '18'
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Lint
run: npm run lint
- name: Type check
run: npm run type-check
test:
runs-on: ubuntu-latest
needs: lint
services:
postgres:
image: postgres:15-alpine
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: test
ports:
- 5432:5432
redis:
image: redis:7-alpine
ports:
- 6379:6379
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run migrations
run: npx prisma migrate deploy
env:
DATABASE_URL: postgresql://test:test@localhost:5432/test
- name: Run tests
run: npm run test:cov
env:
DATABASE_URL: postgresql://test:test@localhost:5432/test
REDIS_URL: redis://localhost:6379
- name: Upload coverage
uses: codecov/codecov-action@v3
build:
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: dist
path: dist/
docker:
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/main'
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker images
run: |
for service in hms crm payment queue report; do
docker build \
--build-arg APP_NAME=$service \
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-$service:${{ github.sha }} \
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-$service:latest \
./server
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-$service:${{ github.sha }}
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-$service:latest
done
deploy-staging:
runs-on: ubuntu-latest
needs: docker
if: github.ref == 'refs/heads/main'
environment: staging
steps:
- name: Deploy to Staging
run: |
# Deploy using SSH or cloud provider CLI
echo "Deploying to staging..."
deploy-production:
runs-on: ubuntu-latest
needs: deploy-staging
if: github.ref == 'refs/heads/main'
environment: production
steps:
- name: Deploy to Production
run: |
# Deploy using SSH or cloud provider CLI
echo "Deploying to production..."
Branch Strategy
| Branch | Purpose | Deploys To |
|---|---|---|
main | Production code | Production |
develop | Development | Staging |
feature/* | New features | PR only |
hotfix/* | Emergency fixes | Production |
Deployment Environments
Staging
- URL:
https://staging.ihospita.com - Auto-deploys from
mainbranch - Used for QA testing
Production
- URL:
https://ihospita.com - Requires manual approval
- Blue-green deployment
Rollback Procedure
# List recent deployments
kubectl rollout history deployment/hms-service
# Rollback to previous version
kubectl rollout undo deployment/hms-service
# Rollback to specific revision
kubectl rollout undo deployment/hms-service --to-revision=2
Monitoring
- Build status: GitHub Actions dashboard
- Deployment status: Grafana dashboard
- Alerts: Slack notifications