We use Drone CI a lot in our daily works. So its not a secret we are running instance ourselves.
We will show you how to run Drone CI on Raspberry Pi using Synpse on RPI!
Important: This will not work if your devices are not able to be accessed via an external IP address.
For this to work you might need to configure your router with a port forwarding. Which is out of scope for this blog post.
###Technologies used
Synpse for hosting and running applications anywhere
DDNS for managing DNS records for multiple DNS providers
First, what is Synpse? It’s an IoT management platform allowing devices to be managed remotely. And it has free tier for us to use. BYO-OS and docker and you are set to go!
Install Synpse agent via https://cloud.synpse.net and you are ready to deploy applications into remote devices.
it gives you CLI, Web and even SSH access to device, located anywhere in the world as long as they have internet connection.
###Domain
If you don’t own a domain, and don’t have a need for it - you can use DuckDNS to get one for you. It is very convenient online service to get free DNS names. If you want to use your own custom domain, see our other blog posts how to expose Synpse application using custom domain.
Sign-in into DuckDNS and create a domain for your application.
we go ourselfs a synpse-drone.duckdns.org domain
###Deploy DDNS
Drone CI required DNS to be present when it is running, we will setup Dynamic DNS part first.
We are going to use linuxserver docker image for DDNS client.
docker run linuxserver/ddclient ddclient --help | grep duckdns -A 10
Our example config looks like this:
1
2
3
4
5
6
7
8
9
10
11
12
# /etc/ddclient/ddclient.conf#protocol=duckdns
use=web
web=checkip.dyndns.org
daemon=60syslog=yes
ssl=yes
ttl=2# password is a token from duckdns.orgpassword=68466070-xxxx-xxxx-xxx-xxxxxxxxxx
synpse-drone
Let’s create a configuration for “CertBot” (same credentials as in DDNS). We gonna use them from the script, because all script is treated as a secret in Synpse. This script will renew the certificate on a periodic basis as certbot is not able to run as a daemon, which is required for containers:
#!/bin/sh
# Small hack script to renew "Let's Encrypt" certs each week# Once deployed in production remove --test-cert flag to generate valid certificate# doing development without this flag will get you banned from Lets Encrypt very fast!
pip install certbot_dns_duckdns
while[ : ]doecho"Renewing Let's Encrypt certs"
certbot certonly -v \
--preferred-challenges dns \
--authenticator dns-duckdns \
--email [email protected]\
--dns-duckdns-token 68466070-xxxx-xxxx-xxx-xxxxxxxxxx \
--dns-duckdns-propagation-seconds 60\
--renew-by-default \
--agree-tos \
--test-cert \
-d "synpse-drone.duckdns.org"\
-n
echo"Sleeping for 7d"
sleep 7d
done
1
synpse secret create script-cert-bot -f renew.sh
and extend our existing application. Note variables we added to the original application and change of port.
name:drone-cischeduling:type:Conditionalselectors:app:drone-cispec:containers:- name:ddnsimage:ghcr.io/linuxserver/ddclientenv:- name:TZvalue:Europe/London- name:PUIDvalue:"0"- name:PGIDvalue:"0"secrets:- name:ddns-configfilepath:/config/ddclient.confrestartPolicy:{}- name:certbot# For amd64 use certbot/certbot:latestimage:certbot/certbot:arm64v8-v1.17.0command:/run/secrets/renew.shentrypoint:- shvolumes:- /data/demo/letsencrypt:/etc/letsencrypt- /data/demo/var-lib-letsencrypt:/var/lib/letsencryptsecrets:- name:script-cert-botfilepath:/run/secrets/renew.shrestartPolicy:{}
By deploying Lets Encrypt and DDNS we will provision certificates before Drone starts, so we have them already for the next step.
Once DDNS and Let’s Encrypt is running, we are ready to deploy Drone-CI into the same application.
###Deploy Drone CI
Extend our application with Drone CI image.
Follow Drone CI Guide for github and register Github application for your CI instance.
And fill values from Github bellow in the env variables of the Drone application.
If everything done right you should be able to access Drone CI using URL. In our case it was https://synpse-drone.duckdns.org. You can skip “Let’s Encrypt” part if you don’t need TLS. But it always looks better :)
If you have any questions or suggestions, feel free to start a new discussion in our forum or drop us a line on Discord