/ mozey.co / blog


April 10, 2016

🔗 gogs

A painless self-hosted Git service.

🔗 Install

🔗 Requires

MySQL or PostgreSQL


SSH server

🔗 Install go

Downloads page

curl -O https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz

tar xvf go1.8.3.linux-amd64.tar.gz

sudo chown -R root:root ./go

sudo mv go /usr/local

vi ~/.profile
# export GOPATH=$HOME/go
# export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin

source ~/.profile

mkdir $HOME/go

🔗 Download binary and extract

wget https://github.com/gogits/gogs/releases/download/v0.11.19/linux_amd64.tar.gz 

mv linux_amd64.tar.gz gogs_v0.11.19.linux_amd64.tar.gz

tar xvzf gogs_v0.11.19.linux_amd64.tar.gz

🔗 Create database

cd gogs

mysql -u root -p < scripts/mysql.sql 

🔗 Create custom config, example

cd gogs

mkdir -p custom/conf

vi custom/conf/app.ini

🔗 Run server

cd gogs

./gogs web &

ps ax | grep gogs

🔗 Connect via web interface to complete install

Run user = ubuntu

Sign up to create admin user (id = 1)

🔗 Create letsencrypt cert

sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install -y python-certbot-apache

sudo certbot --standalone certonly -d host.example.com
# /etc/letsencrypt/live/host.example.com/fullchain.pem

mkdir ~/gogs/certs
sudo cp /etc/letsencrypt/live/host.example.com/* ~/gogs/certs
sudo chown -R ubuntu:ubuntu ~/gogs/certs
chmod 400 ~/gogs/certs/*

🔗 Update config for HTTPS

vi custom/conf/app.ini
# PROTOCOL = https
# DOMAIN = host.example.com
# ROOT_URL = https://host.example.com/
# CERT_FILE = /home/ubuntu/gogs/certs/fullchain.pem
# KEY_FILE = /home/ubuntu/gogs/certs/privkey.pem

🔗 Disable user registration


🔗 Usage

🔗 Change remote to use https

git remote -v

git remote set-url origin https://host.example.com:3000/user/repos.git

🔗 go get

Private repository

cd $GOPATH/src

mkdir /path/as/required && cd /path/as/required

git clone [email protected]:private/repos.git

Update the package

go get -u

Install the package

go install