CICD Pipelines! <3
In this post I will show you how to setup a cicd pipeline using drone to build a jekyll site and deploy to docker swarm.
Environment Overview
Jekyll’s Codebase: Our code will be hosted on Github (I will demonstrate how to set it up from scratch)
Secret Store: Our secrets such as ssh key, swarm host address etc will be stored in drones secrets manager
Docker Swarm: Docker Swarm has Traefik as a HTTP Loadbalancer
Drone Server and Agent: If you dont have drone, you can setup drone server and agent on docker or have a look at cloud.drone.io
Workflow:
1 2 3 4 5 |
|
Install Jekyll Locally
Install Jekyll locally, as we will use it to create the initial site. I am using a mac, so I will be using brew
. For other operating systems, have a look at this post.
I will be demonstrating with a weightloss blog as an example.
Install jekyll:
1
|
|
Go ahead and create a new site which will host the data for your jekyll site:
1
|
|
Create a Github Repository
First we need to create an empty github repository, in my example it was github.com/ruanbekker/blog-weightloss.git
. Once you create the repo change into the directory created by the jekyll new
command:
1
|
|
Now initialize git, set the remote, add the jekyll data and push to github:
1 2 3 4 5 |
|
You should see your data on your github repository.
Create Secrets on Drone
Logon to the Drone UI, sync repositories, activate the new repository and head over to settings where you will find the secrets section.
Add the following secrets:
1 2 3 4 5 6 7 8 |
|
You should see the following:
Add the Drone Config
Drone looks from a .drone.yml
file in the root directory for instructions on how to do its tasks. Lets go ahead and declare our pipeline:
1
|
|
And populate the drone config:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
Notifications?
If you want to be notified about your builds, you can add a slack notification step as the last step.
To do that, create a new webhook integration, you can follow this post for a step by step guide. After you have the webhook, go to secrets and create a slack_webhook
secret.
Then apply the notification step as shown below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Based on the status, you should get a notification similar like this:
Add the Docker Compose
Next we need to declare our docker compose file which is needed to deploy our jekyll service to the swarm:
1
|
|
And populate this info (just change the values for your own environment/settings):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
Push to Github
Now we need to push our .drone.yml
and docker-compose.yml
to github. Since the repository is activated on drone, any push to master will trigger the pipeline, so after this push we should go to drone to look at our pipeline running.
Add the untracked files and push to github:
1 2 3 4 |
|
As you head over to your drone ui, you should see your pipeline output which will look more or less like this (just look how pretty it is! :D )
Test Jekyll
If your deployment has completed you should be able to access your application on the configured domain. A screenshot of my response when accessing Jekyll:
Absolutely Amazingness! I really love drone!