Project demo untuk belajar menggunakan Docker di GitHub Codespaces lengkap dengan automated testing via GitHub Actions.
cobaa/
βββ app.js # Express API server
βββ test.js # Automated test suite
βββ package.json # Node.js dependencies
βββ Dockerfile # Multi-stage Docker build
βββ docker-compose.yml # Docker Compose (app + test)
βββ .dockerignore
βββ .gitignore
βββ .devcontainer/
β βββ devcontainer.json # GitHub Codespaces config
βββ .github/
βββ workflows/
βββ docker-test.yml # CI/CD pipeline
- Push repo ini ke GitHub
- Buka repository di GitHub
- Klik tombol
<> CodeβCodespacesβCreate codespace on main - Tunggu environment siap (Docker sudah otomatis tersedia!)
- Di terminal Codespaces, jalankan:
# Build & run
docker compose up --build
# Buka tab baru, test
docker compose --profile test run --rm test# Clone repo
git clone https://github.com/USERNAME/cobaa.git
cd cobaa
# Build & run app
docker compose up --build -d
# Jalankan test
docker compose --profile test run --rm test
# Stop
docker compose downnpm install
npm start # Start server di port 3000
# Buka terminal baru:
npm test # Jalankan test suite# Health check
curl http://localhost:3000/health
# Info endpoint
curl http://localhost:3000/info
# Echo endpoint
curl -X POST http://localhost:3000/echo \
-H "Content-Type: application/json" \
-d '{"hello": "docker"}'# Ini akan build app, tunggu healthy, lalu jalankan test suite
docker compose --profile test run --rm testSetiap kali kamu push atau buat Pull Request, GitHub Actions akan otomatis:
- β Build Docker image
- β Start container & tunggu healthy
- β Jalankan test suite
- β Cleanup
Cek hasilnya di tab Actions di repository GitHub kamu.
| Method | Path | Deskripsi |
|---|---|---|
| GET | / |
Info tentang API |
| GET | /health |
Health check (untuk Docker) |
| GET | /info |
System info (Node, memory) |
| POST | /echo |
Echo back request body |
# Init git repo
git init
git add .
git commit -m "π³ Initial: Docker + Codespaces demo"
# Push ke GitHub
git remote add origin https://github.com/USERNAME/cobaa.git
git branch -M main
git push -u origin mainNote: Ganti
USERNAMEdengan username GitHub kamu.
βββββββββββββββββββββββββββββββββββββββββββββββ
β GitHub Codespaces β
β βββββββββββββββββββββββββββββββββββββββββ β
β β devcontainer (Node.js 20) β β
β β βββββββββββββββββββββββββββββββββββ β β
β β β Docker-in-Docker β β β
β β β βββββββββββββ βββββββββββββ β β β
β β β β web:3000 β β test β β β β
β β β β (app.js) ββ β (test.js) β β β β
β β β βββββββββββββ βββββββββββββ β β β
β β βββββββββββββββββββββββββββββββββββ β β
β βββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββ
β GitHub Actions (CI/CD) β
β push/PR β build image β run β test β β
β
βββββββββββββββββββββββββββββββββββββββββββββββ