Self Hosted CICD with Gitea and Drone CI

ruanbekker

Ruan Bekker

Posted on February 11, 2020

Self Hosted CICD with Gitea and Drone CI

drone-ci

What is Drone?

Drone is a self-service continuous delivery platform which can be used for CICD pipelines, devopsy stuff which is really awesome.

With Configuration as Code, Pipelines are configured with a simple, easy‑to‑read file that you commit to your git repository such as github, gitlab, gogs, gitea etc.

Each Pipeline step is executed inside an isolated Docker container that is automatically downloaded at runtime, if not found in cache.

Show me pipelines!

A pipeline can look as easy as:

kind: pipeline

steps:
- name: test
  image: node
  commands:
  - npm install
  - npm test

services:
- name: database
  image: mysql
  ports:
  - 3306
Enter fullscreen mode Exit fullscreen mode

What are we doing?

This post will show how to setup Gitea, Drone Server and Drone Agent on a Docker host using docker-compose. The drone example in this tutorial will be very basic, but in future posts I will focus more on pipeline examples using Drone.

Components

  • Gitea: will be your self hosted git server

  • Drone Server: will be server being responsible for the web service, repositories, secrets, users, etc.

  • Drone Agent: will be the workers that runs your builds, jobs etc.

Deploy Gitea and Drone

Get the docker-compose.yml:

$ wget -O docker-compose.yml https://gist.githubusercontent.com/ruanbekker/27d2cb2e3f4194ee5cfe2bcdc9c4bf52/raw/25590a23e87190a871d70fd57ab461ce303cd286/2020.02.04-gitea-drone_docker-compose.yml
Enter fullscreen mode Exit fullscreen mode

Verify the environment variables and adjust the defaults if you want to change something, if you want your git clone ssh url to point to a dns name as well as the url for gitea, then change the following to your dns:

  gitea:
    ...
    environment:
      - ROOT_URL=http://gi.myresolvable.dns:3000
      - SSH_DOMAIN=git.myresolvable.dns
Enter fullscreen mode Exit fullscreen mode

then deploy:

$ docker-compose up -d
Enter fullscreen mode Exit fullscreen mode

Access your Stack

The default port for Gitea in this setup is port 3000:

image

Initial configuration will be pre-populated from our environment variables:

image

From the additional settings section, create your admin user (this user is referenced in our docker-compose as well)

image

Because I am using gitea as my hostname, you will be redirected to http://gitea:3000/user/login, if you don't have a host entry setup for that it will fail, but you can just replace your servers ip in the request url and it will take you to the login screen, and after logging on, you should see this screen:

image

Access drone on port 80, you will be directed to the login screen:

image

Use the same credentials that you have used to sign up with gitea, and after logging on, you should see this:

image

If ever your login does not work, just delete the drone access token on gitea (gitea:3000/user/settings/applications)

Create a Git Repository

On gitea, create a new git repository:

image

You should now see your git repository:

image

Create a new file .drone.yml with the following content:

kind: pipeline
name: hello-world
type: docker

steps:
  - name: say-hello
    image: busybox
    commands:
      - echo hello-world
Enter fullscreen mode Exit fullscreen mode

It should look like this:

image

Configure Drone

Commit the file in your git repository and head over to drone (which should be available on port 80) and select "Sync", after a couple of seconds you should see the git repository:

image

Select "Activate" and "Activate Repository", on the next screen select "Trusted", verify that the configuration file name is the same as which we created, then select save:

image

Trigger the Build

If you click on "Activity Feed" you should see a empty feed. Head back to git and commit a dummy file to trigger the build to start. I will create a file name trigger with the value as 1 for my dummy file.

After committing the file, you will see on drone that the build started:

image

When we select the build, you can see we have a clone step and the step that we defined to echo "hello-world":

image

Thank You

This was a basic introduction for gitea and drone, but I will use this post in conjunction with more gitea examples in the future.

💖 💪 🙅 🚩
ruanbekker
Ruan Bekker

Posted on February 11, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related