Drone CI is a modern, lightweight continuous integration and delivery platform designed for self-hosting. Itβs a popular choice among developers and system administrators because it offers full control over the CI/CD pipeline, seamless integration with version control systems, and a highly customizable environment. In this guide, weβll walk through deploying, configuring, and managing Drone CI, focusing on Docker-based installation, reverse proxy setup with Nginx, logging, backups, updates, and leveraging its unique features.
Installing Drone CI
π¦ Docker/Docker Compose Setup
Drone CI is most commonly deployed using Docker. Below is a docker-compose.yml
file tailored for Drone CI:
version: '3'
services:
drone-server:
image: drone/drone:latest
container_name: drone-server
ports:
- "80:80" # Expose Drone on port 80
- "443:443" # For HTTPS (later configured with Nginx)
volumes:
- /var/lib/drone:/data
restart: always
environment:
- DRONE_GITEA_SERVER=https://gitea.example.com # Replace with your Gitea server URL
- DRONE_RPC_SECRET=supersecretkey # Shared secret between server and runner
- DRONE_SERVER_HOST=drone.example.com
- DRONE_SERVER_PROTO=https
- DRONE_USER_CREATE=username:admin,admin:true
networks:
- drone-network
drone-runner:
image: drone/drone-runner-docker:latest
container_name: drone-runner
restart: always
depends_on:
- drone-server
environment:
- DRONE_RPC_PROTO=https
- DRONE_RPC_HOST=drone-server
- DRONE_RPC_SECRET=supersecretkey
- DRONE_RUNNER_CAPACITY=2
networks:
- drone-network
networks:
drone-network:
driver: bridge
To deploy Drone CI, execute the following commands:
mkdir -p /opt/drone && cd /opt/drone
nano docker-compose.yml # Paste the above configuration
docker-compose up -d
This will spin up Drone CI and its runner. Replace placeholders (like the Gitea URL and domain) with your specifics.
π Manual Installation
For those who prefer manual setup on a Linux server:
- Install Docker and Docker Compose:
sudo apt update && sudo apt install -y docker.io docker-compose
- Run Drone CI using Docker:
docker run -d \
--name drone-server \
-p 80:80 \
-p 443:443 \
-v /var/lib/drone:/data \
-e DRONE_GITEA_SERVER=https://gitea.example.com \
-e DRONE_RPC_SECRET=supersecretkey \
-e DRONE_SERVER_HOST=drone.example.com \
-e DRONE_SERVER_PROTO=https \
-e DRONE_USER_CREATE=username:admin,admin:true \
drone/drone:latest
Add a runner using similar Docker commands tailored to your requirements.
Configuring Nginx as a Reverse Proxy
π Nginx Configuration
To expose Drone CI securely, configure an Nginx reverse proxy:
server {
server_name drone.example.com;
location / {
proxy_pass http://127.0.0.1:80;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
listen 80;
}
Place this configuration in /etc/nginx/sites-available/drone
and enable it:
sudo ln -s /etc/nginx/sites-available/drone /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
π SSL/TLS Setup
Secure Drone CI with Letβs Encrypt:
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d drone.example.com
This automatically configures Nginx to serve traffic over HTTPS and sets up automatic renewal for the SSL certificate.
π οΈ Testing and Reloading Nginx
Validate the Nginx configuration and reload the service:
sudo nginx -t
sudo systemctl reload nginx
Access Drone CI at https://drone.example.com
after Nginx is configured.
Logging and Debugging Drone CI
ποΈ Enabling Debug Logs
To enable debug-level logging, set the appropriate environment variable in your docker-compose.yml
:
environment:
- DRONE_LOGS_DEBUG=true
Restart the container to apply changes:
docker-compose restart drone-server
π Viewing Logs
View logs for the Drone server and runner:
docker logs -f drone-server
docker logs -f drone-runner
π οΈ Troubleshooting Common Issues
Check for:
-
Authentication errors: Ensure
DRONE_RPC_SECRET
matches between server and runner. -
Connectivity issues: Verify DNS and proxy configurations.
π€ Exporting Logs
Forward logs to an ELK stack using Dockerβs logging driver:
logging:
driver: "gelf"
options:
gelf-address: "udp://elk.example.com:12201"
Backup and Restore
ποΈ File-Based Backups
Backup the /var/lib/drone
directory, which contains all Drone data:
tar -czvf drone-backup.tar.gz /var/lib/drone
π Database Backups
If using an external database, back it up with a command like:
mysqldump -u root -p drone_db > drone_db_backup.sql
π Automated Backup Scripts
Automate backups with a cron job:
echo "0 2 * * * tar -czvf /backup/drone-$(date +\%F).tar.gz /var/lib/drone" | crontab -
Updating and Upgrading Drone CI
β¬οΈ Updating Docker Images
Pull the latest Docker images and redeploy:
docker-compose pull
docker-compose up -d
π οΈ Manual Updates
For manual installations, re-download the binary:
wget https://github.com/drone/drone/releases/latest/download/drone-server-linux-amd64
chmod +x drone-server-linux-amd64
mv drone-server-linux-amd64 /usr/local/bin/drone
Restart the application to apply updates.
π Checking for Updates
Verify the current version:
curl -s http://localhost/api/version
Leveraging Drone CIβs Unique Features
π§ Enabling APIs
Activate Droneβs API to interact programmatically:
-
Add
DRONE_SERVER_ENABLE_API=true
to your environment variables. -
Test it with
curl
:
curl -H "Authorization: Bearer <token>" https://drone.example.com/api/repos
π Advanced Configurations
Integrate with third-party tools like Slack by adding a notification plugin to your .drone.yml
file:
pipeline:
notify:
image: plugins/slack
webhook: https://hooks.slack.com/services/XXX/YYY/ZZZ
channel: '#ci-cd'
username: 'drone'
Wrapping Up
Self-hosting Drone CI provides unparalleled control over your CI/CD pipelines. From deployment to advanced configurations, this guide covered all the essential steps to help you get started. With the provided examples, you can now fully leverage Drone CI to streamline your development workflows while maintaining full data ownership. Start exploring its flexibility and power today!