Installing Gogs on WebfactionPosted: Tags: tech,webfaction,gogs
I have been wanting to host all my repository under my own domain. Earlier bitbucket offered a CNAME option, but not any more. Now it is possible with Gogs.
Gogs is a Git service implemented in Golang. It is easy to install (download one zip file) and easy to run (just one binary). It also has the familiar Github UI. I installed it on my favorite web-host, webfaction.
Goto webfaction panel, and create a new domain (//repo.jjude.com), a new custom app listening on a port and a website record connecting these two. Note down the port from the application page.
Login via ssh and browse to the application directory. Goto the download page and copy the link for the latest version. As I write this, link to the latest version is:
https://dl.gogs.io/gogs_v0.8.25_linux_amd64.zip. Unzip it.
wget https://dl.gogs.io/gogs_v0.8.25_linux_amd64.zip unzip gogs_v0.8.25_linux_amd64.zip
Now you are ready to run gogs.
cd gogs ./gogs web -p "xxxx"
Use the port number instead of 'xxxx'. This will run gogs in development mode. If everything worked, you will be able to browse to the domain from the browser. Gogs will automatically detect that this is the first run and redirect to installation screen.
Gogs supports sqlite, mysql & postgresql. I chose to use sqlite. Change 'Application Name' to suit your purpose. Fill in your webfaction user id for 'Run User'; application port number for 'HTTP Port' and domain url for 'Application URL'. This URL will be used in the front-end for cloning a repo.
Once the installation is over, Gogs will automatically create the config file in Gogs directory. You can find the config file in custom/config directory. You can change these values later. Refer config cheat sheet page to understand the configuration options in detail.
Terminate the gogs process. Now you can run the process in background using
./gogs web &. While this is good enough, we want gogs to restart if it crashes or if system reboots. We need a process controller like supervisor. If you have not already installed
supervisor, you can install using
pip install supervisor. Refter webfaction guide for installing python packages using
pip. You can also refer to Jamie Curle's excellent guide for installing supervisor and its configuration. There is also a community guide. Here is how I went about installing supervisord.
pip2.7 install --user supervisor ln -s ~/local/etc ~/etc echo_supervisord_conf > supervisord.conf
Following Jamie Curle's advice, I created a separate .ini file for Gogs and included it in
supervisord.conf. The last section of the
supervisord.conf looks like this.
[include] files = /home/userid/webapps/gogs/supervisor.ini
I created a
supervisor.ini file in the gogs directory. It's contents are:
[program:gogs] command=./gogs web
Now Gogs can be managed using supervisord.
supervisorctl stop gogs supervisorctl start gogs
What if supervisor fails? Let us cover that with cron.
crontab -1 0,20,40 * * * * $HOME/bin/supervisord -c $HOME/etc/supervisord.conf > /dev/null 2>&1
All done. Gogs has another cool feature to migrate a git repository. I used it and imported git repos from both github and bitbucket. You can browse my public repos.