You’ve been asked to stand up a CI for a few repositories. Drone’s quickstart is honest: a single docker run, an OAuth app, and you have green checks in fifteen minutes. The trap shows up a quarter later when “a few repos” becomes “every push and every PR” — the runner host swaps under load, docker.sock is mounted into every pipeline, the OAuth secret has been pasted into shell history three times, and the Drone server is exposed on :80 without TLS because certbot was always “next sprint”. The CI either melts or becomes the easiest path to root the build infrastructure.
What’s happening
A Drone deployment that is actually production-ready needs more than the quickstart. The server runs behind nginx with a Let’s Encrypt cert and HSTS; the OAuth secret pair lives in a root-owned /etc/drone/server.env, not in shell history; runners run on their own systemd units with LimitNOFILE=64000 and an explicit DRONE_RUNNER_CAPACITY that matches host cores; the docker runner uses a dedicated drone user in the docker group, and pipelines that need root containers are flagged trusted per-repo, not globally; webhooks are signed; and the GHE/Gitea hostname is validated before the first build is allowed. The docker daemon needs the same care as any prod host — log rotation, sysctl tuning, unattended-upgrades — because it builds the artifacts that go to production.
How to verify
After install, the listeners should look like this:
ss -lntp | grep -E ':(80|443|3000)\b'
# 127.0.0.1:3000 drone-server (loopback only — nginx fronts it)
# 0.0.0.0:80 nginx (HTTP -> HTTPS redirect)
# 0.0.0.0:443 nginx (TLS)
Drone server health should answer 200:
curl -fsS https://drone.example.com/healthz
And the runner should appear as a registered agent on the Drone server, with capacity reflecting what was provisioned:
docker logs drone-runner-docker --tail 20 | grep -E 'capacity|registered|polling'
# polling the remote server
# capacity 4
If the runner logs “401 Unauthorized” or “no such host”, the shared DRONE_RPC_SECRET or DRONE_RPC_HOST is wrong — fix that before any pipeline runs.
The fix
Save the script below as /root/setup-drone-ubuntu22.sh, then run it. It runs on a fresh Ubuntu 22.04 host: apt update, docker engine + compose plugin, unattended-upgrades, sysctl/FD tuning, SSH hardening, a dedicated drone user, nginx + certbot, an OAuth-ready Compose file for the server, a separate Compose file for the docker runner, systemd units wrapping each Compose stack, and a listener wait loop before declaring success.
#!/usr/bin/env bash
set -euo pipefail
### Ubuntu 22.04 Drone CI clean host installer
### Drone server + docker runner via Docker Compose
### Keeps root SSH key login enabled
### Disables SSH password login
### Enables unattended-upgrades for security
### nginx reverse proxy with Let's Encrypt
### No local backups; assumes VM-level backup
if [[ "$(id -u)" -ne 0 ]]; then
echo "Run as root."
exit 1
fi
: "${DRONE_DOMAIN:?Set DRONE_DOMAIN (e.g. drone.example.com)}"
: "${DRONE_GIT_PROVIDER:?Set DRONE_GIT_PROVIDER to one of: gitea | github}"
: "${DRONE_GIT_SERVER:?Set DRONE_GIT_SERVER (e.g. https://git.example.com or https://github.com)}"
: "${DRONE_OAUTH_CLIENT_ID:?Set DRONE_OAUTH_CLIENT_ID}"
: "${DRONE_OAUTH_CLIENT_SECRET:?Set DRONE_OAUTH_CLIENT_SECRET}"
: "${DRONE_USER_FILTER:?Set DRONE_USER_FILTER (comma-separated admin usernames)}"
: "${LE_EMAIL:?Set LE_EMAIL}"
DRONE_RPC_SECRET="$(openssl rand -hex 32)"
RUNNER_CAPACITY="${RUNNER_CAPACITY:-4}"
echo
echo "========================================"
echo "Drone CI Ubuntu 22.04 Setup"
echo "Domain: ${DRONE_DOMAIN}"
echo "Git provider: ${DRONE_GIT_PROVIDER}"
echo "========================================"
echo
export DEBIAN_FRONTEND=noninteractive
echo "==> Updating base OS"
apt-get update
apt-get -y upgrade
apt-get -y install \
ca-certificates curl gnupg lsb-release \
vim chrony fail2ban unattended-upgrades \
iproute2 lsof tcpdump dnsutils tar gzip unzip \
nginx
echo "==> Enabling time sync"
systemctl enable --now chrony
timedatectl set-ntp true
echo "==> Applying sysctl tuning"
cat > /etc/sysctl.d/99-drone.conf <<'SYSCTL'
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
net.core.somaxconn = 4096
net.core.netdev_max_backlog = 250000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_syncookies = 1
net.ipv4.ip_local_port_range = 10240 65535
kernel.dmesg_restrict = 1
kernel.kptr_restrict = 2
fs.file-max = 2097152
fs.inotify.max_user_watches = 524288
fs.inotify.max_user_instances = 512
SYSCTL
modprobe tcp_bbr || true
echo tcp_bbr > /etc/modules-load.d/bbr.conf
sysctl --system
echo "==> Setting file limits"
cat > /etc/security/limits.d/99-drone.conf <<'LIMITS'
* soft nofile 64000
* hard nofile 64000
root soft nofile 64000
root hard nofile 64000
LIMITS
echo "==> Hardening SSH"
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak.$(date +%F-%H%M%S)
set_sshd_option() {
local key="$1"
local value="$2"
if grep -qE "^[#[:space:]]*${key}[[:space:]]+" /etc/ssh/sshd_config; then
sed -i "s|^[#[:space:]]*${key}[[:space:]].*|${key} ${value}|" /etc/ssh/sshd_config
else
echo "${key} ${value}" >> /etc/ssh/sshd_config
fi
}
set_sshd_option PermitRootLogin prohibit-password
set_sshd_option PasswordAuthentication no
set_sshd_option PubkeyAuthentication yes
set_sshd_option KbdInteractiveAuthentication no
set_sshd_option X11Forwarding no
set_sshd_option ClientAliveInterval 300
set_sshd_option ClientAliveCountMax 2
set_sshd_option MaxAuthTries 4
sshd -t
systemctl restart ssh
echo "==> Configuring fail2ban"
mkdir -p /etc/fail2ban/jail.d
cat > /etc/fail2ban/jail.d/sshd.local <<'FAIL2BAN'
[sshd]
enabled = true
port = ssh
backend = systemd
maxretry = 4
findtime = 10m
bantime = 1h
FAIL2BAN
systemctl enable --now fail2ban
echo "==> Enabling unattended-upgrades for security"
cat > /etc/apt/apt.conf.d/20auto-upgrades <<'AUTOUPG'
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
APT::Periodic::AutocleanInterval "7";
AUTOUPG
echo "==> Installing Docker engine and compose plugin"
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" \
> /etc/apt/sources.list.d/docker.list
apt-get update
apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
cat > /etc/docker/daemon.json <<'DOCKERJSON'
{
"log-driver": "json-file",
"log-opts": { "max-size": "50m", "max-file": "5" },
"live-restore": true,
"default-ulimits": { "nofile": { "Name": "nofile", "Hard": 64000, "Soft": 64000 } }
}
DOCKERJSON
systemctl enable --now docker
systemctl restart docker
echo "==> Creating drone system user"
getent passwd drone >/dev/null || \
useradd --system --create-home --home-dir /var/lib/drone --shell /bin/bash drone
usermod -aG docker drone
install -d -o drone -g drone -m 0750 /var/lib/drone/server /var/lib/drone/runner
install -d -o root -g root -m 0750 /etc/drone
echo "==> Writing /etc/drone/server.env"
cat > /etc/drone/server.env <<ENV
DRONE_SERVER_HOST=${DRONE_DOMAIN}
DRONE_SERVER_PROTO=https
DRONE_RPC_SECRET=${DRONE_RPC_SECRET}
DRONE_USER_FILTER=${DRONE_USER_FILTER}
DRONE_USER_CREATE=username:$(echo "${DRONE_USER_FILTER}" | cut -d',' -f1),admin:true
DRONE_DATABASE_DRIVER=sqlite3
DRONE_DATABASE_DATASOURCE=/data/database.sqlite
DRONE_LOGS_PRETTY=true
DRONE_LOGS_NOCOLOR=true
ENV
case "${DRONE_GIT_PROVIDER}" in
gitea)
cat >> /etc/drone/server.env <<ENV
DRONE_GITEA_SERVER=${DRONE_GIT_SERVER}
DRONE_GITEA_CLIENT_ID=${DRONE_OAUTH_CLIENT_ID}
DRONE_GITEA_CLIENT_SECRET=${DRONE_OAUTH_CLIENT_SECRET}
ENV
;;
github)
cat >> /etc/drone/server.env <<ENV
DRONE_GITHUB_CLIENT_ID=${DRONE_OAUTH_CLIENT_ID}
DRONE_GITHUB_CLIENT_SECRET=${DRONE_OAUTH_CLIENT_SECRET}
ENV
;;
*)
echo "Unsupported DRONE_GIT_PROVIDER: ${DRONE_GIT_PROVIDER}"
exit 1
;;
esac
chmod 600 /etc/drone/server.env
chown root:root /etc/drone/server.env
echo "==> Writing /etc/drone/runner.env"
cat > /etc/drone/runner.env <<ENV
DRONE_RPC_PROTO=https
DRONE_RPC_HOST=${DRONE_DOMAIN}
DRONE_RPC_SECRET=${DRONE_RPC_SECRET}
DRONE_RUNNER_CAPACITY=${RUNNER_CAPACITY}
DRONE_RUNNER_NAME=$(hostname)-docker
DRONE_LOGS_PRETTY=true
DRONE_LOGS_NOCOLOR=true
ENV
chmod 600 /etc/drone/runner.env
echo "==> Writing /var/lib/drone/server/compose.yml"
cat > /var/lib/drone/server/compose.yml <<'COMPOSE'
services:
drone-server:
image: drone/drone:2
container_name: drone-server
restart: unless-stopped
env_file: /etc/drone/server.env
ports:
- "127.0.0.1:3000:80"
volumes:
- /var/lib/drone/server/data:/data
ulimits:
nofile: 64000
COMPOSE
echo "==> Writing /var/lib/drone/runner/compose.yml"
cat > /var/lib/drone/runner/compose.yml <<'COMPOSE'
services:
drone-runner-docker:
image: drone/drone-runner-docker:1
container_name: drone-runner-docker
restart: unless-stopped
env_file: /etc/drone/runner.env
volumes:
- /var/run/docker.sock:/var/run/docker.sock
ulimits:
nofile: 64000
COMPOSE
echo "==> Installing systemd units"
cat > /etc/systemd/system/drone-server.service <<'UNIT'
[Unit]
Description=Drone CI server (Compose)
Requires=docker.service
After=docker.service network-online.target
Wants=network-online.target
[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/var/lib/drone/server
ExecStart=/usr/bin/docker compose up -d
ExecStop=/usr/bin/docker compose down
LimitNOFILE=64000
[Install]
WantedBy=multi-user.target
UNIT
cat > /etc/systemd/system/drone-runner-docker.service <<'UNIT'
[Unit]
Description=Drone CI docker runner (Compose)
Requires=docker.service
After=docker.service drone-server.service network-online.target
Wants=network-online.target
[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/var/lib/drone/runner
ExecStart=/usr/bin/docker compose up -d
ExecStop=/usr/bin/docker compose down
LimitNOFILE=64000
[Install]
WantedBy=multi-user.target
UNIT
systemctl daemon-reload
systemctl enable --now drone-server
systemctl enable --now drone-runner-docker
echo "==> Waiting for Drone server on 127.0.0.1:3000"
for i in {1..60}; do
if ss -lntp | grep -q '127.0.0.1:3000'; then
break
fi
sleep 1
done
if ! ss -lntp | grep -q '127.0.0.1:3000'; then
echo "Drone server failed to bind on 127.0.0.1:3000"
systemctl status drone-server --no-pager -l || true
docker logs drone-server --tail 100 || true
exit 1
fi
echo "==> Installing certbot and obtaining cert"
apt-get -y install certbot python3-certbot-nginx
cat > /etc/nginx/sites-available/drone.conf <<NGINX
server {
listen 80;
listen [::]:80;
server_name ${DRONE_DOMAIN};
location /.well-known/acme-challenge/ { root /var/lib/letsencrypt; }
location / { return 301 https://\$host\$request_uri; }
}
NGINX
ln -sf /etc/nginx/sites-available/drone.conf /etc/nginx/sites-enabled/drone.conf
rm -f /etc/nginx/sites-enabled/default
mkdir -p /var/lib/letsencrypt
nginx -t
systemctl enable --now nginx
systemctl reload nginx
certbot certonly --webroot -w /var/lib/letsencrypt \
-d "${DRONE_DOMAIN}" --email "${LE_EMAIL}" \
--agree-tos --no-eff-email --non-interactive
cat > /etc/nginx/sites-available/drone.conf <<NGINX
server {
listen 80;
listen [::]:80;
server_name ${DRONE_DOMAIN};
location /.well-known/acme-challenge/ { root /var/lib/letsencrypt; }
location / { return 301 https://\$host\$request_uri; }
}
server {
listen 443 ssl;
listen [::]:443 ssl;
http2 on;
server_name ${DRONE_DOMAIN};
ssl_certificate /etc/letsencrypt/live/${DRONE_DOMAIN}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/${DRONE_DOMAIN}/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
client_max_body_size 256m;
location / {
proxy_pass http://127.0.0.1:3000;
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 https;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 3600s;
}
}
NGINX
nginx -t
systemctl reload nginx
systemctl enable --now certbot.timer
echo
echo "========================================"
echo "DONE"
echo "========================================"
echo
echo "Kernel:"
uname -r
echo
echo "Services:"
systemctl is-active docker drone-server drone-runner-docker nginx chrony fail2ban || true
echo
echo "Listeners:"
ss -lntp | grep -E ':(80|443|3000)\b' || true
echo
echo "Web UI:"
echo "https://${DRONE_DOMAIN}/"
echo
echo "DRONE_RPC_SECRET (stored in /etc/drone/server.env and /etc/drone/runner.env)"
echo "First admin user (from DRONE_USER_FILTER):"
echo " $(echo "${DRONE_USER_FILTER}" | cut -d',' -f1)"
echo
echo "Final step: sign in at https://${DRONE_DOMAIN}/ with the OAuth provider."
echo "Then in Settings -> Activate, turn on the repos you want CI on."
Make it executable and run it:
chmod 700 /root/setup-drone-ubuntu22.sh
DRONE_DOMAIN=drone.example.com \
DRONE_GIT_PROVIDER=gitea \
DRONE_GIT_SERVER=https://git.example.com \
DRONE_OAUTH_CLIENT_ID=... \
DRONE_OAUTH_CLIENT_SECRET=... \
DRONE_USER_FILTER=alice,bob \
LE_EMAIL=ops@example.com \
/root/setup-drone-ubuntu22.sh
After the first OAuth login, activate only the repos the team actually wants Drone to watch — the webhook-on-every-repo default is a noise source the audit log will not thank you for. Host-level backups are out of scope: /var/lib/drone/server/data/database.sqlite is the only stateful path, and the VM is assumed to have snapshot/backup at the cloud layer. For larger fleets, swap SQLite for postgres bound to localhost, and add an exec runner unit for jobs that need to run outside Docker.
Drone, your runner fleet, and the deploy pipelines it feeds belong to a single deployment-management surface — see Deployment management → for how we own it end-to-end, or start a conversation.