Skip to content

paulkusuma/simple-notes-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

11 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€ Simple Notes App โ€” DevOps CI/CD Pipeline

Build Status Docker Node License

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.


๐Ÿงฐ Tech Stack

Application

  • Node.js
  • Express.js
  • HTML / CSS / JavaScript

Containerization

  • Docker
  • Docker Compose

CI/CD

  • GitHub Actions

Security Tools

  • Trivy (Container Vulnerability Scanner)
  • Gitleaks (Secret Leak Detection)
  • npm audit (Dependency Vulnerability Scanner)

๐Ÿ—๏ธ CI/CD Architecture

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

Pipeline memastikan bahwa hanya image yang telah tervalidasi yang akan dipublish ke registry.


๐Ÿ“‚ Project Structure

simple-notes-app
โ”‚
โ”œโ”€โ”€ backend
โ”‚ โ”œโ”€โ”€ src
โ”‚ โ”œโ”€โ”€ package.json
โ”‚ โ””โ”€โ”€ Dockerfile
โ”‚
โ”œโ”€โ”€ frontend
โ”‚ โ”œโ”€โ”€ index.html
โ”‚ โ”œโ”€โ”€ script.js
โ”‚ โ”œโ”€โ”€ style.css
โ”‚ โ””โ”€โ”€ Dockerfile
โ”‚
โ”œโ”€โ”€ docker-compose.yml
โ”‚
โ””โ”€โ”€ .github
    โ””โ”€โ”€ workflows
        โ””โ”€โ”€ ci-dev.yml

Folder .github/workflows berisi konfigurasi CI pipeline menggunakan GitHub Actions.


โš™๏ธ Prerequisites

Pastikan software berikut sudah terinstall sebelum menjalankan proyek:

  • Node.js >= 18
  • Docker
  • Docker Compose
  • Git

Cek versi:

node -v
docker -v
docker compose version

๐Ÿ› ๏ธ Local Development Setup

Clone repository:

git clone https://github.com/USERNAME/simple-notes-app.git
cd simple-notes-app

Backend

cd backend
npm install
npm start

Server backend akan berjalan di:

http://localhost:3000

Frontend

cd frontend

Buka file: index.html atau jalankan server sederhana:

npx serve .

Frontend akan tersedia di: http://localhost:8080


๐Ÿณ Running with Docker

Cara paling mudah menjalankan seluruh stack adalah menggunakan Docker Compose.

Build dan jalankan container:

docker compose up --build

Akses service:

Frontend: http://localhost:8080

Backend API: http://localhost:3000

Stop service:

docker compose down

๐Ÿ”— API Structure Base URL

http://localhost:3000/api

Endpoint 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 note

Example 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"
}

๐Ÿ”‘ Environment Variables

Aplikasi menggunakan konfigurasi environment untuk menjalankan service.

Contoh .env:

PORT=3000
NODE_ENV=development
DB_PATH=./notes.db

Dalam environment container, konfigurasi ini biasanya didefinisikan melalui:

  • docker-compose.yml
  • environment variables pada container
  • CI/CD secret configuration

โš™๏ธ CI Pipeline Stages

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> ./frontend

Setiap 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 -d

Setelah service berjalan, pipeline menjalankan beberapa test endpoint.

Backend Health Check

docker exec notes-backend wget -qO- http://localhost:3000/health

Backend API Test

docker exec notes-backend wget -qO- http://localhost:3000/api/notes

Frontend Availability

curl -f http://localhost:8080

Jika salah satu test gagal, pipeline akan dihentikan.


๐Ÿ” Security Scanning

Pipeline menjalankan beberapa tahap security scanning.

Dependency Vulnerability Scan

Dependency backend discan menggunakan:

npm audit

Pipeline akan gagal jika ditemukan vulnerability dengan severity tinggi.

Secret Detection

Secret scanning dilakukan menggunakan Gitleaks. Tool ini mendeteksi kemungkinan kebocoran: API keys, tokens, password, credentials.

Container Vulnerability Scan

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

๐Ÿ“ฆ Artifact Publishing

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

๐Ÿ”ฎ Future Improvements

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

About

Aplikasi Web Sederhana

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors