Zk | gitea-6

Gitea and GoCD

Introduction

In the process of developing and releasing software, one of the most useful tools at a developer’s disposal is a solution that performs continuous integration and continuous deployment, or CI/CD.

Continuous integration (CI) refers to the practice of multiple developers merging their changes to a codebase back into the main branch often, perhaps daily or even more frequently, relying on smaller chunks of work that are more easily reviewed to and tested during the process of development. In order to ensure that these changes don’t leave the main branch in a broken state, a tool that helps with continuous integration will often include functionality that runs test suites within the software package. When a developer proposes a merge of their work back into the main branch, the tests will run automatically and report back whether or not they pass, which may mean that the code is not ready to land.

Continuous deployment or continuous delivery (CD) refers to the idea that changes to code — whether they’re security patches, bug fixes, or new features — be released quickly and seamlessly to the end users of the application. In the case of applications that the user runs, this will mean a frequent release schedule, offering incremental improvements to the software they are using. In the case of a service such as a website, this will mean frequent deployments of the new features in the code to the site so that the user’s experience is continuously improving.

There are several tools that can help with CI/CD. These run as their own web services, which work with many source code management (SCM) systems to perform these tasks automatically. GoCD is one such solution, that provides a way of executing pipelines — sets of steps that the service will run through such as building the software and running tests — that are described in the code itself. GoCD is a full-featured CI/CD tool with a flexible, declarative pipeline syntax that allows you to accomplish many tasks.

This tutorial aims to show how GoCD can integrate with the source code management tool Gitea in order to offer fully self-hosted solutions for SCM and CI/CD. You will be connecting GoCD with Gitea, and creating a sample project for GoCD to run tests on in order to see how the two services work together.

Prerequisites

To complete this tutorial, you will need the following:

Once you have these steps complete, you can continue installing GoCD on your new server.

Step 1 — Installing GoCD

There are several ways to install GoCD. As a Java binary, it is fine to run on its own, but this makes keeping the service up to date more difficult. You can also install it in a Docker container, which is a good way to keep the server containerized if you are running multiple applications on a single server.

For the purposes of this tutorial, however, we will be installing the service via the APT repository. This allows easier updates and lets the service run without the overhead of a Docker container.

Installing the GoCD server

To begin, add the APT source to the sources list:

echo "deb https://download.gocd.org /" | sudo tee /etc/apt/sources.list.d/gocd.list
curl https://download.gocd.org/GOCD-GPG-KEY.asc | sudo apt-key add -
sudo apt-get update

These commands will first add the repository like to a new file in /etc/apt/sources.list.d/gocd.list, then fetch the GoCD PGP key in order to verify the install. Finally, it will update the list of cached package information.

From here, install the GoCD server using APT:

sudo apt install go-server

Installing the GoCD Agent

Every instance of GoCD needs at least one agent. Agents are the mechanism by which the server runs pipelines. They spin up an environment in which to execute the commands specified within the pipeline, and once they are finished running those commands, they clean up the environment.

As before, there are several different ways to install agents, each with their own benefits and drawbacks. For instance, installing with Docker will allow multiple agents to be running at a time and is suitable for multiple agents running at the same time. This may be preferable if you foresee running multiple pipelines concurrently. As before, you can also run agents through a Java binary downloaded from the GoCD website.

Once again, you will be using an agent installed from the APT repository that you set up earlier in this step.

sudo apt install go-agent

This will install the GoCD agent on the server and allow you to run at least one pipeline at a time.

Setting Up Your Domain Name and HTTPS

In order to view the GoCD web interface, you will need a domain name pointed at your server as mentioned in the prerequisites. Once you have that DNS record properly in place, you will need to open the firewall ports to allow HTTP(S) connections:

sudo ufw allow 

edit a configuration file that the GoCD agent has installed in order to listen for requests on the proper address and ports.

Open the configuration file for editing. The following example uses `nano`. This file will contain environment variables that `go-server` relies on for its operation:

```command
nano /usr/share/go-server/wrapper-config/wrapper-properties.conf

Step 2 — Hooking GoCD Up to Gitea

Step 3 — Setting Up a Pipeline on GoCD

Conclusion