Build Your Own Git Server using Gogs
Latest posts by Gini Gangadharan (see all)
- How to Request Resource Quota Increase in Microsoft Azure - November 8, 2019
- Build Your Own Git Server using Gogs - October 22, 2019
- Adding Container Images to Google Container Registry (GCR) - October 21, 2019
When it comes to VCS (Version Control System), we will have confusion as we have many products in market with almost same capabilities. When we think about enterprise level usage, GitLab, GitHub, Subversion, Bitbucket etc. will come on top of the list and some are with enterprise level support too.
Please note, SCM (Software Configuration Management) is not same as VCS but, VCS is a part or subset of SCM.
Installing our own git server with GUI is not a big deal as we have gitlab-ce (Learn more) which is free and another option is self-hosted bitbucket (but not free), or you can go for other premium VCS solutions. Fortunately, we have a simple opensource product called Gogs, which itself described as “A painless self-hosted Git service“. Yes, you can setup your own gitlab/github like git server with Gogs. You have different choices for installation from source, from packages, from binaries or just run it inside a docker container.
Let’s build a Gogs git server using docker container.
Prepare Docker Image and Data directory
Create a local directory for storing data and repositories. For production, you can point this to any nfs or cloud disks.
[email protected]:~$ mkdir gogs [email protected]:~$ ls -l total 4 drwxrwxr-x 2 devops devops 4096 Oct 22 04:56 gogs
Get Gogs docker image
[email protected]:~$ sudo docker pull gogs/gogs Using default tag: latest latest: Pulling from gogs/gogs 9d48c3bd43c5: Pull complete 1013a6a6073e: Pull complete f074cb3ecafc: Pull complete 33433d770f0d: Pull complete b464f169dfd9: Pull complete 77e3c5692f7d: Pull complete e6d8ab097b45: Pull complete 13266a8e4353: Pull complete 2ac951b0051b: Pull complete 266414b76811: Pull complete Digest: sha256:48cd3d14f6d5c9f73cd462b42e67f7a021b299da8fdaa2003cc164fe6ed08a38 Status: Downloaded newer image for gogs/gogs:latest
Start docker container
[email protected]:~$ sudo docker run --name=gogs -p 10022:22 -p 10080:3000 -v ~/gogs:/data gogs/gogs
Do not forget to map the port for ssh (10022:22) and http (10080:3000) etc. You can customize these ports inside container if you want. Also see, we have mounted ~/gogs to /data inside container.
Now, you check your machine IP with your http port as we need to setup first time setup. (here my localmachine is a GCP instance, hence I will use the public IP of the same)
If you are using a database, you can choose MySQL, PostgreSQL or MSSQL; in this case I use SQLite for quick demo.
Customize whatever parameters you need and add an initial admin user to login. Then Install Gogs.
Note: Install script will reload browser to localhost:3000/user/login, which will not work if you are using a cloud instance or Gogs inside docker. Please remember to put public IP or your DNS name in place of public url.
Open the url in browser again and you can see the welcome screen.
Login with the credential you have created during install and create your very first repo inside.
That’s all, you have your own git server with Web GUI.
Start Docker detached or Start it again.
If you stopped docker container, start it again as volume mapping will be there.
[email protected]:~$ sudo docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 583d7b1b136a gogs/gogs "/app/gogs/docker/st…" 20 minutes ago Exited (0) 8 seconds ago gogs [email protected]:~$ sudo docker start gogs gogs [email protected]:~$ sudo docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 583d7b1b136a gogs/gogs "/app/gogs/docker/st…" 21 minutes ago Up 3 seconds 0.0.0.0:10022->22/tcp, 0.0.0.0:10080->3000/tcp gogs
[email protected]:~$ sudo vim ~/gogs/gogs/conf/app.ini