89 lines
13 KiB
HTML
89 lines
13 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<title>Zk | gitea-6</title>
|
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Gentium+Plus&family=Lato&family=Ubuntu+Monodisplay=swap" />
|
|
<link rel="stylesheet" type="text/css" href="/style.css" />
|
|
<meta name="viewport" content="width=device-width" />
|
|
<meta charset="utf-8" />
|
|
</head>
|
|
<body>
|
|
<main>
|
|
<header>
|
|
<h1>Zk | gitea-6</h1>
|
|
</header>
|
|
<article class="content">
|
|
<h1 id="gitea-and-gocd">Gitea and GoCD</h1>
|
|
<h2 id="introduction">Introduction</h2>
|
|
<p>In the process of developing and releasing software, one of the most useful tools at a developer’s disposal is a solution that performs <strong>continuous integration</strong> and <strong>continuous deployment</strong>, or <strong>CI/CD</strong>.</p>
|
|
<p>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.</p>
|
|
<p>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.</p>
|
|
<p>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. <a href="https://gocd.org">GoCD</a> is one such solution, that provides a way of executing <strong>pipelines</strong> — 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.</p>
|
|
<p>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.</p>
|
|
<h3 id="prerequisites">Prerequisites</h3>
|
|
<p>To complete this tutorial, you will need the following:</p>
|
|
<ul>
|
|
<li>An Ubuntu 20.04 server configured with a non-root sudo user and firewall by following the <a href="https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-20-04">Ubuntu 20.04 initial server setup guide</a>.</li>
|
|
<li>A domain or subdomain pointed to your server that you will use to access the GoCD server. This must be separate from the domain that you use for your Gitea installation. If you are using a DigitalOcean Droplet, you can accomplish this by following our <a href="https://docs.digitalocean.com/products/networking/dns/">Domains and DNS</a> documentation. This tutorial will use <code><^>your_domain<^></code> in examples throughout.</li>
|
|
<li>An instance of Gitea installed on a separate server. For an example of how to install Gitea, you can follow the <a href="https://www.digitalocean.com/community/tutorials/how-to-install-gitea-on-ubuntu-using-docker#creating-a-test-repository">Now To Install Gitea on Ubuntu Using Docker</a> tutorial. For this tutorial, you will need the following:<ul>
|
|
<li>An Ubuntu 20.04 server configured with a non-root sudo user and firewall by following the <a href="https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-20-04">Ubuntu 20.04 initial server setup guide</a>.</li>
|
|
<li>Docker installed. You can find out how to do this by following <strong>Steps 1 and 2</strong> of the <a href="https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-20-04">How to Install and Use Docker on Ubuntu 20.04</a> tutuorial.</li>
|
|
<li>Docker Compose installed. You can find out how to do this by following <strong>Step 1</strong> of the <a href="https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-compose-on-ubuntu-20-04#step-1-installing-docker-compose">How to Install and Use Docker Compose on 20.04</a> tutorial.</li>
|
|
<li></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
<p>Once you have these steps complete, you can continue installing GoCD on your new server.</p>
|
|
<h2 id="step-1-installing-gocd">Step 1 — Installing GoCD</h2>
|
|
<p>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.</p>
|
|
<p>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.</p>
|
|
<h3 id="installing-the-gocd-server">Installing the GoCD server</h3>
|
|
<p>To begin, add the APT source to the sources list:</p>
|
|
<div class="codehilite"><pre><span></span><code><span class="n">echo</span><span class="w"> </span><span class="s2">"deb https://download.gocd.org /"</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">sudo</span><span class="w"> </span><span class="n">tee</span><span class="w"> </span><span class="o">/</span><span class="n">etc</span><span class="o">/</span><span class="n">apt</span><span class="o">/</span><span class="n">sources</span><span class="o">.</span><span class="n">list</span><span class="o">.</span><span class="n">d</span><span class="o">/</span><span class="n">gocd</span><span class="o">.</span><span class="n">list</span><span class="w"></span>
|
|
<span class="n">curl</span><span class="w"> </span><span class="n">https</span><span class="p">:</span><span class="o">//</span><span class="n">download</span><span class="o">.</span><span class="n">gocd</span><span class="o">.</span><span class="n">org</span><span class="o">/</span><span class="n">GOCD</span><span class="o">-</span><span class="n">GPG</span><span class="o">-</span><span class="n">KEY</span><span class="o">.</span><span class="n">asc</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">sudo</span><span class="w"> </span><span class="n">apt</span><span class="o">-</span><span class="n">key</span><span class="w"> </span><span class="n">add</span><span class="w"> </span><span class="o">-</span><span class="w"></span>
|
|
<span class="n">sudo</span><span class="w"> </span><span class="n">apt</span><span class="o">-</span><span class="n">get</span><span class="w"> </span><span class="n">update</span><span class="w"></span>
|
|
</code></pre></div>
|
|
|
|
<p>These commands will first add the repository like to a new file in <code>/etc/apt/sources.list.d/gocd.list</code>, then fetch the GoCD PGP key in order to verify the install. Finally, it will update the list of cached package information.</p>
|
|
<p>From here, install the GoCD server using APT:</p>
|
|
<div class="codehilite"><pre><span></span><code><span class="n">sudo</span><span class="w"> </span><span class="n">apt</span><span class="w"> </span><span class="n">install</span><span class="w"> </span><span class="k">go</span><span class="o">-</span><span class="n">server</span><span class="w"></span>
|
|
</code></pre></div>
|
|
|
|
<h3 id="installing-the-gocd-agent">Installing the GoCD Agent</h3>
|
|
<p>Every instance of GoCD needs at least one <strong>agent</strong>. 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.</p>
|
|
<p>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.</p>
|
|
<p>Once again, you will be using an agent installed from the APT repository that you set up earlier in this step.</p>
|
|
<div class="codehilite"><pre><span></span><code><span class="n">sudo</span><span class="w"> </span><span class="n">apt</span><span class="w"> </span><span class="n">install</span><span class="w"> </span><span class="k">go</span><span class="o">-</span><span class="n">agent</span><span class="w"></span>
|
|
</code></pre></div>
|
|
|
|
<p>This will install the GoCD agent on the server and allow you to run at least one pipeline at a time.</p>
|
|
<h3 id="setting-up-your-domain-name-and-https">Setting Up Your Domain Name and HTTPS</h3>
|
|
<p>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:</p>
|
|
<div class="codehilite"><pre><span></span><code><span class="n">sudo</span><span class="w"> </span><span class="n">ufw</span><span class="w"> </span><span class="n">allow</span><span class="w"> </span>
|
|
|
|
<span class="n">edit</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="n">configuration</span><span class="w"> </span><span class="k">file</span><span class="w"> </span><span class="n">that</span><span class="w"> </span><span class="n">the</span><span class="w"> </span><span class="n">GoCD</span><span class="w"> </span><span class="n">agent</span><span class="w"> </span><span class="n">has</span><span class="w"> </span><span class="n">installed</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="k">order</span><span class="w"> </span><span class="k">to</span><span class="w"> </span><span class="n">listen</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">requests</span><span class="w"> </span><span class="k">on</span><span class="w"> </span><span class="n">the</span><span class="w"> </span><span class="n">proper</span><span class="w"> </span><span class="n">address</span><span class="w"> </span><span class="k">and</span><span class="w"> </span><span class="n">ports</span><span class="p">.</span><span class="w"></span>
|
|
|
|
<span class="k">Open</span><span class="w"> </span><span class="n">the</span><span class="w"> </span><span class="n">configuration</span><span class="w"> </span><span class="k">file</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">editing</span><span class="p">.</span><span class="w"> </span><span class="n">The</span><span class="w"> </span><span class="k">following</span><span class="w"> </span><span class="n">example</span><span class="w"> </span><span class="n">uses</span><span class="w"> </span><span class="n n-Quoted">`nano`</span><span class="p">.</span><span class="w"> </span><span class="n">This</span><span class="w"> </span><span class="k">file</span><span class="w"> </span><span class="n">will</span><span class="w"> </span><span class="n">contain</span><span class="w"> </span><span class="n">environment</span><span class="w"> </span><span class="k">variables</span><span class="w"> </span><span class="n">that</span><span class="w"> </span><span class="n n-Quoted">`go-server`</span><span class="w"> </span><span class="n">relies</span><span class="w"> </span><span class="k">on</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">its</span><span class="w"> </span><span class="n">operation</span><span class="o">:</span><span class="w"></span>
|
|
|
|
<span class="n n-Quoted">`</span><span class="n n-Quoted n-Quoted-Escape">``</span><span class="n n-Quoted">command</span>
|
|
<span class="n n-Quoted">nano /usr/share/go-server/wrapper-config/wrapper-properties.conf</span>
|
|
</code></pre></div>
|
|
|
|
<h2 id="step-2-hooking-gocd-up-to-gitea">Step 2 — Hooking GoCD Up to Gitea</h2>
|
|
<h2 id="step-3-setting-up-a-pipeline-on-gocd">Step 3 — Setting Up a Pipeline on GoCD</h2>
|
|
<h2 id="conclusion">Conclusion</h2>
|
|
</article>
|
|
<footer>
|
|
<p>Page generated on 2023-05-10</p>
|
|
</footer>
|
|
</main>
|
|
<script type="text/javascript">
|
|
document.querySelectorAll('.tag').forEach(tag => {
|
|
let text = tag.innerText;
|
|
tag.innerText = '';
|
|
tag.innerHTML = `<a href="/tags.html#${text}">${text}</a>`;
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|