Introduction

Welcome to our blog post on continuous integration (CI) and continuous delivery (CD)!

If you’re looking for ways to streamline your software development process, continuous integration (CI) and continuous delivery (CD) are two practices that can help. In this post, we’ll discuss the benefits of CI/CD and show you how to set up a workflow using Drone, a popular open source tool. We’ll also explain how container technology makes CI/CD possible.

What is CI/CD?

Continuous integration is a development practice that requires developers to integrate code into a shared repository frequently. Each integration can then be verified by an automated build and test process. This practice helps to ensure that the codebase is always in a stable state and that new features can be delivered to users quickly and efficiently (using continous delivery).

Continuous delivery is a software development practice that enables developers to rapidly and safely deliver new features to users. It involves a continuous process deploying code changes. This allows developers to get feedback on their code changes quickly and makes it easy to roll back changes if necessary.

What is Drone.io?

Drone.io is a cloud-based Continuous Integration and Delivery (CI/CD) platform that enables developers to build, test and deploy their code. It provides a simple and easy-to-use interface that makes it easy for developers to get started with CI/CD.

What are the benefits of using continuous integration and continuous delivery?

  • Reduced risk: By integrating code frequently, you can identify and fix errors quickly, before they have a chance to impact users.
  • Increased efficiency: Continuous integration and delivery helps to automate many of the tasks involved in software development, such as building, testing and deploying code. This can save developers a lot of time and effort.
  • Improved quality: Continuous integration and delivery can help to improve the quality of your code by automatically testing and verifying changes.
  • Faster releases: By automating the software development process, you can release new features and updates to users much faster.

How do I self host Drone.io?

Drone.io can be self-hosted on any Linux server. It requires a minimum of 2GB of RAM and 2 CPU cores. I personally host all my services using docker so here goes a docker-compose.yml for you!

Using Docker-Compose

In this example we’ll let drone connect to Gitea.

First we need to create a shared secret (to allow drone-runners to connect with drone)

openssl rand -hex 16

Output: bea26a2221fd8090ea38720fc445eca6

---
version: '3.6'

services:
  drone:
    image: drone/drone
    restart: unless-stopped
    environment:
      # https://docs.drone.io/server/provider/gitea/
      - DRONE_DATABASE_DRIVER=sqlite3 # sqlite is sufficient for me
      - DRONE_DATABASE_DATASOURCE=/data/database.sqlite
      - DRONE_GITEA_SERVER=https://gitea.your.domain/ # Gitea uses https
      - DRONE_GIT_ALWAYS_AUTH=false
      - DRONE_RPC_SECRET={SECRET-SOMETHING} # You need to replace this
      - DRONE_SERVER_PROTO=http # I have mine behind a TLS termination proxy so http is fine
      - DRONE_SERVER_HOST=drone.your.domain
      - DRONE_GITEA_CLIENT_ID= # Add your client ID from Oauth2 applications (gitea)
      - DRONE_GITEA_CLIENT_SECRET= # Add your client Ssecret from Oauth2 applications (gitea)
    ports:
       - "{external_https}:443" # Make sure those ports are accessible
       - "{external_http}:80" # if you plan on accessing drone from another machine
    volumes:
       - /var/run/docker.sock:/var/run/docker.sock
       - ./drone:/data # Replace this with a mount you like better.

  drone-runner:
    image: drone/drone-runner-docker
    restart: unless-stopped
    depends_on:
      - drone
    environment:
      - DRONE_RPC_PROTO=https # Drone is behind a TLS termination proxy for me
      - DRONE_RPC_HOST=drone.your.domain # The URL to connect to the drone server
      - DRONE_RPC_SECRET={SECRET-SOMETHING} # You need to replace this
      - DRONE_RUNNER_NAME="drone-runner"
      - DRONE_RUNNER_CAPACITY=2
    ports:
      - "{RUNNER_PORT}:3000" # Choose a runner port here.
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

How does container technology make CI/CD much easier?

Container technology is what makes CI/CD possible. By packaging code changes in containers, they can be easily and quickly deployed to production servers. Containers also provide a consistent and isolated environment for builds, ensuring that each build is reproducible.

Getting started with Drone.io on your own GIT repository!

To get started with Drone, you first need to create a .drone.yml file in the root directory of your project. This file defines your build environment and contains instructions for Drone on how to build, test, and deploy your code.

A basic .drone.yml file might look something like this:

---
pipeline:
    build:
    image: golang:1.13
    commands:
        - go build ./...
        - go test ./...
    deploy:
    image: plugins/s3
    bucket: my-bucket
    acl: public-read
    region: eu-central-1
    secret: ${S3_SECRET}
trigger:
  branch:
  - master

In this file, we’ve defined a pipeline with two steps: build and deploy. The build step will use the golang container image and run the go build and go test commands. The deploy step will use the s3 plugin to deploy our code to an Amazon S3 bucket.

We can then trigger a build by pushing our code changes to the master branch on the remote repository. Drone will automatically detect the change, build our code, and run our tests (if we had defined that). If the phases finish without errors, our code will be deployed to production.

We hope this post has given you a good overview of continuous integration/continuous delivery (CI/CD) and how you can use Drone to set up a workflow. If you have any questions, please don’t hesitate to ask in the comments section below.