Overview
In this series I want to demonstrate how to set up an open-sourced, self-managed continuous delivery solution that can be run on a private server for free thanks to Drone and Traefik.
The goal is to update a web app on a live website by just running:
git push origin master
on your dev machine.
That's it! After a couple of minutes a website should be automatically updated with changes that have just been pushed to a Git repo.
Below image depicts this process from pushing a commit to serving an HTTPS website.
Requirements
You need to have a Linux server to host and run the required software. You can buy one for example from OVH.
Tech stack
The presented continuous delivery's pipeline contains:
1. GitHub
A hosted Git repo with hooks that notifies a build server about a new commit.
2. Drone
A build server that will listen to new commits, build images and push them to a Docker repo.
3. Traefik
A load balancer and a reverse proxy, that runs a Docker's image of a web app and routes a web domain foo.bar.com to a container that runs a Docker image build with Drone.
Installing Docker
To start we need a Docker running on a server.
sudo apt-get update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
sudo apt update
apt-cache policy docker-ce
sudo apt install docker-ce
sudo systemctl status docker
Press Ctrl-C
to quit.
Below will allow your non-root user to access Docker.
sudo usermod -aG docker yourusername
Installing docker-compose
sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
Installing Traefik
For more detailed installation refer to the article I based this one on [1]
Go to your home directory and create a folder:
cd ~
mkdir traefik
cd traefik
Set up a password for your Traefik dashboard using apache2-utils
.
sudo apt-get install apache2-utils
htpasswd -Bc password.txt yourusername
Open password.txt
and copy your password hash from there. You will need it in the next step.
Create a traefik.toml
file and paste below content into it:
vim traefik.toml
defaultEntryPoints = ["http", "https"]
[entryPoints]
[entryPoints.dashboard]
address = ":8080"
[entryPoints.dashboard.auth]
[entryPoints.dashboard.auth.basic]
users = ["$output_of_password.txt_file_created_above"] # ***** EDIT HERE *****
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
[api]
entrypoint="dashboard"
[acme]
email = "youremail@email.com" # ***** EDIT HERE *****
storage = "acme.json"
entryPoint = "https"
onHostRule = true
[acme.httpChallenge]
entryPoint = "http"
[docker]
domain = "docker.yourdomain.com" # ***** EDIT HERE *****
watch = true
network = "web"
sudo docker network create web
touch acme.json
chmod 600 acme.json
Run Traefik:
vim docker-compose.yml
And paste below:
version: '3'
services:
traefik:
image: traefik:1.7.6-alpine
restart: always
ports:
- "80:80"
- "443:443"
labels:
- traefik.frontend.rule=Host:traefik.foo.bar.com # ***** EDIT HERE *****
- traefik.port=8080
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./traefik.toml:/traefik.toml
- ./acme.json:/acme.json
networks:
- web
networks:
web:
external: true
Run Traefik
docker-compose up -d
Traefik Dashboard
To confirm that your Traefik installation was successful you should be able to access traefik.foo.bar.com
URL that you specified in above docker-compose.yml
file.
You should see a website like below:
Conclusion
Well done! You've got half of your continuous delivery pipeline set up. In the next article I will show how to install Drone build server and how to connect the trio: GitHub, Drone and Traefik.
Top comments (1)
To get the best web hosting solutions, approach HostSailor as it is the perfect platform for innovative hosting solutions, with 24/7 hosting support. This makes it possible to run your website with confidence.