Woodpecker CI @ Codeberg

What is this article about?

Woodpecker is a server application which provides automated testing and build functionality for Continuous Integration (CI) of software. Woodpecker is a fork of the Drone CI from back in 2019 when Drone was open source. After that Drone went in a different direction where in the meantime essential parts of the Drone software (e.g. Drone runners) are not available with a FOSS compliant license any more. So in simple words Woodpecker is the open source alternative to Drone.io.

This article will show how to install and configure the woodpecker docker containers and how to configure Codeberg (or any other Gitea based site) to automatically use these containers for CI.

Before Woodpecker Version 0.14.0 the server needed user cridentials (username & password) to connect to Codeberg. Since Version 0.14.0 an OAuth2 authentication method is used. This article addresses Version 0.14.0 and higher.

Prerequisites

  • docker and docker-compose installed on your server
  • A domain name for your server (e.g. woodpecker.example.com)
  • Working Traefik reverse proxy (I use it in this example but port 8000 could as well be exported instead or another reverse proxy (like NGINX) could be used)
  • Codeberg account (its free)

Create OAuth2 application

  • Navigate to Codeberg.
  • Once you are logged in enter the Settings page.
  • On the “Applications” tab you find a form to “Create a new OAuth2 Application” where you fill in an “Application Name” (can be any name) and the “Redirect URI”. For the “Redirect URI” use the Woodpecker Server URI followed by /authorize e.g. https://woodpecker.example.com/authorize.
  • When you press “Create” you will get a Client ID and a Client Secret. Copy it since you will need in the docker-compose.yml file.

Prepare woodpecker containers

Let’s create a folder and within a docker-compose.yml like the following …

version: '3'

services:
  drone-server:
    image: woodpeckerci/woodpecker-server:v0.14.0
    networks:
      - woodpecker
      - web
    volumes:
      - /var/lib/drone:/var/lib/drone/
    environment:
      - DRONE_OPEN=true
      - DRONE_HOST={your woodpecker domain including "https"}
      - DRONE_GITEA=true
      - DRONE_GITEA_URL=https://codeberg.org
      - DRONE_GITEA_CLIENT={OAuth2 Client ID}
      - DRONE_GITEA_SECRET={OAuth2 Client Secret}
      - DRONE_SECRET={Random key for the communication to the agent}

    labels:
      - "traefik.docker.network=web"
      - "traefik.enable=true"
      - "traefik.http.routers.woodpecker.rule=Host(`{your woodpecker domain}`)"
      - "traefik.http.routers.woodpecker.entrypoints=https"
      - "traefik.http.routers.woodpecker.tls=true"
      - "traefik.http.routers.woodpecker.tls.certresolver=letsencrypt"
      - "traefik.http.services.woodpecker.loadbalancer.server.port=8000"
      - "traefik.http.services.woodpecker.loadbalancer.server.scheme=http"
  drone-agent:
    image: woodpeckerci/woodpecker-agent:v0.14.0
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    depends_on:
      - drone-server
    networks:
      - woodpecker
    environment:
      - DRONE_SERVER=drone-server:9000
      - DRONE_SECRET={Random key for the communication to the agent - same as above}
      - DRONE_MAX_PROCS=1

networks:
  web:
    external: true
  woodpecker:

Replace {your woodpecker domain} with your domain name. The format shall be “https://woodpecker.example.com

The random key could be any string or you create one …

openssl rand -hex 32 

The database with login infos and build results goes into “/var/lib/drone” in this example. Of course your are free to change it, use a docker volume or store it within the container (which will be replaced once you recreate your container).

That’s it … next start the container

docker-compose up 

Connect woodpecker with Codeberg

  • Use your prefered browser and navigate to your woodpecker server (use the domain configured before e.g. https://woodpecker.example.com)
  • You will get redirected to Codeberg and if you are not logged in alreade have to enter your Codeberg login credentials into the login page.
  • Next you have to authorize woodpecker to access your data. This is necessary for woodpecker to set and change webhooks in the repositories.
  • Enable the repository your would like to use woodpecker upon which will create a webhook in your Codeberg repository.

Finished

Woodpecker is now set up. You can adapt the Woodpecker settings as needed and it will change the webhooks in Codeberg in the background.