Change tracking and version control are essential tools for software development. In fact, they are one of the pillars upon which projects succeed, both in the short and long term. Today, Git remains the version control system of choice for many teams, with almost half of all professional developers reporting that it was their primary choice.

In spite of its widespread adoption, Git can be difficult to learn. As one software engineer put it, "Git makes difficult things possible, and simple things so frustrating that I've thought about becoming a llama rancher." Online tools like Github and Bitbucket attempt to make Git easier for individuals and teams, but these services come with additional costs and risks. These risks and costs can be mitigated by self-hosting a Git service.

git-gogs-1.png

In this tutorial we will show you how to use CenturyLink Cloud services to deploy Gogs, a lightweight, full-featured, and self-hosted Git service.

Before We Start

If you don’t have a CenturyLink Cloud account yet, head over to our website and sign up for a free trial. You’ll need it to use CenturyLink Cloud tools.

Tools Used

CenturyLink Cloud Compute servers are high-performance cloud servers. These enterprise-grade virtual machines are easy to deploy and manage from the CenturyLink Cloud Console and via our powerful API.

Deploy a New Virtual Server

Our first step is to deploy a new CenturyLink Cloud virtual server. Follow the steps below.

  1. Log-in to the CenturyLink Cloud Control Portal.

  2. From the Navigation menu on the left side, click Infrastructure > Servers.

  3. On the left-hand side of the server panel, click on the region for the server you want to provision.

  4. Click Create, and then click Server.

  5. Fill out the form for your new server.

  6. For Operating System, select Ubuntu 16 | 64-bit.

  7. Click Create Server.

  8. Your server provisioning request will enter the queue. You can watch the progress of your request on the screen. Your server is provisioned when the status of all tasks in the queue is complete.

    Request Details

  9. After the new server is provisioned, return to the Control Portal and click Infrastructure > Servers.

  10. Navigate to the region, find the new server and click on its name.

  11. Click the More menu, and then click add public ip.

  12. Check the boxes for HTTP (80) and SSH/SFTP (22).

  13. Click add public ip address.

Configuring Your Virtual Server for Gogs

To update your virtual server and prepare it for running Gogs, follow these steps.

  1. Log-in to the Control Portal.

  2. From the Navigation Menu, click Infrastructure > Servers.

  3. Navigate to the virtual server you provisioned above and click on its name.

  4. On the right hand side of the server status page, look for IP ADDRESS(ES). Your server's public IP address will be underlined.

  5. From a shell or terminal on your local machine, connect to your virtual server with the following command. Replace "YOUR.VPS.IP" with your server's public IP address.

    shell
    ssh root@YOUR.VPS.IP
    
  6. Install the required Ubuntu packages with the following commands.

    shell
    apt update
    apt install sqlite3 git nginx -y
    
  7. Now you have to configure the NGINX web server to act as a reverse proxy for Gogs. Open /etc/nginx/sites-available/default with a text editor.

  8. Below the location / block, add the following code.

    conf
    location /gogs/ {
          proxy_pass http://127.0.0.1:3000/;
    }
    
  9. At the shell prompt, run the following command to restart NGINX.

    shell
    service nginx restart
    

Installing and Configuring Gogs

Now we install Gogs to run under a dedicated Git user. This allows you to expand your Git self-hosting capabilities in the future with additional software. It also keeps users from accessing restricted accounts on your machine. To create the user account and install Gogs, run the following:

  1. Create the user and switch roles using the following commands.

    shell
    useradd -c 'Git Repo User' -d /home/git -m git
    su -l git
    cd ~
    
  2. Download and install Gogs with these commands.

    shell
    wget https://github.com/gogits/gogs/releases/download/v0.9.113/linux_amd64.tar.gz
    tar xvzf linux_amd64.tar.gz
    cd gogs
    mkdir -p custom/conf
    
  3. Open the custom/conf/app.ini file with a text editor and edit it to look like the following. Replace YOUR.VPS.IP with the IP address of your virtual server.

    conf
    [server]
    ROOT_URL = http://YOUR.VPS.IP/gogs/
    
  4. Run the Gogs server with the following command.

    shell
    ./gogs web
    
  5. You should see output similar to the following, which indicates that Gogs is up and running.

    git-gogs-3.png

  6. In your web browser, go to http://YOUR.VPS.IP/gogs/.

    Note: Replace YOUR.VPS.IP with the IP address of your virtual server. This takes you to the Gogs installation screen.

    git-gogs-4.png

  7. From the Database Type drop-down, select SQLite3.

  8. Set the application hostname to the IP address of your virtual server.

  9. Configure the rest of the settings according to your requirements.

  10. Click Install Gogs.

  11. In your web browser, go to http://YOUR.VPS.IP/gogs/. Replace YOUR.VPS.IP with the IP address of your virtual server. This takes you to the Gogs log-in screen.

  12. Log-in and use the application (which is similar to how you would use Github).

    git-gogs-5.png

Next Steps

Now that you have Gogs set up and configured, it's time to get your team to use it! Try creating new repositories and cloning them, the same as you do with other Git services. You might also want to try configuring Gogs to use CenturyLink Cloud MySQL, our cloud-hosted managed relational database solution. In addition, you can use tmux to keep Gogs running while you're not logged into your server. Check out our tutorial on deploying NEM securely for hints on using tmux.

Sign-up for our Developer-focused newsletter CODE. Designed hands-on by developers, for developers. Keep up to date on topics of interest: tutorials, tips and tricks, and community building events.

We’re a different kind of cloud provider – let us show you why.