Gitea is a fork of Gogs, the easy to use self-hosted Git service. It is similar to GitHub, Bitbucket, and Gitlab. Gitea is lightweight code hosting solution written in Go, can run on minimal hardware requirements. It is a cross-platform application, can run anywhere Go can be compiled such as Windows, Linux, MacOS, ARM etc.

In this tutorial, I will show you step-by-step how to install and configure the lightweight Git service using Gitea. We will deploy the Gitea server using Docker and will be using the PostgreSQL database and Traefik Reverse proxy. For this guide, we will be using the latest Ubuntu 18.04 Server.

Prerequisites

Ubuntu 18.04

Root privileges

What we will do?

Install Docker-CE

Install Docker Compose

Deploy Gitea as Container using Docker

Gitea Post-Installation

Create First Repository

Testing First Commit

Step 1 - Install Docker-CE

The first step we will do for this guide is to install the Docker community edition to the Ubuntu 18.04 server. We will install the Docker CE package from the official Docker repository.

When the installation is complete, start the docker service and enable it to launch everytime at system boot.

sudo systemctl start dockersudo systemctl enable docker

Docker CE is up and running on the Ubuntu 18.04 server. Verify the installation by checking the docker version.

docker version

or run the docker 'hello-world'.

docker run hello-world

Step 2 - Install Docker Compose

Docker-Compose is a command line tool for defining and managing multi-container docker applications. It allows you to create a container as a service, great for your development, testing and staging environment.

Install Docker Compose by downloading the binary file and make it an executable.

Step 3 - Deploy Gitea as Docker Container

In this step, we will create a new docker-compose script that contains all services configuration including PostgreSQL Database and Traefik reverse proxy. We will set up all deployment files on the directory named 'deployment'.

Create Custom Docker Network

Before creating the deployment configuration, let's create a new custom bridge network. It will be used for the external service traefik reverse proxy.

Check the list docker network.

docker network ls

Now create a new custom bridge network named 'hakasenet'.

docker network create hakasenet

Check it again.

docker network ls

Now you will get 'hakasenet' network on the list.

Setup Deployment Directory and Files

Create a new directory named 'deployment' and the 'docker-compose.yml' script on it.

mkdir deployment; cd deploymenttouch docker-compose.yml

Now create new directory 'gitea' and 'postgres' data volume.

mkdir -p gitea/ postgres/

Create a new file 'acme.json' and change the permission of the file. it will be used to store Letsencrypt data.

touch acme.jsonchmod 600 acme.json

Now create the global traefik configuration 'traefik.toml' file.

touch traefik.toml

And below are files and directories we've for the Gitea installation using Docker.

tree

Setup PostgreSQL Service

The database service PostgreSQL is the first service that we want to configure. The database service will run only on the internal docker network.

And we will be using the Postgres 9.6 image, using 'gitea' as database name, user, and password, and set up the postgres data volume.

Setup Traefik Reverse Proxy

Now we will configure the Traefik reverse proxy for our Gitea installation.

The traefik service will be running under HTTP and HTTPS default ports, running on the custom bridge network named 'hakasenet', and we will configure it to use the Letsencrypt certificates that will be defined on the 'traefik.toml' file.

The Gitea service will be running on the TCP port '3000', using those two docker networks 'internal' and 'hakasenet', and will run under the traefik reverse proxy on domain 'git.hakase-labs.io'.

Docker composes configuration for Gitea deployment has been completed.

Deploy All Services

Now deploy the stack using 'docker-compose' command below.

docker-compose up -d

The command will download all docker images needed and run services defined on the docker-compose script.

And when it's complete, check available services on docker using ps option as below.

docker-compose ps

Now you will get the result as below.

The PostgreSQL database, Gitea, and traefik reverse proxy containers are now up and running. The database service is running on the default port '5432', the gitea server is running on port '3000', and the traefik proxy is running on HTTP and HTTPS ports, accessible from the outside network/internet.

Reference

Muhammad Arul is a freelance system administrator and technical writer. He is working with Linux Environments for more than 5 years, an Open Source enthusiast and highly motivated on Linux installation and troubleshooting. Mostly working with RedHat/CentOS Linux and Ubuntu/Debian, Nginx and Apache web server, Proxmox, Zimbra Administration, and Website Optimization. Currently learning about OpenStack and Container Technology.