https://github.com/abdulrahmanalpha/ci-cd-webapp-ec2
CI/CD pipeline for web application using GitHub Actions, Docker, and AWS EC2.
https://github.com/abdulrahmanalpha/ci-cd-webapp-ec2
automation aws ci-cd cloud devops docker ec2 github-actions pipeline
Last synced: 9 months ago
JSON representation
CI/CD pipeline for web application using GitHub Actions, Docker, and AWS EC2.
- Host: GitHub
- URL: https://github.com/abdulrahmanalpha/ci-cd-webapp-ec2
- Owner: AbdulrahmanAlpha
- License: mit
- Created: 2025-09-25T23:36:39.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-09-26T01:11:36.000Z (9 months ago)
- Last Synced: 2025-09-26T02:34:49.533Z (9 months ago)
- Topics: automation, aws, ci-cd, cloud, devops, docker, ec2, github-actions, pipeline
- Language: Shell
- Homepage:
- Size: 74.2 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
# ๐ CI/CD Pipeline for Web Application
**Stack:** GitHub Actions ยท Docker ยท AWS EC2
---




---
## ๐ Project Overview
This project demonstrates how to build a **lightweight CI/CD pipeline** for deploying a web application on **AWS EC2** using **GitHub Actions** and **Docker**.
The goal was to **automate build, test, and deployment** workflows, ensuring faster delivery cycles and reproducible builds.
### ๐ฏ Outcomes
* Reduced deployment cycle time from **6 hours โ 30 minutes**.
* Increased **developer velocity** with automated linting & testing.
* Standardized builds with **Docker images**.
* Automated deployment to **AWS EC2** via GitHub Actions.
---
## ๐๏ธ Architecture

**Key components:**
1. **GitHub Actions CI/CD:**
* Workflow triggers on `git push`.
* Stages: Lint โ Test โ Build โ Push โ Deploy.
* Uses GitHub Secrets for storing AWS credentials & SSH keys.
2. **Docker:**
* Containerizes the application for reproducible builds.
* Images stored in AWS ECR (or Docker Hub).
3. **AWS EC2:**
* Acts as the deployment target.
* Runs Docker containers via a **deployment script** (`remote-deploy.sh`).
* Pulls new image, runs container, performs health check, and swaps/rolls back.
---
## ๐ Repository Structure
```
cicd-pipeline-ec2/
โโโ .github/workflows/ # GitHub Actions workflows (CI/CD)
โโโ docker/ # Dockerfiles for containerization
โโโ scripts/ # Deployment helper scripts (e.g., remote-deploy.sh)
โโโ app/ # Application source code
โโโ docs/ # Architecture docs, diagrams
โโโ README.md # Project documentation
```
---
## โ๏ธ Step-by-Step Implementation
### 1๏ธโฃ Setup GitHub Actions CI/CD
* Created `.github/workflows/cicd.yml` with stages:
1. Lint (ESLint).
2. Run unit tests (Jest).
3. Build Docker image.
4. Push image to AWS ECR (or Docker Hub).
5. Deploy to AWS EC2 over SSH.
๐ Triggered automatically on `push` to `main`.
---
### 2๏ธโฃ Containerize Application with Docker
* Wrote **Dockerfile** to package app (Node.js/Express).
* Local test:
```bash
docker build -t webapp:local docker/
docker run -p 3000:3000 webapp:local
```
---
### 3๏ธโฃ Provision AWS EC2
* Launched an EC2 instance with:
* Docker installed.
* Security Group allowing SSH (22) & App traffic (3000).
* Configured SSH keys and stored in GitHub Secrets.
---
### 4๏ธโฃ Deploy to EC2
* Added `scripts/remote-deploy.sh`:
* Connects via SSH.
* Pulls latest Docker image.
* Stops old container & starts new one.
* Performs health check.
* Rolls back if failure detected.
๐ Run automatically from GitHub Actions after build & push.
---
### 5๏ธโฃ Access the Application
* Find EC2 public IP:
```bash
aws ec2 describe-instances \
--query "Reservations[].Instances[].PublicIpAddress" \
--output text
```
* Open `http://:3000` in browser.
---
### 6๏ธโฃ Cleanup
* Stop Docker containers on EC2:
```bash
docker ps -q | xargs docker stop
```
* Terminate EC2 instance to avoid charges.
---
## ๐ Security Notes
* **AWS credentials** stored securely in **GitHub Secrets**.
* **SSH key** used for deployment (never stored in repo).
* Docker images tagged with commit SHA for traceability.
* EC2 Security Group restricted to trusted IP ranges.
---
## ๐ Next Improvements
* Add **Blue-Green Deployments** for zero-downtime releases.
* Use **Terraform** for EC2 provisioning.
* Replace manual SSH deploy with **AWS CodeDeploy** or **Ansible**.
* Add monitoring/alerts with **CloudWatch + Grafana**.
---
## โ
Skills Demonstrated
* CI/CD with **GitHub Actions**.
* **Dockerization** for reproducible builds.
* Automated **EC2 deployments**.
* Secure use of **GitHub Secrets**.
* Real-world **DevOps automation workflow**.
---
## ๐งโ๐ป Author
**Abdulrahman A. Muhamad**
DevOps | Cloud | SRE Enthusiast
๐ [LinkedIn](https://www.linkedin.com/in/abdulrahmanalpha) | [GitHub](https://github.com/AbdulrahmanAlpha) | [Portfolio](https://abdulrahman-alpha.web.app)