Membangun Pipeline CI/CD Modern dengan PHP, Git, Docker, dan Jenkins
Dalam beberapa tahun terakhir, cara melakukan deployment aplikasi telah berubah drastis.
Dahulu proses deployment biasanya dilakukan secara manual:
Developer selesai coding
↓
Copy file ke server menggunakan FTP
↓
Replace file lama
↓
Restart web server
↓
Berdoa semoga tidak error
Metode tersebut memiliki banyak kelemahan:
- Rentan human error
- Sulit melakukan rollback
- Tidak ada histori deployment
- Tidak konsisten antar server
- Sulit diskalakan
Karena itu muncul pendekatan modern:
Developer Commit Code
↓
Git Repository
↓
CI/CD Pipeline
↓
Build Otomatis
↓
Testing Otomatis
↓
Deployment Otomatis
Pendekatan ini memungkinkan proses deployment menjadi lebih cepat, aman, dan konsisten.
2. Memahami Continuous Integration dan Continuous Deployment
Continuous Integration (CI)
Continuous Integration adalah proses menggabungkan perubahan kode secara rutin ke repository utama.
Tujuannya:
- Mengurangi konflik kode
- Memastikan aplikasi selalu dapat dibangun
- Menjalankan testing otomatis
Contoh:
Developer A Push
Developer B Push
Developer C Push
↓
Jenkins Build Otomatis
↓
Semua perubahan diverifikasi
Continuous Deployment (CD)
Continuous Deployment adalah proses mengirim hasil build ke environment tujuan secara otomatis.
Contoh:
Git Push
↓
Build Docker Image
↓
Deploy Container Baru
↓
Aplikasi Aktif
3. Arsitektur Tutorial
Arsitektur yang akan dibangun:
+----------------------+
| Developer Laptop |
+----------+-----------+
|
| Git Push
v
+----------------------+
| Git Repository |
| GitHub / GitLab |
+----------+-----------+
|
| Webhook
v
+----------------------+
| Jenkins Server |
+----------+-----------+
|
| Docker Build
v
+----------------------+
| Docker Image |
+----------+-----------+
|
| Docker Run
v
+----------------------+
| PHP Application |
+----------------------+
4. Persiapan Infrastruktur
Laptop Developer
Komponen:
- Git
- Docker Desktop / Docker Engine
- VSCode atau IDE lain
Verifikasi:
git --version
docker --version
Jenkins Server
Spesifikasi minimum:
CPU : 2 Core
RAM : 4 GB
Disk : 50 GB
OS : Linux
Direkomendasikan:
CPU : 4 Core
RAM : 8 GB
Disk : 100 GB SSD
5. Membuat Aplikasi PHP
Struktur project:
php-hello-jenkins/
├── src/
│ └── index.php
├── Dockerfile
├── Jenkinsfile
└── README.md
File:
<?php
echo "<h1>Hello World</h1>";
echo "<p>CI/CD berhasil berjalan.</p>";
Meskipun sederhana, aplikasi ini cukup untuk memahami seluruh proses pipeline.
6. Git sebagai Fondasi CI/CD
Git merupakan fondasi utama seluruh pipeline.
Tanpa Git, Jenkins tidak memiliki sumber kebenaran (source of truth).
Inisialisasi Repository
git init
Menambahkan File
git add .
Commit
git commit -m "Initial Commit"
Push
git push origin main
7. Branching Strategy
Banyak tim gagal karena tidak memiliki strategi branch yang jelas.
Untuk tim kecil:
main
Untuk tim menengah:
main
develop
feature/*
Untuk enterprise:
main
develop
release/*
hotfix/*
feature/*
8. Docker Fundamentals
Docker memecahkan masalah:
"Berjalan di laptop saya, tapi gagal di server"
Dengan Docker:
Code
+
Runtime
+
Dependencies
↓
Docker Image
Hasilnya identik di semua server.
9. Dockerfile
Contoh:
FROM php:8.3-apache
COPY src/ /var/www/html/
EXPOSE 80
Proses build:
docker build -t php-hello-world .
Docker membaca Dockerfile dan menghasilkan image.
10. Memahami Jenkins
Jenkins adalah automation server.
Fungsi utamanya:
- Build
- Test
- Package
- Deploy
Jenkins bertindak sebagai "robot DevOps".
11. Instalasi Jenkins
Ubuntu:
sudo apt update
sudo apt install jenkins
AlmaLinux:
sudo dnf install jenkins
Aktifkan:
sudo systemctl enable jenkins
sudo systemctl start jenkins
12. Jenkins dan Docker
Secara default Jenkins tidak bisa mengakses Docker.
Tambahkan:
sudo usermod -aG docker jenkins
Restart:
sudo systemctl restart jenkins
Verifikasi:
sudo -u jenkins docker ps
13. Jenkins Pipeline
Pipeline adalah definisi otomatisasi.
Contoh sederhana:
pipeline {
agent any
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build') {
steps {
sh 'docker build -t php-app .'
}
}
stage('Deploy') {
steps {
sh 'docker run ...'
}
}
}
}
14. Konsep Stage
Pipeline biasanya terdiri dari:
Checkout
↓
Build
↓
Unit Test
↓
Security Scan
↓
Package
↓
Deploy
↓
Verify
Semakin matang organisasi, semakin banyak stage.
15. Docker Compose
Ketika aplikasi bertambah kompleks:
PHP
MySQL
Redis
Nginx
Menjalankan satu per satu container menjadi tidak praktis.
Gunakan:
services:
app:
image: php-app
db:
image: mysql
redis:
image: redis
16. Auto Deployment dengan Webhook
Tanpa webhook:
Git Push
↓
Login Jenkins
↓
Klik Build
Dengan webhook:
Git Push
↓
GitHub Notify Jenkins
↓
Pipeline Jalan Otomatis
Inilah CI/CD yang sesungguhnya.
17. Environment Management
Jangan deploy langsung ke production.
Minimal:
Development
↓
Staging
↓
Production
Tujuan:
- Mengurangi risiko
- Validasi sebelum produksi
- Testing user acceptance
18. Versioning
Jangan gunakan:
latest
Gunakan:
v1.0.0
v1.0.1
v1.1.0
v2.0.0
Mengikuti Semantic Versioning:
MAJOR.MINOR.PATCH
Contoh:
2.4.15
19. Rollback Strategy
Deployment harus selalu memiliki jalur mundur.
Contoh:
v1.0.0
↓
Deploy v1.1.0
↓
Error
↓
Rollback ke v1.0.0
Tanpa rollback, downtime bisa berlangsung berjam-jam.
20. Logging dan Monitoring
Deployment bukan akhir perjalanan.
Minimal pasang:
Application Log
Container Log
System Log
Tools populer:
ELK Stack
Graylog
Grafana Loki
Prometheus
Grafana
21. Security Best Practice
Jangan pernah:
Password di Git
Token di Git
API Key di Git
Gunakan:
Jenkins Credentials
Vault
Docker Secret
Kubernetes Secret
22. CI/CD Enterprise Architecture
Tahap berikutnya:
Git
↓
Jenkins
↓
SonarQube
↓
Security Scan
↓
Docker Registry
↓
Staging
↓
Approval
↓
Production
Lebih lanjut:
Git
↓
Jenkins
↓
Docker Registry
↓
Kubernetes
↓
Service Mesh
↓
Observability Platform
23. Roadmap Belajar Selanjutnya
Urutan yang disarankan:
- Git Dasar
- Git Branching
- Docker Dasar
- Docker Compose
- Jenkins Pipeline
- Jenkins Shared Library
- SonarQube
- Nexus / Harbor
- Kubernetes
- GitOps
- ArgoCD
- Observability
Penutup
CI/CD bukan sekadar mengotomatisasi deployment.
CI/CD adalah perubahan cara berpikir dalam pengembangan perangkat lunak.
Tujuan akhirnya bukan hanya:
Deploy lebih cepat
melainkan:
Deploy lebih aman
Deploy lebih konsisten
Deploy lebih terukur
Deploy lebih sering
Deploy dengan risiko minimal
Ketika Git, Docker, dan Jenkins digunakan dengan benar, bahkan tim kecil dapat memiliki proses delivery yang setara dengan organisasi teknologi yang jauh lebih besar.
Published by Nirantara
Nirantara is an Indonesian Enterprise AI company specializing in Enterprise AI, RAG, Intelligent Search, and AI Automation. Article written by jsturana.