Running GitLab in the Cloud with Azure

    Introduction

    One of the first things that you should do before starting a software project is set up a version control system (VCS) for your code. A version control system allows you to track changes for your code, concurrently maintain different versions (i.e. production and development) and simplifies the task of merging and integrating contributions from multiple developers. One of the most popular VCS is Git, a distributed version control and source code management system. Though Git itself is mainly a collection of command line tools, many people manage Git repositories using third party tools and services, such as GitHub, Gitorious or GitLab.

    GitLab is a Ruby on Rails web application that helps you manage who has permissions to contribute to which repository. It also includes a wiki, enables code reviews and many other features. GitLab CI is a complementary web application that provides Continuous Integration closely integrated with Git to run tasks after a new change or run tests in different branches in the repository.

    This guide describes how to create your own Git repository and integrate it with a Continuous Integration server in the cloud with Windows Azure and a BitNami GitLab virtual machine.

     

    Using a Windows Azure cloud server for hosting your source control repositories has a number of advantages, including:

    • The ability to resize the server as needed. You can start with a small virtual machine and as your needs change, easily scale it up or down
    • Easily create full backups of the server, which can be used to create replicas to test upgrade procedures or to restore the full server in case of catastrophic failure
    • Provide great connectivity, important when you are managing a distributed team or transferring large amounts of code or data
    • Easily monitor server performance and manage security settings

     

    GitLab & GitLab CI

    GitLab is a self-hosted Git management software application written in Ruby on Rails and distributed under an open source license. GitLab simplifies the task of managing Git projects: you can enable or disable access per user and per project, keep track of project activities, code reviews, merge requests or track issues. GitLab CI allows you to run tasks with the project code. It is useful for automating the tests or the release process.

    BitNami provides a free, pre-configured GitLab virtual machine that you can deploy in Windows Azure. The image is based on Ubuntu and ships all of the required dependencies for running GitLab and GitLab CI, including a web server, database and Ruby on Rails runtime. This means you can get started with GitLab right away, without having to install or configure it.

     

    gitlab1.png

     

    The BitNami GitLab VM Depot image

    The BitNami GitLab image for Windows Azure is available in the VM Depot catalog. This image can be deployed directly from the catalog or from the Windows Azure management console web interface. This section will cover how to deploy this image in Windows Azure, so you will need to have a Windows Azure subscription account to follow along with the process (free trials are available if you don’t already have a subscription).

    Once you are logged into Windows Azure, go to the "Virtual Machines" section, then click on the "Images" tab, and in "Browse VM Depot" at the bottom of the page. In addition to the GitLab image, you can find other useful open source applications packaged by BitNami, such as Alfresco, for managing documents or SugarCRM for managing customer relationships.

     

    gitlab2.png

     

    If you complete the process outlined previouslyshort wizard, you will now have the GitLab image in your “Images” section. Select it and click on the "Register" button.

    Once the new image is addedavailable, click on “New” in the left bottom corner. Select "Virtual Machine" and then the "From Gallery" option. Go to "My Images" in the new pop-up window and select your new image.

    Now it is necessary to configure the virtual machine. You should assign sufficient resources for the machine based on how many users are going to access the application simultaneously. GitLab does not require a lot of resources so you can start with an “Extra small” virtual machine and then, if you need to improve its performance, you can simply resize the server later on. This is one of the advantages of deploying applications in the Cloud.

    At this point, you have two ways of configuring authentication in the server: using a SSH key or providing a password. The recommended way to use an SSH key. This guide provides the information you need for creating the required keys.

     

    gitlab3.png

     

    In the next screen, you can configure the domain name. For this tutorial, we selected bitnamigitlab.cloudapp.net. You will need to select a different one. Once you have completed the new machine wizard, click "Virtual Machines" in the left menu, and select your new server. After a few minutes, the machine will be running.

    It is important to allow remote connections to the web application. By default, the only accessible port at this point is the SSH port (22). It is necessary to configure the Virtual Machine “Endpoint” to allow connections to the HTTP port (80), this is done by selecting the Virtual Machine in your management portal and selecting “Endpoints”. Once you have done this, you should be able to go the application domain from your browser and see the welcome screen below.

     

    gitlab4.png

     

    For more details on how to start the BitNami GitLab image in Windows Azure, you can find a step-by-step tutorial here.

    How to create a Git repository in GitLab

    The default Admin credentials for GitLab are:

    Username: user

    Password: bitnami

    You should change these default values right away. You can change the password and the email in the “User’s Profile” section, where you can also upload your public SSH key. This key will be necessary to push the code into the repository and it will be also required for all new users that need privileges to modify the code.

     

    gitlab5.png

     

    Now you can create your first Git project in GitLab and follow the steps to upload the code. At this point, you must have a Git client installed in your desktop or laptop local machine. There are different ways to install Git in a development environment. An easy way to install Git is using BitNami WAMP, LAMP or MAMP stacks. These stacks provide a complete PHP, MySQL and Apache development environment for Windows, Linux or OS X. They also install Git so you can use them for syncing the files with the repository.

     

    gitlab6.png

     

    You can upload your project files to the GitLab repository by following the steps above. It is important to copy your private key in the SSH folder according to your platform:

    For Windows: "C:\Users\user_name\.ssh\id_rsa"

    For Linux: "/home/user_name/.ssh/id_rsa"

    For OS X: "/Users/user_name/.ssh/id_rsa"

     

     

    If the configuration is correct, you have just pushed the README.txt file into the repository and you can see it in the GitLab web application.

     

    GitLab administration

    BitNami GitLab images can be customized in a variety of ways. As you have access to all the files in the server, the domain name or the email settings are easily customizable.

     

    gitlab8.png

     

    Custom domain name

    Once the Gitlab application is up and running, it is possible to use a custom domain. The only requirement is that the domain points to the server’s IP address or the cloudapp.net domain. Then, run the following command to configure it automatically, substituting gitlab.example.com by your domain name:

    $ sudo /opt/bitnami/apps/gitlab/bnconfig --machine_hostname gitlab.example.com

    Note that this command runs every time that you restart the machine and uses the public IP address of the server by default. If you already configured the domain, rename or remove the “bnconfig” tool in order to prevent it from changing every time the machine is rebooted.

    $ sudo mv /opt/bitnami/apps/gitlab/bnconfig /opt/bitnami/apps/gitlab/bnconfig.back
    Email settings

    The BitNami GitLab application does not configure email settings by default. This step is required for the application to send notifications via email. It is recommended that you use an email provider for sending the emails from the application. For this purpose, you can use a free email service like Hotmail, Office365, Yahoo or GMail. That should work for small or test deployments of Gitlab, but it you have a larger installation that needs send a lot of email, you risk your emails being throttled.

    The example below describes how to configure GitLab with GMail for sending emails through SMTP. Edit the file production.rb and set the following settings:

    $ nano /opt/bitnami/apps/gitlab/htdocs/config/environments/production.rb
    config.action_mailer.raise_delivery_errors = true
    config.action_mailer.delivery_method = :smtp
    config.action_mailer.perform_deliveries = true
    config.action_mailer.smtp_settings = {
        :address => "smtp.gmail.com",
        :port => 587,
        :domain => "gmail.com",
        :authentication => :plain,
        :user_name => "your_account@gmail.com",
        :password => "your_password",
        :enable_starttls_auto => true
    }

    Then restart the Apache server:

    $ sudo /opt/bitnami/ctlscript.sh restart apache
    Configuring GitLab

    Managing projects from the GitLab application is extremely easy. From the “Admin” panel it is possible to add new users or to create teams and groups with different permissions within a projects.

     

    gitlab9.png

     

    GitLab projects can be set up as public too. That means that any user has read access for that project and is able to clone the project with the command below.

    $ git clone http://bitnamigitlab.cloudapp.net/gitlab/example.git

     

    Server management

    It is possible to manage all the GitLab servers using the “/opt/bitnami/ctlscript.sh” tool. GitLab requires the following servers:

    • A MySQL database
    • An Apache server configured with a Passenger module for Ruby on Rails apps
    • A Redis server for storing the job messages
    • A GitLab Sidekiq server for processing the jobs in the background

     

    You can log into the server through SSH and check the status of the servers with the command below:

    $ sudo /opt/bitnami/ctlscript.sh status

     

    For troubleshooting problems with the servers, you can typically find the required information in each server’s log files:

    Apache: /opt/bitnami/apache2/error_log

    MySQL: /opt/bitnami/mysql/data/mysqld.log

    Redis: /opt/bitnami/redis/var/log/redis-server.log

    GitLab Sidekiq: /opt/bitnami/gitlab/htdocs/log/sidekiq.log

    GitLab CI Sidekiq: /opt/bitnami/gitlabci/htdocs/log/sidekiq.log

    Sidekiq ships a control panel where it is possible to check the logs and the status of the jobs.

     

    gitlab10.png

     

    How to integrate GitLab & GitLab CI

    This section explains how to fully integrate GitLab and GitLab CI for running tasks automatically. This example will cover how to run the unit tests of a Ruby on Rails project, Redmine.

    It is necessary to create a public and private key for the “gitlab_ci” user in the server, so this user will have read access to the chosen repositories. Once logged in the server through SSH, run the following command and do not specify any password for the key:

    $ sudo su gitlab_ci -c "ssh-keygen -t rsa"

    Then read the new public key and copy the contents in a file. GitLab will give read-only privileges to this user account.

    In GitLab, go to the project “Settings” and add a new “Deploy Key”. Then copy the public key created previously. When you copy the key, make sure the key content does not contain newlines.

     

    gitlab11.png

     

    Now the “gitlab_ci” user will be able to clone the repository in the server running the commands below.

    $ sudo su gitlab_ci
    $ mkdir repositories
    $ cd repositories
    $ git config --global user.name 'Administrator'
    $ git config --global user.email 'user@example.com'
    $ git clone git@bitnamigitlab.cloudapp.net:example.git"
    Cloning into 'example'...
    remote: Counting objects: 3, done.
    Receiving objects: 100% (3/3), 201 bytes, done. remote: Total 3 (delta 0), reused 0 (delta 0)

     

    Now it is time to access to the GitLab CI application. In this example GitLab CI is running at “http://bitnamigitlab.cloudapp.net/gitlabci”.

    The default credentials for GitLab CI are:

    email: user@example.com

    password: bitnami

    You will need to change them from in User’s profile section.

    For enabling this new repository in the GitLab CI application, create a new project and configure the following options:

    - Name: Example

    - Token: (blank)

    - Path: /home/gitlab_ci/repositories/example

    - Follow branches: master

     

    gitlab12.png

     

    Once created, click on the “Details” tab because the “Project URL” and “Project Token” are required for the next step.

     

    gitlab13.png

     

    GitLab requires these settings for finishing the integration. Go to the GitLab project settings and configure GitLab CI in the “Services” tab. Fill "Project URL" and "Project Token" with the values from the previous step and press “Save”. This is the last step for integrating both applications.

     

    Running a sample test

    A Continuous Integration process typically performs different tasks: running tests, measuring performance, building releases and other tasks. The example below describes how to upload a Ruby on Rails project to a GitLab repository and run the unit tests in GitLab CI. This example will use the Redmine project code, a popular Project Management tool.

    After downloading and extracting the Redmine project files, uncompress them in the previously created GitLab project folder.

    Before pushing all of the Redmine files, it is necessary to create the database.yml config file with the configuration below. This example will use a SQLite database, so it requires you to add the “sqlite3” gem in the Gemfile.

     

    gitlab14.png

     

    Now you can push all the files into the repository:

    $ git add .
    $ git commit -m “Redmine files”
    $ git push

    For configuring the tasks in GitLab CI, go to the project and edit the “Scripts” section. The example below will configure and run the Redmine unit tests.

    bundle install --binstubs --path vendor/gems
    bin/rake db:create
    bin/rake db:migrate
    bin/rake test:units

     

    gitlab15.png

     

    Finally, run the test from the GitLab CI application. If everything was properly configured, the Redmine unit tests will be executed and you can check the results directly in the GitLab CI panel.

     

    gitlab16.png

    gitlab17.png

     

    Summary

    BitNami GitLab allows you to easily create and manage your own Git repository in Windows Azure. Some advantages of running your own repository in a Cloud include:

    • Full control of the server
    • Flexibility to customize the application as required
    • Ability to resize your server as needs change
    • Centralized control panel for managing administrative tasks
    Tag page (Edit tags)
    • No tags
    Page statistics
    12190 view(s), 11 edit(s) and 26769 character(s)

    Comments

    You must login to post a comment.

    Attach file

    Attachments

    FileSizeDateAttached by 
     azure-free.png
    Azure free trial
    5.25 kB17:24, 3 Oct 2013AdminActions
     gitlab1.png
    GitLab application
    71.35 kB10:05, 3 Oct 2013AdminActions
     gitlab10.png
    GitLab Sidekiq
    126.71 kB10:36, 3 Oct 2013AdminActions
     gitlab11.png
    GitLab CI deploy key
    117.58 kB10:39, 3 Oct 2013AdminActions
     gitlab12.png
    GitLab CI project
    58.18 kB10:41, 3 Oct 2013AdminActions
     gitlab13.png
    GitLab CI project details
    77.49 kB10:42, 3 Oct 2013AdminActions
     gitlab14.png
    GitLab CI sample
    32.64 kB10:43, 3 Oct 2013AdminActions
     gitlab15.png
    GitLab CI sample
    64.79 kB10:44, 3 Oct 2013AdminActions
     gitlab16.png
    GitLab CI sample
    57.71 kB10:46, 3 Oct 2013AdminActions
     gitlab17.png
    GitLab CI sample
    35.26 kB10:46, 3 Oct 2013AdminActions
     gitlab2.png
    GitLab azure image
    111.94 kB10:23, 3 Oct 2013AdminActions
     gitlab3.png
    GitLab azure image
    76.96 kB10:25, 3 Oct 2013AdminActions
     gitlab4.png
    GitLab welcome
    86.16 kB10:26, 3 Oct 2013AdminActions
     gitlab5.png
    GitLab ssh key
    102.33 kB10:28, 3 Oct 2013AdminActions
     gitlab6.png
    GitLab project
    58.25 kB10:29, 3 Oct 2013AdminActions
     gitlab7.png
    Git console for Windows
    16.38 kB10:30, 3 Oct 2013AdminActions
     gitlab8.png
    GitLab console
    49.22 kB10:31, 3 Oct 2013AdminActions
     gitlab9.png
    GitLab dashboard
    64.08 kB10:34, 3 Oct 2013AdminActions