Lucene search

K
n0whereN0whereN0WHERE:76308
HistoryFeb 21, 2016 - 8:10 p.m.

Self Hosted Git Service: Gogs

2016-02-2120:10:36
n0where.net
15

Gogs is a self-hosted Git service written in Go which is very easy to get running and has low system usage as well. It aspires to be the easiest, fastest, and most painless way to set up a self-hosted Git service. With Go, this can be done with an independent binary distribution across ALL platforms that Go supports, including Linux, Mac OS X, Windows and ARM.

gogs

Features

  • Activity timeline
  • SSH and HTTP/HTTPS protocols
  • SMTP/LDAP/Reverse proxy authentication
  • Reverse proxy with sub-path
  • Account/Organization/Repository management
  • Repository/Organization webhooks (including Slack)
  • Repository Git hooks/deploy keys
  • Repository issues, pull requests and wiki
  • Add/Remove repository collaborators
  • Gravatar and custom source
  • Mail service
  • Administration panel
  • Supports MySQL, PostgreSQL, SQLite3 and TiDB (experimental)
  • Multi-language support ( 14 languages )

System Requirements

  • A cheap Raspberry Pi is powerful enough for basic functionality.
  • 2 CPU cores and 1GB RAM would be the baseline for teamwork.

Prerequisites

  • Database (choose one of following):
  • Git (bash):
    • Version >= 1.7.1 for both server and client sides
    • Best to use latest version for Windows
  • A functioning SSH server:
    • Ignore this if you’re only going to use HTTP/HTTPS or use builtin SSH server
    • Recommend Cygwin OpenSSH or Copssh for Windows.

How to Install Self Hosted Git Service ?

There are 5 ways to install Gogs:

Install the Database

We’re going to use MySQL as our back end server.

sudo apt-get -y install mysql-server

During the installation, you will be asked to enter the password of the database root user.

Now create and open a file named gogs.sql .

nano gogs.sql

Paste the following contents into the file, and save and close it.

DROP DATABASE IF EXISTS gogs;
CREATE DATABASE IF NOT EXISTS gogs CHARACTER SET utf8 COLLATE utf8_general_ci;

Finally, execute gogs.sql with MySQL to create the Gogs database. Replace your_password with the root password you chose earlier.

mysql -u root -pyour_password < gogs.sql

To install Gogs from source, version control tools like Git and Mercurial are needed.

sudo apt-get -y install mercurial git

If you plan to clone a repository via SSH, a functioning SSH server is required.

Install Go

nano ~/.bashrc

Add the following lines to the end of the file, then close and save it.

export GOPATH=/home/git/go
export GOROOT=/usr/local/src/go
export PATH=${PATH}:$GOROOT/bin

Next, apply your changes.

source ~/.bashrc

Then use wget to download latest complied version of Go here .

wget https://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz

Extract

tar zxf go1.4.2.linux-amd64.tar.gz

Change directories to the $GOROOT we defined in ~/.bashrc .

sudo mv go $GOROOT

Now, if you type go in your terminal:

go

You should see something like this:

Go is a tool for managing Go source code.

Usage:

    go command [arguments]

...

Use "go help [topic]" for more information about that topic.

Install and Start Gogs as a Service

Go has a built in command, get , for easily downloading the source code of a Go project along with all of its dependencies, which we’ll use to download Gogs.

go get -d github.com/gogits/gogs

The source code of Gogs will now be in $GOPATH/src/github.com/gogits/gogs .

cd $GOPATH/src/github.com/gogits/gogs

Next, build and generate the binary. This command may take a moment to run.

go build

We’re going to use .

Install Supervisor to manage the Gogs service.

sudo apt-get -y install supervisor

Make a Gogs daemon.

sudo mkdir -p /var/log/gogs

Open the Supervisor configuration file for editing.

sudo nano /etc/supervisor/supervisord.conf

Append the following contents to the file to create the Gogs section.

[program:gogs]
directory=/home/git/go/src/github.com/gogits/gogs/
command=/home/git/go/src/github.com/gogits/gogs/gogs web
autostart=true
autorestart=true
startsecs=10
stdout_logfile=/var/log/gogs/stdout.log
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
stdout_capture_maxbytes=1MB
stderr_logfile=/var/log/gogs/stderr.log
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=10
stderr_capture_maxbytes=1MB
environment = HOME="/home/git", USER="git"
user = git

This section defines the command we want to execute to start Gogs, automatically starts it with Supervisor, and specifies the locations of log files and corresponding environment variables.

Now restart Supervisor.

sudo service supervisor restart

Check that Gogs is running.

ps -ef | grep gogs

You should see something like this as the output.

root      1344  1343  0 08:55 ?        00:00:00 /home/git/go/src/github.com/gogits/gogs/gogs web

You should also be able visit the web page with URL http:// your_server_ip :3000/ . This will redirect to the installation page.

Set Up Nginx as a Reverse Proxy

Install Nginx.

sudo apt-get -y install nginx

Create an Nginx configuration file for gogs.

sudo nano /etc/nginx/sites-available/gogs

Add the following content, replacing your_server_ip with your IP address. If you’re using a domain name for your Droplet, you can use your domain name here instead.

server {
    listen 80;
    server_name your_server_ip;

    proxy_set_header X-Real-IP  $remote_addr; # pass on real client IP

    location / {
        proxy_pass http://localhost:3000;
    }
}

And symlink it so that Nginx can use it.

sudo ln -s /etc/nginx/sites-available/gogs /etc/nginx/sites-enabled/gogs

Restart Nginx to activate the virtual host configuration.

sudo service nginx restart

You should now be able visit the web page with the URL http:// your_server_ip / , without specifying the port.

Initialize Gogs

There is one more simple step left to initialize Gogs for its first run.

Visit http:// your_server_ip /install and fill in the following options. Many of them will be filled out for you already, but make sure to replace the variables in red with the values for your server.

In the first section, Gogs requires MySQL, PostgreSQL or SQLite3 , fill out:

  • Database Type: MySQL
  • Host: 127.0.0.1:3306
  • User: root
  • Password: your_database_password
  • Database Name: gogs

In the second section, General Settings of Gogs , fill out:

  • Repository Root Path: /home/git/gogs-repositories
  • Run User: git
  • Domain: your_server_ip
  • HTTP Port: 3000
  • Application URL: http:// your_server_ip /

Skip the optional e-mail and notification settings, then under Admin Account Settings , choose an admin username and password, and include your email address. We’ll refer to the admin username a your_admin_username .

Finally, click Install Gogs , and then log in.

Test Gogs

You’re all done! Let’s do a simple pull/push test just to make sure Gogs is functioning correctly.

First, go to http:// your_server_ip /repo/create and create a repository with the name my-test-repo , and you click on the option Initialize this repository with a README.md .

Now you should be able to clone it. First, move to your home directory.

cd

Next, clone the repository.

git clone http://your_server_ip/your_admin_username/my-test-repo.git

Change to the repository directory.

cd my-test-repo

Update the README.md .

echo 'I love Gogs!' >> README.md

Commit your changes and push them. This command will ask you for your Gogs username and password.

git add --all && git commit -m "init commit" && git push origin master

Self Hosted Git Service: Gogs documentation

Source && Download

Self Hosted Git Service: Gogs download