Deploy a Azure Web App using Gitlab – Part 1

So recently I decided to start writing about things that I want to learn and that interest me. One of the first things I thought of doing was to use Gitlab to deploy virtual machines on Azure. I recently saw the power of using Desired State Configuration (DSC) to manage Windows machines, which were deployed from Gitlab. Basically you can deploy entire environments with some simple code. I thought this was amazing and I wanted to learn how to do this.

But I wanted to start small, and first set up an environment from where I can build more complex projects. So I decided to create a simple Azure Web app to test my environment. This Web App should be connected to a private Gitlab repository. In the process of building this environment I was faced with some challenges, so I thought why not make this the subject of my first blog post. I will show some basic configurations, including enabling HTTPS on Gitlab. And I will show how to deploy a simple website using Gitlab, by pushing code from a local pc.

Installing Gitlab

I’m going to use Azure to host a virtual machine on which Gitlab is installed. Deploying a new Gitlab server is easy because Azure already has templates you can use. So I logged in to Azure and choose Virtual Machines -> Add. There you can use the filter to look for the Gitlab Community Edition. This is a free to use edition of Gitlab. After you selected the correct template you can give your machine a name, and some basic settings. I like to use a password instead of a ssh key, because this is easier for demonstration purposes.

Next choose a size. The server doesn’t need much processing power so a DS1_V2 Standard size should be enough, and choose next. The settings step can be left at the default settings. And in the summery you can create the VM.

After the deployment is completed, you should be able to get the public IP address of the VM in the overview.

Copy and paste the IP address into your browser. If everything went well you should see a Gitlab page where you are asked to change your password. Make sure to write it down since it will be your root admin password.

After you’ve changed the password you can login using the root account.

Using the hosting providor of my website I added an A record to point the IP address of the gitlab server to gitlab.stephanvdkruis.nl.

Configuring Gitlab

After you finished installing the Gitlab server you probably want to change some basic settings before you can actually use Gitlab. One of the first things you will notice when you create a new project is that the URL of your project is something like http://gitlab-ce.hxakzvpf0otezeojz3wqhme5wg.cx.internal.cloudapp.net/root/example-project.git. My project name is example-project.

To address this issue we will need to connect to the Gitlab server via SSH. I like to use Putty, but you can choose whatever you like.

So connect to the Gitlab server and enter the credentials you used when creating the VM in Azure. When you are logged in, change to the Gitlab directory by using

cd /etc/gitlab/

Here you will find the gitlab.rb file (use ls to list the items in the folder). This file contains all the configurations for your Gitlab server. You can edit by using nano, a simple text editor, by typing

nano /etc/gitlab/gitlab.rb

I got a access denied at this point. This can be fixed to elevating to sudo su, and running the command again.

sudo su

nano /etc/gitlab/gitlab.rb

There you can find external_url. Here you can configure the URL to match your preferences. In my case this is http://gitlab.stephanvdkruis.nl. We will get back here when we enable HTTPS. For now, exit and save the file. Now run

gitlab-ctl reconfigure

This will reconfigure Gitlab. If you would return back to your browser and refresh it and you will have a more friendly URL to work with.

 Next

In the next part I will show you how to add a ssl certificate to Gitlab server so you can have a secure connection. So please continue reading in Deploy a Azure Web App using Gitlab Part 2. Also if anything is unclear or you want to comment please leave a message.

 

Leave a Reply

Your email address will not be published. Required fields are marked *