In our first post, I demonstrated how to setup Drone-CI, Gitea and Postgres on Kubernetes. In this post we will setup our first Git repository on Gitea, add our SSH key, push our application code to git and setup our first CI/CD Pipeline.

SSH Key for Gitea

In order to clone and push to our repository we will need to create a SSH key first:

$ ssh-keygen -b 2048 -f ~/.ssh/civo -t rsa -q -N ""

The copy the contents of your public key (which we will paste in the gitea ssh user interface)

$ cat ~/.ssh/civo.pub
# should start like this
ssh-rsa AAAAB..............3qF7

Head over to Gitea, from the dashboard:

13FBAE30-C1E9-4370-8AA4-8C6EB2A15B8A

Select your profile, then select settings:

9C1A2755-97EE-4460-98B3-FA791FF1D7BE

From the SSH tab, add a new key and provide the public key's contents:

4A17E448-D040-483A-876F-FC700DA3891B

Go back to the dashboard and create a "New Repository", in this example my repository name is "cicd-on-civo":

649F7007-7768-4CE7-A647-3F52135EBB0F

After the repository has been created, it should look like this:

AAE94909-65BA-4E02-A1C8-0D00841B3C9E

Clone the Git Repository

Now we will clone the repository on our terminal, first add the SSH key to your ssh-agent:

$ eval $(ssh-agent -t 43200)
$ ssh-add ~/.ssh/civo

From the clone tab on the right, select SSH and copy the address:

image

Now clone the repository:

$ git clone ssh://[email protected]:2222/rbekker87/cicd-on-civo.git
Cloning into 'cicd-on-civo'...

Commit Changes to Gitea

Change into the repository:

$ cd cicd-on-civo/

Now we will edit the README.md:

$ vim README.md

And add some content:

A6457201-8BD2-4A58-BCE5-D5530D8C73E7

Add and Commit your changes, then push to git:

$ git add README.md
$ git commit -m "Update readmeā€
$ git push origin master

Once you head back to Gitea, you will see the changes that we pushed:

A08B749A-525E-4180-B115-CE900D33E3F0

If we look at the commit:

6C6668C7-C039-41AF-9040-B255DA041E83
Git Commit in Gitea

Drone Pipeline

Now let's add our first basic drone pipeline, which will be in a file named .drone.yml

$ touch .drone.yml

Our pipeline will consist of a dummy test, build and deploy step. We will share a runtime volume to persist the data between the steps, and I am also adding custom clone step that skips tls verification (just for the demo)

$ vim .drone.yml
kind: pipeline
name: basic-example
type: docker

clone:
  disable: true

steps:
- name: skip_tls_clone
  image: plugins/git
  settings:
    depth: 10
    skip_verify: true

- name: test
  image: busybox
  commands:
  - echo "this is a dummy test step"

- name: build
  image: busybox
  commands:
  - echo "this is a dummy build step"
  - echo "dummy artifact" > /tmp/runtime-volume/data.txt
  volumes:
  - name: runtime-volume
    path: /tmp/runtime-volume

- name: deploy
  image: busybox
  commands:
  - echo "this is a dummy deploy step"
  - cat /tmp/runtime-volume/data.txt
  volumes:
  - name: runtime-volume
    path: /tmp/runtime-volume

volumes:
  - name: runtime-volume
    temp: {}

Commit the file to git:

$ git add .drone.yml
$ git commit -m "Add basic pipeline"
$ git push origin master

Now when we head over to Drone and we hit the "Sync" button, we should see our git repository:

image

Select "Activate" and "Activate Repository", which will bring you to this section, confirm your changes and select "Save":

image

Now create a dummy commit, so that we can trigger our pipeline to start:

$ echo "1" > trigger
$ git add trigger
$ git commit -m "Trigger pipeline"
$ git push origin master

Then when we look at Drone, we can see the pipeline has been triggered:

image
Drone CI Triggered Pipeline

When a pipeline has succeeded, it should look like this:

drone-pipeline-status

For example the build step, you can see that we are writing content to a file in our shared volume that is shared between steps:

Drone CI Build Step

And the deploy step, you can see we are reading from that shared volume:

Drone CI Pipeline Deploy Step

Thanks

This was a basic example on how to setup your first git repository on gitea and how to setup a very basic pipeline with drone and how to trigger your drone pipeline on a git commit.

In the future I will post more tutorials on drone to showcase a more useful ci/cd pipeline, how the secrets work, how to notify you on slack if your pipeline succeeded and showcasing more of the drone plugins.

I really like drone, it's super lightweight and has a ton of plugins that allows you to do pretty much anything.