Skip to content

Instantly share code, notes, and snippets.

@jblaise
Created October 31, 2017 09:18
Show Gist options
  • Save jblaise/358bffe5b8800955347956cf601ee838 to your computer and use it in GitHub Desktop.
Save jblaise/358bffe5b8800955347956cf601ee838 to your computer and use it in GitHub Desktop.
Install gitea *almost* from scratch

Installing Gitea on Raspbian

This file is a rundown of the different steps to install gitea. As a fork of gogs, gitea installs the same way gogs does, but I didn't find an exhaustive how-to to install it. I did however find an extensive guide on this blog post, most of this data is reused here.

Prerequisite:

  • Fresh install of Raspbian GNU/Linux 9 light or newer
  • some patience

Install

$ sudo apt install git golang mariadb-client mariadb-server
$ sudo adduser --disabled-login --gecos 'gitea' git
$ echo export GOPATH="PATH" >> ~/.bashrc

Database configuration

As said, I am using MySQL. This part replace or create a gitea database and create an account to access it.

Be sure to set SOME_PASSWORD to something you'll remember.

$ sudo mariadb -u root
> create database gitea character set utf8 collate utf8_general_ci;
> grant all on gitea.* to 'git'@'localhost' identified by 'SOME_PASSWORD';
> quit

Fetch and build gitea

This will fetch and build the latest version of gitea and put it in $GOPATH/code.gitea.io/gitea.

$ go get -u code.gitea.io/gitea
$ cd $GOPATH/src/code.gitea.io/gitea
$ go build

Pre-configure gitea

Once build, I recommend you move a few files around. I don't like having a folder filled with source, cvs folders and compilation products in it.

$ export LOC=/usr/local/gitea
$ sudo mkdir -m 775 $LOC $LOC/bin $LOC/systemd
$ sudo chown -R git $LOC
$ sudo -u git cp $GOPATH/src/code.gitea.io/gitea/gitea $LOC/bin
$ sudo -u git cp -r $GOPATH/src/code.gitea.io/gitea/conf $LOC
$ sudo -u git cp -r $GOPATH/src/code.gitea.io/gitea/options/locale $LOC/conf
$ sudo -u git cp -r $GOPATH/src/code.gitea.io/gitea/public $LOC
$ sudo -u git cp -r $GOPATH/src/code.gitea.io/gitea/templates/ $LOC
$ sudo -u git cp $GOPATH/src/code.gitea.io/gitea/contrib/systemd $LOC

After that you can customize gitea.

$ sudo -u git vi $LOC/systemd/gitea.service
$ sudo -u git vi $LOC/conf/app.ini

The app.ini file you got here is unmodified. It will be modified by the installation process you will go through afterward. A few things can be configured before hand, though. Read the cheat sheet for more info.

  • The project folder root is set in [repository].ROOT. I set it to gitea-repos, beside the gitea application folder
  • The database url and credentials are set in the [database] section
  • The DOMAIN and HTTP_ADDR of the [server] and the [repository].ROOT_URL are used for display and a displaying the cloning URL
  • I suggest setting [service].DISABLE_REGISTRATION and [service].REQUIRE_SIGNIN_VIEW to true if you really want to go private server
  • I also suggest setting [log].ROOT_PATH to a folder you'll remember (like /home/git/gitea/logs)
  • Setting up security can also be a good idea: set configure the [server].CERT_FILE and [server].KEY_FILE entries accordingly

Systemd configuration

Copy the systemd script to the /lib/systemd/system folder:

$ cd /lib/systemd/system/
$ sudo ln -s /usr/local/share/gitea/gitea.service

Edit that file (remember you need root powers for that) to change the different paths:

  • WORKINGDIR=/home/git/gitea
  • ExecStart=/home/git/gitea/gitea web
  • Environment=USER=git HOME=/home/git

Also decomment the After=mysqld.service

Starting gitea

Start gitea after that:

git:~$ sudo systemctl start gitea

First installation

Use your webbrowser to go to http://:3000 (you can use the https if you set up certificates.)

You should be redirected to gitea install page. Fill the mandatory fields and press Install. If you set DISABLE_REGISTRATION to true in the Pre-configure gitea step, you'll also have to create the administrator account there.

Once the installation is done, you should be redirected to the Dashboard.

Others

Importing projects

Simply press the + on the right of the Dashboard then select New Migration. You can migrate local git bare repositories too.

Using git-ssh

In order to use git-ssh to clone projects and push commits, you have to add your public ssh key to your account. That is done in 'Your Settings' -> 'SSH Keys'. Notice that if you don't do that, the URL checkout presented in the URL will not work. You should still be able to checkout and push using the regular git URLs.

For example: a user is named JAppleseed. After setting his public key in gitea, his project should be clonable from git@yourserver:JAppleseed/MyProject.git. Without the public key set, a git clone will result in a 'JAppleseed/MyProject.git is not a valid repository' message.

Using git@yourserver:<your git repo root>/jappleseed/myproject.git or something equivalent based on the filesystem will work, though it will not be thanks to gitea.

FAQs

Q. I failed the original configuration process!! I want a do over!

A. Stop the gitea process, reset the database entry (see Database configuration), and set [security].INSTALL_LOCK to false in the gitea/custom/conf/app.ini file.

Q. The install webpage doesn't appear after I've done the systemctl start gitea command

A. Take a look at the logs of the app (or the systemctl status gitea). You set them in the Pre-configure gitea step. There should be a "listening to XXX.XXX.XXX.XXX:3000" in the log. Anyway, starting the web server takes some time. Like up to 10s on a raspberry pi 2.

Q. I can't checkout using the short URLs

A. Either you didn't set your public key (or it's not correct) or your git command tool doesn't know which key to use because you got multiple keys in your .ssh folder. I suggest reading a few docs on git or ssh to solve your problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment