Red Hat Enterprise Linux

How to set up GOGS git server with MkDocks?

How to set up GOGS git server?

Introduction

Before we dive in into the explanation let’s understand what are gogs and mkdocks.
Gogs is a local git server, that we use to create repositories and save our code in thier.
MkDocks is a static site generator for building project documentation.

Prerequisites:

Database:

First of all, we need to have a database. We need to choose between MySQL, PostgreSQL, and SQLite3. For this demonstration, we will choose SQLite3. For SQLite3 DB we don’t need to download and configure the DB, depends on the DB you will need to act appropriately. See this documentation for more details:

GOGS Installation Documentation

Git:

We need to ensure that our machine has git on it. Let’s Download the git package. Run the following command:

dnf/yum -y update && upgradednf/yum install -y git

 

Installing GOGS

Prerequisites:

Install GO:

First of all, we need to install GO. To do that, we have to accomplish a few steps:

Refer to this documentation: GO Installation Documentation

Download the tar file.

 

Next, go to the Download directory to check the file downloaded successfully.

 

To extract the tar file, run the command:
tar -C /usr/local -xzf go1.22.0.linux-amd64.tar.gz

Check the /usr/local directory for the file.

 

Add /usr/local/go/bin to the PATH environment variable. Run the command:
export PATH=$PATH:/usr/local/go/bin

 

Verify that you’ve installed Go by typing the following command:
go version

 

After accomplishing this step and successfully downloading GO to your machine, you are ready to proceed with the next steps.

 

Downloading and setting up GOGS

The first step is to clone the GOGS repository from GitHub. Run the command:

git clone --depth 1 https://github.com/gogs/gogs.git gogs

 

Change to the new GOGS directory and download dependencies. Run the commands:

 cd gogs
 go build -o gogs

 

Run the GOGS server. To check if everything is set up correctly, we need to run: http://localhost:3000 and we expect to see the GOGS default page. Run the command:

 ./gogs web

 

Now we need to fill the form according to our settings and click install.

 

 

You can create a GOGS account on this screen or the next one.

 

 

If everything went according to plan, you should get the following screen:

 

Creating a Repository

Now we need to create a new repository for our MkDocs project. You can do it simply by pressing the ‘+’ button and fill the form to create a new repositor.

 

Downloading MkDocs

First of all, to be able to download MkDocs, we need to install Python3 package 

manager pip from our package manager. For more information:

MkDocs Getting Started

Run the command:

dnf/yum -y install pip

 

Next, we need to install MkDocs using pip. Run the command:

pip install mkdocs

 

Creating a new project using MkDocs

First, we need to clone our repository from gogs, to be able to create our mkdocs project there, and eventually push our changes to our repository.

 

Now we need to create a new mkdocs project inside our repository.

 

Now let’s check that our mkdocs project created successfully. To run mkdocs run: mkdocs serve, then run: http://localhost:8000 and check if we see the default mkdocks page.

 

Pushing the MkDocs project to our Git repository

After we checked we can access our project, we will push it to our Git repository. The next steps are needed to add, commit, and push our changes to our repository.

git add .

git commit -m "adding MkDocs project"

git remote add origin http://localhost:3000/ortuser19/mkdocs-demo-project.git (to be sure our branch is in the GOGS server).

git push -u origin master

 

Now we can look inside our repository to check if the project is there.

 

Setting up Nginx

At this point, after we have everything set up, we need to figure out how to make our GOGS and MkDocs servers accessible. To help us achieve this goal, we need the help of a reverse proxy, which will help us redirect our traffic to the right place. This is where Nginx takes place.

 

Downloading Nginx

To download Nginx, run the command:
dnf/yum -y install nginx

 

Start and enable the Nginx service. This helps us to make sure Nginx service will start every boot. Run the following commands:

systemctl start nginx
systemctl enable nginx
systemctl status nginx

 

Configure Nginx

Our goal is to be able to access GOGS through gogs-ortuser19.ort.tamnun.inc to our GOGS server, and access our MkDocs server through docs-ortuser19.ort.tamnun.inc. To achieve that, we need to tell Nginx to listen on port 80 (HTTP) and if a user is accessing through gogs-ortuser19.ort.tamnun.inc, then send him to the GOGS server. Otherwise, if the user accessing through docs-ortuser19.ort.tamnun.inc, then send him to the MkDocs server. Our way to configure this kind of act is in the nginx.conf file.

gogs-ortuser19.ort.tamnun.inc config:

 
docs-ortuser19.ort.tamnun.inc config:

In those server sections, we are telling Nginx to listen on port 80 with the appropriate domain, then proxy the request to the appropriate port, localhost:3000 for GOGS and localhost:8000 for MkDocs.

Don’t forget to run systemctl restart nginx to apply changes.

You may encounter a problem where everything is set up, Nginx is running, but you can’t reach the destination, which are our GOGS and MkDocs servers. This may due to SELinux (Security Enhanced Linux) which is denying Nginx network connections. To solve this problem you may need to run the following command to enable it:

setsebool -P httpd_can_network_connect 1

 

Configure Domains

Last but not least, we need to edit a specific file, where we can set a DNS record of our domains and connect them to our localhost IP address. This file is in /etc/hosts.

 

Check Connectivity

Now, everything is set up and all we have to do is to write in our browser our domains, and expect our GOGS and MkDocs servers to show up.

 

GOGS:

 

MkDocs:

 

Summary

If you followed every single step in this article, you should get this satisfying result. I hope you enjoyed this article and this project as much as I did, hope this was helpful to you. I wish you no bugs at all and happy coding 🙂

Red Hat
Red Hat

חברת אוקטופוס היא שותף בכיר של Red Hat בישראל ומציעים רישוי לכלל מוצרי Red Hat במחירים תחרותיים וכן את שירותי ייעוץ המומחים שלנו מאחוריהם אלפי שעות בפרויקטים המורכבים ביותר במשק.

צור קשר