Membangun sistem deployment berbasis snapshot dengan 3 Server
Panduan lengkap membangun sistem deployment berbasis snapshot (Dev → Staging → Production), menggunakan aplikasi open-source yang sepenuhnya bisa kamu jalankan di server Linux (Ubuntu / Debian).
Panduan ini cocok untuk dosen, sysadmin, atau tim DevOps yang ingin membuat sistem CI/CD ringan, bisa rollback, dan tanpa vendor lock-in.
1. Tujuan Sistem
Membangun pipeline deployment tiga tahap — Dev, Staging, Production — dengan kemampuan:
- Membuat snapshot otomatis di tiap tahap (untuk rollback).
- Melakukan merge deployment antar environment.
- Menjalankan pengujian otomatis sebelum production.
- Menyimpan Audit Log dan catatan perubahan.
2. Arsitektur Umum
Developer → Dev Server → Staging Server → Production Server
Komponen:
| Komponen | Fungsi | Aplikasi Open Source | 
|---|---|---|
| Version Control | Manajemen kode sumber | Gitea / GitLab CE | 
| CI/CD Automation | Orkestrasi build, test, deploy | Drone CI, Jenkins, atau Woodpecker CI | 
| Snapshot Management | Backup & restore environment | BorgBackup, Restic, atau rsync + Btrfs | 
| Containerization | Isolasi environment antar stage | Docker / Podman | 
| Logging & Audit | Catatan perubahan & aktivitas | Loki + Grafana, atau ELK Stack (Elasticsearch, Logstash, Kibana) | 
| Testing Framework | Pengujian otomatis | pytest, Selenium, Postman CLI, dll. | 
3. Topologi Server
| Server | Fungsi | Tools Utama | 
|---|---|---|
| Dev Server | Tempat developer melakukan commit dan build awal | Gitea + Docker | 
| Staging Server | Tempat testing & validasi merge | Drone CI / Jenkins + Docker Compose | 
| Production Server | Sistem live dengan backup snapshot otomatis | Docker Compose + Restic + Loki | 
4. Langkah Implementasi
Langkah 1: Siapkan Repositori Kode (Dev Server)
- Install Gitea:
sudo apt install docker docker-compose -y mkdir /srv/gitea && cd /srv/gitea wget https://dl.gitea.io/gitea/docker-compose.yml docker-compose up -d
- Buat repositori proyek (misal: proyek-a).
- Developer melakukan commit & push kode ke Gitea.
Langkah 2: Siapkan CI/CD Pipeline (Staging Server)
Gunakan Drone CI (ringan, terintegrasi dengan Gitea).
- Deploy Drone CI:
docker run -d \ -e DRONE_GITEA_SERVER=https://gitea.local \ -e DRONE_GITEA_CLIENT_ID=<client_id> \ -e DRONE_GITEA_CLIENT_SECRET=<client_secret> \ -e DRONE_RPC_SECRET=<random_secret> \ -p 8080:80 --name drone \ drone/drone:latest
- Tambahkan file pipeline di repo:
kind: pipeline type: docker name: test_and_snapshot steps: - name: run-tests image: python:3.12 commands: - pip install -r requirements.txt - pytest tests/ - name: snapshot image: alpine commands: - apk add borgbackup - borg create /snapshots/staging::{now} /app
- Hasil sukses = snapshot otomatis dibuat di /snapshots/staging.
Langkah 3: Deploy ke Production (Manual/Automasi)
Gunakan Drone atau Jenkins untuk pipeline kedua:
kind: pipeline
type: docker
name: deploy_production
steps:
  - name: deploy
    image: alpine
    commands:
      - apk add rsync
      - rsync -avz /snapshots/staging/* prodserver:/srv/app/
      - docker compose up -d
  - name: audit
    image: busybox
    commands:
      - echo "Deployment $(date) by $DRONE_COMMIT_AUTHOR" >> /var/log/deploy_audit.log
Pastikan Production server punya SSH key-only access dari Staging agar aman.
Langkah 4: Snapshot & Rollback System
Gunakan Restic untuk backup otomatis setiap deploy:
restic -r /backup/proyek-a backup /srv/app/
# Untuk restore
restic -r /backup/proyek-a restore latest --target /srv/restore/
Bisa dijadwalkan via cron:
0 2 * * * restic -r /backup/proyek-a backup /srv/ap
Langkah 5: Logging & Audit
Pasang Loki + Grafana untuk memantau log deployment:
docker run -d --name loki -p 3100:3100 grafana/loki:latest
docker run -d -p 3000:3000 grafana/grafana:latest
- Simpan log Drone/Jenkins ke Loki.
- Audit Log disimpan otomatis di /var/log/deploy_audit.log.
5. Alur Operasional
| Tahap | Aktivitas | Tools | 
|---|---|---|
| Dev | Kode diubah & commit | Gitea | 
| Staging | Pipeline test otomatis → snapshot | Drone CI / Jenkins | 
| Production | Deploy dari snapshot staging → audit log | Drone CI + Restic | 
| Rollback | Restore snapshot terakhir | Restic / Borg | 
6. Best Practice
- 
Gunakan branching model: - dev→ untuk pengembangan.
- staging→ untuk pengujian.
- main→ untuk production.
 
- 
Simpan snapshot minimal 3 versi terakhir. 
- 
Gunakan environment parity (konfigurasi identik antar server). 
- 
Aktifkan webhook Gitea → Drone agar build otomatis setiap push. 
- 
Tambahkan notifikasi Telegram/Slack untuk status pipeline. 
7. Contoh Integrasi Ringan di Ubuntu
sudo apt install docker-compose restic borgbackup -y
# Direktori proyek
mkdir -p /srv/{dev,staging,production}/proyek-a
# Inisialisasi backup
restic init -r /srv/backup/proyek-A
8. Alternatif Tools Setara (Semua Open Source)
| Fitur | Rekomendasi Utama | Alternatif | 
|---|---|---|
| Git hosting | Gitea | GitLab CE | 
| CI/CD | Drone CI | Jenkins / Woodpecker | 
| Snapshot | BorgBackup | Restic | 
| Containerization | Docker | Podman | 
| Monitoring | Loki + Grafana | ELK Stack | 
| Test Automation | pytest | Robot Framework | 
9. Hasil Akhir Sistem
Setelah semua komponen aktif:
- Developer push → Drone build di Staging.
- Snapshot dibuat otomatis → diverifikasi.
- Setelah lolos test → deploy ke Production via merge mode.
- Semua aktivitas tercatat di Audit Log dan Grafana.
- Jika ada error → rollback snapshot otomatis.
Selesai


