Self-hosted CI/CD mulai banyak diadopsi untuk menghindari batasan platform seperti GitHub Actions, antara lain build time limit dan runner yang sering sibuk pada jam puncak. Solusi umum: Gitea (self-hosted Git) + Drone CI. Setup sendiri, unlimited builds, seluruhnya berjalan di VPS yang sama.
Panduan ini mencakup instalasi, konfigurasi, contoh pipeline nyata, dan praktik terbaik yang relevan untuk production.
Kenapa Gitea + Drone, Bukan Gitea Actions?
Gitea memiliki built-in Actions (kompatibel syntax GitHub Actions), namun terdapat beberapa pertimbangan:
- Resource usage — Actions runner butuh ~256MB idle, Drone hanya ~80MB.
- Cache management — Gitea Actions tidak memiliki built-in cache; perlu setup external cache (minio/s3). Drone memiliki built-in volume cache.
- Secrets management — Drone lebih matang, mendukung per-branch dan pull request.
Rekomendasi: Drone untuk VPS di bawah 4GB RAM, dan Gitea Actions jika sudah familiar syntax GitHub Actions dan ingin menghindari pemeliharaan 2 service.
Setup Drone CI
# docker-compose.drone.yml
services:
drone-server:
image: drone/drone:2
ports:
- "3080:80"
- "3443:443"
volumes:
- drone_data:/data
environment:
- DRONE_GITEA_SERVER=https://git.example.com
- DRONE_GITEA_CLIENT_ID=${GITEA_CLIENT_ID}
- DRONE_GITEA_CLIENT_SECRET=${GITEA_CLIENT_SECRET}
- DRONE_RPC_SECRET=${DRONE_SECRET}
- DRONE_SERVER_HOST=ci.example.com
- DRONE_SERVER_PROTO=https
- DRONE_USER_CREATE=username:admin,admin:true
- DRONE_DATABASE_DATASOURCE=/data/database.sqlite
drone-runner:
image: drone/drone-runner-docker:1
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
- DRONE_RPC_PROTO=https
- DRONE_RPC_HOST=ci.example.com
- DRONE_RPC_SECRET=${DRONE_SECRET}
- DRONE_RUNNER_CAPACITY=2
- DRONE_RUNNER_NAME=runner-1
Penting: DRONE_RUNNER_CAPACITY=2 — maksimal 2 build berjalan simultan. Lebih dari itu, resource VPS 4GB dapat jebol.
Pipeline Real: Build + Test + Deploy
# .drone.yml
kind: pipeline
type: docker
name: build-and-deploy
trigger:
branch:
- main
- develop
steps:
- name: install-deps
image: node:20-alpine
commands:
- npm ci --production=false
depends_on: []
- name: lint-and-test
image: node:20-alpine
commands:
- npm run lint
- npm run test:ci
depends_on: [install-deps]
- name: build
image: node:20-alpine
commands:
- npm run build
depends_on: [lint-and-test]
- name: docker-build
image: plugins/docker
settings:
repo: registry.example.com/myapp
tags: ["latest", "${DRONE_COMMIT_SHA:0:8}"]
registry: registry.example.com
username:
from_secret: registry_user
password:
from_secret: registry_pass
depends_on: [build]
- name: deploy
image: alpine:3.19
commands:
- apk add --no-cache openssh-client
- ssh -o StrictHostKeyChecking=no deploy@server "
docker pull registry.example.com/myapp:latest &&
docker compose -f /opt/myapp/docker-compose.yml up -d"
depends_on: [docker-build]
when:
branch: main
Pipeline ini: install deps → lint & test → build → Docker build → deploy ke production. Total waktu ~8 menit untuk project berukuran menengah (Node.js + Docker build).
Optimasi Cache Agar Cepat
Agar tidak mengunduh node_modules tiap build, gunakan Drone volume cache:
kind: pipeline
type: docker
name: optimized-build
volumes:
- name: cache
host:
path: /tmp/drone-cache
steps:
- name: restore-cache
image: meltwater/drone-cache
settings:
restore: true
bucket: node_modules
mount:
- node_modules
volumes:
- name: cache
- name: build
image: node:20-alpine
commands:
- npm ci --production=false
- npm run build
- name: rebuild-cache
image: meltwater/drone-cache
settings:
rebuild: true
bucket: node_modules
mount:
- node_modules
volumes:
- name: cache
when:
status: [success]
Dengan cache, build kedua turun dari 8 menit menjadi 2.5 menit karena node_modules tidak perlu diunduh ulang.
Praktik Terbaik
- SQLite vs Postgres: SQLite cukup untuk <10 user dan <5 proyek. Lebih dari itu, gunakan Postgres.
- Log rotation: Setup Docker log rotation di compose:
max-size: 10m max-file: 3. - Secrets: Jangan pernah menggunakan
environmentlangsung di compose; gunakanfrom_secretdi .drone.yml. - Self-signed registry certificate: Inject CA cert ke runner container jika registry menggunakan self-signed cert.
💬 Komentar (0)
Belum ada komentar. Jadilah yang pertama! 💬