Drone is a continuous integration and deployment platform that can connect to a wide variety of web-based Git repository hosting platforms including GitHub, Gitlab, Gitea/Gogs, and even BitBucket. Drone uses Docker containers to create what are called runners to serve as the testing bed for your testing/build processes. If you’re not comfortable with Docker, you may want to explore a little more before trying this. Solutions like this rely heavily on the Docker ecosystem.
The setup for most services using Docker is usually simple but Drone posed some issues for me. I’ve griped before about poor documentation and Drone was one of those projects with such lack of quality of information. I can expand more on the documentation, but I’d rather save that for another post.
This guide assumes that you’ve already set up a Gitea server using Docker and docker-compose, as well that you’re using the
nginx-proxycontainer from jwilder and the accompanying
Without further ado, let’s jump right into it.
Just so we’re all on the same page, this is the service definition in my
docker-compose.yml that I’ll be using:
For a little context, I’ll explain a few of the environment variables:
DRONE_GITEA_SERVER is the public address at which your Gitea instance can be reached. Be sure not to include a trailing slash(/) as it the connection between Gitea and Drone will fail to operate correctly.
DRONE_RUNNER_CAPACITY is how many runners you want to allow. Runners are the processes that will actually be performing the continuous integration/deployment. The more people on your server, the higher the number you’ll want to make this, also taking into consideration the amount of resources available to your server. Two runners per person should suffice for most self-hosting persons. Maybe more if the desired jobs take quite a long time.
DRONE_SERVER_HOST is the public domain at which your Drone server can be reached with
DRONE_SERVER_PROTO set to
https because we’ll be using the
I’ll explain the client ID and secret in the next section when we create those within Gitea.
VIRTUAL_PORT are the environment variables to tell nginx-proxy which domains to use for the Drone container and the internal port at which they can be reached. By default, Drone is reachable on port 80.
DRONE_USER_CREATE section will be very important for defining admin users. You need to be an admin to define whether a given repo is “trusted” or not. The trusted status allows you to mount directories directly from the host server’s filesystem. You can use your Gitea username here.
If you’re more experienced, or mildly informed about mounting the docker socket, you’ll notice that I’ve mounted it not read-only. That’s because, as I mentioned earlier, Drone will be using Docker to create runner containers.
data volume isn’t terribly important, but it’s good to have as you’ll be able to cache Docker images across container restarts.
As mentioned in the previous section, we’ll have to set up a client ID and secret. This is done in
user>Settings>Applications>Manage OAuth2 Applications. The web address for that would be https://gitea.domain.com/user/settings/applications. As you can see from the screenshot below, I’ve already created an application called
In the Application Name field you’ll want to enter a name of your choosing for the application. In the Redirect URI field you’ll want to enter exactly what I’ve written as in the screenshot, replacing the domain with your own. That https://yourdomain.com/login without a trailing slash. Then, click Create Application.
On the next screen, you’ll be given the Client ID and Client Secret. Take these values and paste them into the
docker-compose.yml file in the
DRONE_GITEA_CLIENT_SECRET sections, respectively.
Once all the information is entered into your docker-compose config, feel free to start up the Drone container with
docker-compose up -d.
Once the container is started, wait a few seconds, then open your web browser to the domain you set your Drone server to be at. If you’ve already configured the DNS records for your domain, and you’re already logged into Gitea, you’ll be presented a request for application authorization page like the following:
Click Authorize Application and you should be redirected to your Drone installation, with a list of the repositories available to you for activation. Clicking activate will activate monitoring on the selected repository, meaning you’re free to add the
.drone.yml file to said repo.
Setting up Drone with Gitea is pretty simple when you know how to do it, but when you’re brand new to the system, it takes a little bit of troubleshooting to get it really down.
Next time we’ll be tackling the Drone pipeline configuration file and how to set one up in your repository.