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:
Select your profile, then select settings:
From the SSH tab, add a new key and provide the public key's contents:
Go back to the dashboard and create a "New Repository", in this example my repository name is "cicd-on-civo":
After the repository has been created, it should look like this:
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:
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:
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:
If we look at the commit:
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:
Select "Activate" and "Activate Repository", which will bring you to this section, confirm your changes and select "Save":
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:
When a pipeline has succeeded, it should look like this:
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:
And the deploy step, you can see we are reading from that shared volume:
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.
Comments