I spent a good bit of time working out all the bits and pieces needed to make this work, so I’m going to blog about it here as a way of documentation.
I wanted to run Gitlab and host my personal code repos myself. Gitlab is a pretty awesome project and the Docker container they provide is the perfect way to run this on my Ubuntu 14.04 server in my basement. I’m a total Docker amateur and this was a good reason to also learn how to manage this with Ansible 2.0. Feel free to tell me what I’m doing wrong in the comments – this is my first guess at the best way to do this and it does work.
Where I’m Installing This
This will run on an Ubuntu 14.04 server in my basement. This means it is behind my home router and shares an IP address on both my local network and publicly with a bunch of other services, so Gitlab can’t just assume it is the only thing running. This comes into plan when managing the ports Gitlab uses.
Running Gitlab CE Docker Container with Ansible
Some details removed for security, but this is essentially what I run in Ansible.
- name: Pull Gitlab Docker image
- name: Run Gitlab Docker container
You’ll see that this container will be addressed on the Ubuntu server at port 2225 for SSH, port 8085 for HTTP, and port 4443 for HTTPS. I send environmental variables to Gitlab to use my Mailgun account for sending emails.
I use Nginx to proxy_pass HTTP and HTTPS to the Gitlab container. I also do SSL termination here using a LetsEncrypt cert.
I use my
/etc/hosts file on my Ubuntu server to route traffic for gitlab.thelastcicada.com to 127.0.0.1 so I can access it from this same box.
Adding the Git Origin
When I first added the git origin (using SSH not HTTP), Gitlab asked for a password every time I tried to do a git push. This ended up being because I needed to specify port 2225 for the SSH connection instead of the default of port 22. I added the following in my ~/.ssh/config file to make any connection to this host use port 2225 for SSH:
I’ll need to do this on any host that I use to push code to my Gitlab server. I could solve this by having Gitlab use port 22 and setting SSH to the main Ubuntu server to use a different pot, but we’ll see how much of a pain this turns out to be.
I haven’t lived with this long enough to know if this is going to be my final configuration. I’ll update this post if I decide that improvements need to be made.