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 RegistryPipeline 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.ymlFolder .github/workflows berisi konfigurasi CI pipeline menggunakan GitHub Actions.
Pastikan software berikut sudah terinstall sebelum menjalankan proyek:
- Node.js >= 18
- Docker
- Docker Compose
- Git
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 ini dapat dikembangkan lebih lanjut dengan menambahkan:
- Continuous Deployment (CD)
- Automated deployment ke server
- Kubernetes orchestration
- Helm chart
- GitOps workflow
- Monitoring dan observability
- Automated rollback