|
| 1 | +# 🚀 Deployment Process Documentation |
| 2 | + |
| 3 | +This document outlines the CI/CD deployment pipeline for the application, including how testing, Docker image management, deployment to the virtual machine (VM), and post-deployment checks are handled. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## 📦 Pre-Deployment Steps (CI) |
| 8 | + |
| 9 | +### 1. **Linting and Unit Tests** |
| 10 | + |
| 11 | +All code changes undergo automated testing using GitHub Actions: |
| 12 | + |
| 13 | +### **Frontend** |
| 14 | +--- |
| 15 | + |
| 16 | +**Filename**: lint.yml |
| 17 | + |
| 18 | + * **Linter:** Runs using ESLint. |
| 19 | + * **Unit Tests:** Run using **Jest**. |
| 20 | + |
| 21 | +### **Backend** |
| 22 | +--- |
| 23 | + |
| 24 | +**Filename**: backend-lint.yml |
| 25 | + |
| 26 | + * **Linter:** Runs using flake8 |
| 27 | + * **Unit Tests:** Run using **pytest**. |
| 28 | + |
| 29 | +### 2. **Build and Push Docker Images** |
| 30 | + |
| 31 | +Triggered only when a Git **tag is pushed** (e.g., `v1.0.0`). |
| 32 | + |
| 33 | +* **Frontend Image:** |
| 34 | + |
| 35 | + * Dockerfile in `epiready-frontend/` |
| 36 | + * Built and tagged as `epiready-frontend:<git-tag>` |
| 37 | + |
| 38 | +* **Backend Image:** |
| 39 | + |
| 40 | + * Dockerfile in `epiready-backend/` |
| 41 | + * Built and tagged as `epiready-backend:<git-tag>` |
| 42 | + |
| 43 | +* **Push:** Images are pushed to DockerHub using GitHub Actions. |
| 44 | + |
| 45 | +--- |
| 46 | + |
| 47 | +## ☁️ Deployment to VM (CD) |
| 48 | + |
| 49 | +### **Triggering Deployment Workflow** |
| 50 | + |
| 51 | +A **workflow file** (`deploy-docker.yml`) is triggered **after build-backend.yml and build-frontend.yml are run succesfully.** This only runs when the other workflow files are run in the main branch, not before it. |
| 52 | + |
| 53 | +### 1. **SSH Into VM** |
| 54 | + |
| 55 | +* The workflow file then uses appleboy/ssh-action@v1 to ssh into the Lightsail VM and then goes to the epiready directory where it uses git pull to update the docker-compose file in case any new containers or modifications were made. |
| 56 | + |
| 57 | +### 2. **Pull Docker Images** |
| 58 | + |
| 59 | +* Uses Docker to pull: |
| 60 | + |
| 61 | + * `your-dockerhub/frontend:<git-tag>` |
| 62 | + * `your-dockerhub/backend:<git-tag>` |
| 63 | + |
| 64 | +### 3. **Deploy Using Docker Compose** |
| 65 | + |
| 66 | +* Uses a `docker-compose.yml` file that defines: |
| 67 | + |
| 68 | + * **Frontend container** (served via **NGINX**) with **Certbot** for HTTPS |
| 69 | + * **Backend container** |
| 70 | + * **PostgreSQL** service with a **named volume** for persistent storage |
| 71 | + |
| 72 | +* Executes: `docker compose pull && docker compose up -d` |
| 73 | + |
| 74 | +--- |
| 75 | + |
| 76 | +## 🔍 Post-Deployment Testing |
| 77 | + |
| 78 | +### 7. **E2E Testing with Cypress** |
| 79 | + |
| 80 | +* Cypress tests are triggered **after deployment completes**. |
| 81 | +* Run against the live application to simulate real-user flows. |
| 82 | + |
| 83 | +### 8. **Load Testing with Apache Bench (ab)** |
| 84 | + |
| 85 | +* Conducted to verify server performance and concurrency handling. |
| 86 | +* Example: `ab -n 100 -c 10 https://epiready.taggit.tech/` |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | +## 🗂️ Versioning |
| 91 | + |
| 92 | +* **Git Tags** (e.g., `v1.0.1`) determine image versions. |
| 93 | +* Helps maintain rollback strategy and historical traceability. |
| 94 | + |
| 95 | +--- |
| 96 | + |
| 97 | +## 🔐 Secrets and Security |
| 98 | + |
| 99 | +* SSH keys and DockerHub credentials are stored securely in **GitHub Secrets**. |
| 100 | +* Certbot is used to auto-renew SSL certificates for production. |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | +## 📁 Folder Structure (Simplified) |
| 105 | + |
| 106 | +``` |
| 107 | +epiready/ |
| 108 | +├── backend/ |
| 109 | +│ └── Dockerfile |
| 110 | +├── frontend/ |
| 111 | +│ └── Dockerfile |
| 112 | +├── docker-compose.yml |
| 113 | +├── .github/ |
| 114 | +│ ├── workflows/ |
| 115 | +│ │ ├── backend-lint.yml (backend tests) |
| 116 | +│ │ └── lint.yml (frontend tests) |
| 117 | +│ │ └── docker-deploy.yml (ssh + pull + deploy + post-tests) |
| 118 | +│ │ └── build-backend.yml (build and push backend) |
| 119 | +│ │ └── build-frontend.yml (build and push frontend) |
| 120 | +``` |
| 121 | + |
| 122 | +--- |
| 123 | + |
| 124 | +## ✅ Summary Checklist |
| 125 | + |
| 126 | + [x] Run lint and unit tests |
| 127 | + [x] Build & push tagged Docker images |
| 128 | + [x] SSH into VM and deploy with docker-compose |
| 129 | + [x] Serve with NGINX + Certbot |
| 130 | + [x] PostgreSQL with volume |
| 131 | + [x] Run Cypress tests |
| 132 | + [x] Run Apache Bench |
| 133 | + |
| 134 | +--- |
| 135 | + |
| 136 | +## 🔄 Future Enhancements (Optional) |
| 137 | + |
| 138 | +* Add rollback automation on test failure |
| 139 | +* Add Slack/Discord notifications post-deploy |
| 140 | +* Enable blue-green deployments for zero downtime |
0 commit comments