Personal Infrastructure — Source Code Management

Photo by Clément H on Unsplash

Source Code Management Options

There are few hosted options I’ve used: Very common, has a number of nice features to gihtub SCM solution, has a lot of newer features compared to other options solution, not my preferred

When I’m working on my own projects, I prefer to use Github or Gitlab, although my personal projects almost always use Github. I’ve also used Gitlab for professional projects and at my university, in my experience it was a wonderful user experience and had a good feature set. I started with Github though back in the day, so my personal projects are stored there and will stay there (for now).

If you are looking to host your own service: small and powerful SCM solution running as a Go binary

https://gitlab.comExplained from above runs as a Ruby on Rails application with a number of extra features that can be added as well

I’d recommend either of these solutions depending on what tools you are looking for, but for the purposes of this article. I’m going to use Gogs which means we’ll setup a very small and powerful SCM server for use with other services.

As I said in the previous article, I want to empower developers by teaching them all the basic tools they’ll need for their own development pipeline. Just like what you see below:

Personal Infrastructure

To this end, we’ll start building out our source code management server, which should either be a standalone server or a server and database solution. Since I’m cheap and really don’t want to spend any more money than I need to (my dad was a fireman and my mom was a lunch lady, I didn’t grow up spending a lot of money) I’m going to show you how to set everything up on a single server.

Setting Up Your Own Tools with Docker

// This installs updates to the software sources on Ubuntu via "apt" which is the package manager for Ubuntu
$ sudo apt-get update

// This installs SSL style apt installs, new CA certificates, the last install "software-properties-common" will help install 3rd party software with apt
$ sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
// This installs the required location for the docker software, and let's apt know where to find it
$ curl -fsSL | sudo apt-key add -

This will setup the pre-Docker software required for installing everything you need, once you’ve completed the above just run:

$ sudo add-apt-repository \
"deb [arch=amd64] \
$(lsb_release -cs) \
# Install docker
$ sudo apt install docker-ce

This should setup docker using the root user account ( sudo docker ps) using that command you should see a prompt for any “containers” that are running. While working with docker you’ll need to prefix all commands with sudo until you allow your user access to docker without root access.

To start your own source code management server, let’s start up an instance of Gogs and configure everything.

// This starts a gogs server and detaches it from your session, on shut down the container is removed. The data in /var/gogs should exist after container is removed.
$ sudo docker run -d --rm --name=gogs-server -p 10022:22 -p 10080:3000 -v /var/gogs:/data gogs/gogs
Page Header on “install” page

Open the configuration page as http://localhost:10080/install which should give you access to a page with configurations for Gogs and its data storage. During the configuration I highly recommend using SQLite3 database, this is a local file-based database and will make things easier in the future until you can setup a standard database.

Example of path configuration

A very critical thing when setting up the Gogs git server is the use of /data for the files in the install page. This will allow the data to show up in /var/gogs path of the server or workstation running the docker container.

Create a Repository

Step 1) Create New Repository Step 2) Complete form Step 3) Copy Git URL

Once you’ve created a repository and have a running source code management server, we can download the repository using the git command on your machine. You’ll want to take the git URL copied to your clipboard and paste in into the below example command.

// Clone new Repo to your machine
$ git clone GIT_URL

You should see the command run in the terminal window, downloading the source code into the file path that you are currently located in. Once downloaded you can move the example server.go we created in the last tutorial to this folder. After you’ve moved your source code into this location run the commands below.

// Check current state of working directory
$ git status
// Add new source code to the repository
$ git add .
// Add a message about the code you are adding
$ git commit -m "Added example source code"
// Send the code to your Source Code Management server
$ git push

You should now see a new file in the brand-new repository that you’ve just created, the new file will have a different timestamp from the other files, and you’ll see the message you attached.

This completes the tutorial for setting up a Source Code Management server for yourself, I hope you found it interesting and helpful. We’ll create our own automated CI/CD pipeline with my favorite tool of all time next week, so I hope you are as excited as I am.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
John Stupka

John Stupka


Coffee Drinker, Chief Engineer of Dancing at Desk, Foodie, HyperText Transfer Operator, Overly energetic and active! 💻 ☕