DEV Community

Cover image for Self-hosted Continuous Delivery that doesn't cost a fortune 💰 - Part 1
Łukasz Wolnik
Łukasz Wolnik

Posted on

17 8

Self-hosted Continuous Delivery that doesn't cost a fortune 💰 - Part 1

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
Enter fullscreen mode Exit fullscreen mode

Alt Text

on your dev machine.

Alt Text

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.

Alt Text

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
Enter fullscreen mode Exit fullscreen mode

Press Ctrl-C to quit.

Below will allow your non-root user to access Docker.

sudo usermod -aG docker yourusername
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Set up a password for your Traefik dashboard using apache2-utils.

sudo apt-get install apache2-utils
htpasswd -Bc password.txt yourusername
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode
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"
Enter fullscreen mode Exit fullscreen mode
sudo docker network create web
touch acme.json
chmod 600 acme.json
Enter fullscreen mode Exit fullscreen mode

Run Traefik:

vim docker-compose.yml
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Run Traefik

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

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:

Alt Text

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.

[1] https://www.digitalocean.com/community/tutorials/how-to-use-traefik-as-a-reverse-proxy-for-docker-containers-on-ubuntu-18-04

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

Top comments (1)

Collapse
 
caiadomino profile image
caiadomino

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.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay