Private Github alternative with minimal ram requirements - Gitea on docker

in #tutorial7 years ago (edited)

When I started on steemit a few days ago, I realized that I need a bit of time before publishing a new article. During this time I draft the article local and rewrite it several times, the usual creative way. As Markdown is perfect for version control software, I felt the need for aGit repository, managing the changes and having a fallback if something goes wrong.

To realise this I wanted my own, self hosted Git repository. As I prefer open source and do not have the 4 GB minimum RAM for GitLab, I moved to Gitea. The rough relationship between GitHub und Gitea is as following:

GitHub was rebuild by GitLab as open source version. GitLab consumed a few similar projects and is extremely feature rich but also memory consuming. To reduce the memory consumption it was rebuild in GO and reduced to its key features. As the Gogs developer did not react to pull requests for a few months, it was forked as Gitea and is regularly managed since then.

TL;DR

Scroll down to chapter Installation process. There you can find a tutorial how to install Gitea using Docker and connecting it to the host database.

Why should I host myself instead of using GitHub?

I myself prefer having my data on my own infrastructure. Moreover there are no unlimited, free private repositories on GitHub and I like my drafts private before publishing. But the main reason would be because I can do it, I have my own server which is mostly idleding around and I love experimenting.

Docker and why to use it

As said before, I love experimenting. If I install software for testing purposes on my online system, the dependencies become confusing over the time. This is where Docker comes into play.

If you never heard of Docker, I suggest reading the What is Docker? article first. Anyhow the following lines are sufficiant for a rough understanding:

Docker simply sharing the main functions of the current linux kernel (e.g. disk access, ram access) and additionally installs only compoents inside the containers which are needed by the processes. This way every process dependency (e.g. Python, Go) for GitLab, Gitea will be installed in the container without touching the host. Moreover these containers are completely isolated, so they can be moved, removed or copied without problems.

So, why shouldn't I use a Docker image which runs the software, contains all dependencies and combine it with the host installation of MariaDB?! In this article I will use my local database which is running for other projects. Gitea can simply removed using a docker rm.

Installation process

The installation process includes installing the Docker community edition, download and configuration of Gitea Docker container and finally the installation of Gitea.

To install Docker I suggest reading the following page Get Docker CE for Debian. Installation manuals for different distributions or operating systems are selectable.
Install the packages docker and docker-compose. Docker-compose is a toolset which enables a simple management of different linked Docker containers in a YML file. In my point of view it is better manageable and more readable than saving the run string in a bash file.

The install process creates the following environment:

  • The data of Gitea will be held in the host directory /var/lib/gitea
  • The Mysql connection works with a socket which is linked from host to container. As the container network is usually split from the host network and a firewall protected host might block all connections from the bridged container, this is a performant and simple way to connect the node to the host db instance.
  • The container's SSH Port 22 will be mapped to host port 10022
  • The container's Web Port 3000 will be mapped to host port 10080

The following installation process worked for me:

  • Create the data directory on server:
mkdir /var/lib/Gitea
  • Create a docker-compose.yml file in a directory of your choice:
version: '2'
services:
    Gitea:
        image: Gitea/Gitea:latest
        ports:
            - "10080:3000"
            - "10022:22"
            volumes:
                - /var/lib/Gitea:/data
                - /var/run/mysqld/mysqld.sock:/tmp/mysqld.sock
  • Run sudo docker-compose up in the previously directory and check the log outputs. It should start downloading the latest Gitea container and deploy it to your Docker instance.
  • Check availability of Ports 10080 and 10022.
  • During the installation page you can use /tmp/mysqld.sock as a host for the database instance.
  • Stop the current docker-compose up and use sudo docker-compose run instead to start the daemon process.
  • The Gitea instance should be available under HOSTNAME:10080, this port can be proxied to a usual https or http port through a lightweight Nginx or an already existing Apache server. For example a HTTP Proxy on Apache:
RequestHeader set X-Forwarded-Proto "http"
RequestHeader set X-Forwarded-Port 80
ProxyPreserveHost Off
ProxyPassMatch ^/((?!(?:errors|\.well-known)/).*) http://localhost:10080/$1 retry=30 timeout=7200
ProxyPassReverse / http://localhost:10080/

Optional steps for ssh connections

To create fast ssh connection to your personal Git I would recommend creating a ssh_config file. This is a file to create SSH-Aliases and configure them with individual passwords, users, ports or keyfiles. Due to this file you do not get regularly requests asking for your password. In linux filesystems the file is usually created in /home/USERNAME/.ssh/config.

  • For your own Git you could use something like this:
Host git
        HostName git.example.com
        Port 10022
        User Git
        IdentityFile ~/.ssh/id_rsa
  • Add your SSH public key in the settings your Gitea user account.
  • Use the following connection string to your repositories:
git clone ssh://SSH_ALIAS/USERNAME/REPOSITORY.Git

For repository test of user bob:
git clone ssh://Git/bob/test.Git
  • Never type your ssh password again :)

If there is anything wrong or you have problems with the tutorial, please drop me a short comment. If you like it please follow and stay tuned for other tutorials or tv show reviews.

Sort:  

You've been UpVoted via the UpVote Experiment 002 Bot. Depending on my VP & the price of STEEM you should get a $.01-$.03 for your trouble.
Read more about this experiment here.

Thank You - @blueorgy

Hello! I just upvoted you! I help new Steemit members! Upvote this comment and follow me! i will upvote your future posts! To any other visitor, upvote this post also to receive free UpVotes from me! Happy SteemIt!

Congratulations @norvares! You have received a personal award!

1 Year on Steemit
Click on the badge to view your Board of Honor.

Do not miss the last post from @steemitboard:
SteemitBoard World Cup Contest - Home stretch to the finals. Do not miss them!


Participate in the SteemitBoard World Cup Contest!
Collect World Cup badges and win free SBD
Support the Gold Sponsors of the contest: @good-karma and @lukestokes


Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

Congratulations @norvares! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.028
BTC 58027.38
ETH 2358.35
USDT 1.00
SBD 2.38