Repository ini berisi implementasi CI/CD pipeline end-to-end untuk aplikasi containerized menggunakan Docker dan GitHub Actions.
Fokus utama proyek ini adalah praktik DevOps modern, bukan pada kompleksitas aplikasinya.
Pipeline memastikan bahwa setiap perubahan kode telah melalui proses:
- Build container image
- Unit test container
- Integration test antar service
- Security scanning
- Artifact publishing ke container registry
Pipeline ini dirancang sebagai fondasi sebelum melanjutkan ke Continuous Deployment (CD) atau Kubernetes orchestration.
- Node.js
- Express.js
- HTML / CSS / JavaScript
- Docker
- Docker Compose
- GitHub Actions
- Trivy (Container Vulnerability Scanner)
- Gitleaks (Secret Leak Detection)
- npm audit (Dependency Vulnerability Scanner)
Developer
โ
โ git push
โผ
GitHub Repository
โ
โผ
GitHub Actions CI Pipeline
โ
โโโ Checkout Source Code
โโโ Build Docker Images
โโโ Unit Test (Container)
โโโ Integration Test (Docker Compose)
โโโ Security Scan
โ โโโ Dependency Scan
โ โโโ Secret Scan
โ โโโ Container Vulnerability Scan
โ
โผ
Push Docker Images
Docker Registry
โ
โผ
GitHub Actions (CD)
โ
โผ
SSH โ AWS EC2
โ
โผ
docker-compose pull
docker-compose down
docker-compose up -d
โ
โผ
๐ Application Running on AWS EC2Pipeline memastikan bahwa hanya image yang telah tervalidasi yang akan dipublish ke registry.
simple-notes-app
โ
โโโ backend
โ โโโ src
โ โโโ package.json
โ โโโ Dockerfile
โ
โโโ frontend
โ โโโ index.html
โ โโโ script.js
โ โโโ style.css
โ โโโ Dockerfile
โ
โโโ docker-compose.yml
โ
โโโ .github
โโโ workflows
โโโ ci-dev.yml
โโโ cd-dev.ymlFolder .github/workflows berisi konfigurasi CI CD pipeline menggunakan GitHub Actions.
Pastikan software berikut sudah terinstall sebelum menjalankan proyek:
- Node.js >= 18
- Docker
- Docker Compose
- Git
- AWS EC2 Instance
Cek versi:
node -v
docker -v
docker compose versionClone repository:
git clone https://github.com/USERNAME/simple-notes-app.git
cd simple-notes-appBackend
cd backend
npm install
npm startServer backend akan berjalan di:
http://localhost:3000Frontend
cd frontendBuka file: index.html atau jalankan server sederhana:
npx serve .Frontend akan tersedia di: http://localhost:8080
Cara paling mudah menjalankan seluruh stack adalah menggunakan Docker Compose.
Build dan jalankan container:
docker compose up --buildAkses service:
Frontend: http://localhost:8080
Backend API: http://localhost:3000
Stop service:
docker compose down๐ API Structure Base URL
http://localhost:3000/apiEndpoint Documentation Method Endpoint Description
GET /health Backend health check
GET /api/notes Retrieve all notes
POST /api/notes Create new note
PUT /api/notes/:id Update note
DELETE /api/notes/:id Delete noteExample Request Create note:
curl -X POST http://localhost:3000/api/notes \
-H "Content-Type: application/json" \
-d '{
"title":"Belajar DevOps",
"content":"Membuat CI/CD pipeline"
}'Example response:
{
"id": 1,
"title": "Belajar DevOps",
"content": "Membuat CI/CD pipeline"
}Aplikasi menggunakan konfigurasi environment untuk menjalankan service.
Contoh .env:
PORT=3000
NODE_ENV=development
DB_PATH=./notes.dbDalam environment container, konfigurasi ini biasanya didefinisikan melalui:
- docker-compose.yml
- environment variables pada container
- CI/CD secret configuration
Pipeline dijalankan setiap ada push ke branch dev.
1๏ธ Checkout Source Code GitHub Actions mengambil source code terbaru dari repository.
2๏ธโฃ Build Docker Images Pipeline membangun container image untuk dua service:
- notes-backend
- notes-frontend Contoh command:
docker build -t <docker-user>/notes-backend:<commit-sha> ./backend
docker build -t <docker-user>/notes-frontend:<commit-sha> ./frontendSetiap image menggunakan Git commit SHA sebagai tag untuk memastikan versioning yang konsisten.
3๏ธโฃ Unit Test (Container Level) Container dijalankan secara individual untuk memastikan image dapat berjalan dengan benar. Contoh:
docker run -d -p 3000:3000 notes-backend:<tag>
docker run -d -p 8080:80 notes-frontend:<tag>Validasi dilakukan dengan:
- memastikan container dapat start
- memeriksa log container
- memastikan runtime environment valid
4๏ธโฃ Integration Test (Full Stack) Integration test dilakukan menggunakan Docker Compose. Pipeline menjalankan seluruh stack: frontend, backend, database. Contoh command:
docker compose up -dSetelah service berjalan, pipeline menjalankan beberapa test endpoint.
Backend Health Check
docker exec notes-backend wget -qO- http://localhost:3000/healthBackend API Test
docker exec notes-backend wget -qO- http://localhost:3000/api/notesFrontend Availability
curl -f http://localhost:8080Jika salah satu test gagal, pipeline akan dihentikan.
Pipeline menjalankan beberapa tahap security scanning.
Dependency backend discan menggunakan:
npm auditPipeline akan gagal jika ditemukan vulnerability dengan severity tinggi.
Secret scanning dilakukan menggunakan Gitleaks. Tool ini mendeteksi kemungkinan kebocoran: API keys, tokens, password, credentials.
Image container discan menggunakan Trivy.
Contoh scanning command:
trivy image <image-name>Scan akan memeriksa:
- OS package vulnerabilities
- language dependency vulnerabilities
- container layer vulnerabilities
Pipeline akan gagal jika ditemukan vulnerability dengan severity:
- CRITICAL
- HIGH
Jika semua tahap CI berhasil, pipeline akan mempublish Docker image ke registry.
Contoh:
docker push <docker-user>/notes-backend:<commit-sha>
docker push <docker-user>/notes-frontend:<commit-sha>Image ini kemudian dapat digunakan untuk:
- staging deployment
- production deployment
- Kubernetes workloads
Pipeline Continuous Deployment (CD) bertanggung jawab untuk mendeploy aplikasi secara otomatis ke server cloud setelah pipeline CI berhasil. Pada proyek ini, deployment dilakukan ke instance Amazon EC2 menggunakan SSH automation dari GitHub Actions.
Workflow CD:
GitHub Actions (CI Success)
โ
โผ
Trigger CD Workflow
โ
โผ
SSH ke EC2 Server
โ
โโโ Login Docker Hub
โโโ Pull latest image
โโโ Stop container lama
โโโ Run container baru
โ
โผ
Application Live di EC2Pipeline ini memastikan bahwa:
- Deployment hanya terjadi jika CI sukses
- Server selalu menggunakan image terbaru
- Deployment bersifat repeatable & otomatis
CD menggunakan event:
on:
workflow_call:Contoh pemanggilan dari CI:
jobs:
deploy:
needs: build
uses: ./.github/workflows/cd-dev.ymlDatabase menggunakan Docker Volume:
volumes:
postgres_data:Data tidak hilang walaupun container dihapus Aman saat CI/CD redeploy
Agar CD bisa berjalan, kamu harus set secrets di GitHub: Secret Name Deskripsi
- EC2_HOST Public IP EC2
- EC2_USER Biasanya ubuntu
- EC2_SSH_KEY Private key (tanpa .pem)
- DOCKER_USER Username Docker Hub
- DOCKER_PASS Password / Access Token
CD akan menjalankan script berikut di server EC2:
cd ~/simple-notes-app
echo "${DOCKER_PASS}" | docker login -u "${DOCKER_USER}" --password-stdin
docker-compose pull
docker-compose down
docker-compose up -dPenjelasan:
- Login Docker Hub Agar server bisa pull image private/public terbaru
- Pull Latest Image docker-compose pull Ambil image terbaru dari registry
- Stop Container Lama docker-compose down Menghindari conflict & memastikan clean state
- Start Container Baru docker-compose up -d Menjalankan versi terbaru aplikasi
Setup EC2:
- Launch Ubuntu Instance
- Install Docker & Docker Compose
- Open port: 22 (SSH) 80 (HTTP)
Clone Project di EC2:
git clone https://github.com/USERNAME/simple-notes-app.git
cd simple-notes-appJalankan Aplikasi
docker-compose up -dAkses:
http://<EC2-PUBLIC-IP>- Image hanya berisi aplikasi
- Orkestrasi tetap dikontrol oleh server
backend:
image: <docker-user>/notes-backend:dev
frontend:
image: <docker-user>/notes-frontend:devDi server EC2:
nano .envIsi:
POSTGRES_DB=
POSTGRES_USER=
POSTGRES_PASSWORD=
DB_HOST=
DB_PORT=
DB_NAME=
DB_USER=
DB_PASSWORD=- Compose dibaca dari EC2, bukan dari image Yang dipakai saat deploy:
docker-compose up- Image โ Compose Komponen Fungsi Docker image isi aplikasi docker-compose cara menjalankan
- Kenapa pakai ENV? Supaya:
- tidak hardcode password
- bisa beda environment (dev/prod)
- aman untuk repo publik
# Disable root login
sudo nano /etc/ssh/sshd_config
PermitRootLogin no
PasswordAuthentication no
sudo systemctl restart sshUser (Browser)
โ
Public IP (EC2)
โ
Nginx (Frontend Container :80)
โ
Backend (Node.js :3000)
โ
PostgreSQL (Internal Network)# Cek container
docker ps
# Cek log backend
docker logs notes-backend
# Restart manual
docker-compose down && docker-compose up -d- Image = hanya aplikasi
- Compose = cara menjalankan (orchestration)
- Lebih fleksibel dibanding hardcode di CI/CD
- Bisa scale ke Kubernetes nanti
Pipeline ini dapat dikembangkan lebih lanjut dengan menambahkan:
- Multi-environment deployment (dev, staging, prod)
- Blue-Green Deployment
- Kubernetes (EKS)
- Load Balancer + HTTPS (Nginx + Certbot)
- Monitoring (Prometheus + Grafana)
- Auto rollback jika deployment gagal