Monday, May 13, 2013

Deploy GitLab & GitLab CI in the cloud with BitNami

The GitLab CI application won recently the BitNami bi-weekly packaging contest. Our users chose it to be added to the BitNami library, just as with GitLab previously. GitLab CI is an open-source continuous integration server, closely integrated with GitLab.

As GitLab and GitLab CI have been designed to work together, we have decided to package both in the same GitLab BitNami stack. By launching a recent BitNami GitLab cloud image, (later than version 5.1.0-3), you will have access to both GitLab and GitLab CI. GitLab will be accessible at "/gitlab" and GitLab CI at "/gitlabci"

You can find below a step by step guide on how to perform full integration between them for a sample project. This integration consists on the ability of running a task from GitLab CI when an user makes a commit in a GitLab repository. To achieve that, please perform the following steps:

1. Add a project on GitLab.

Commiting on GitLab
2. Create a ssh key for the gitlab_ci user in this machine without a password. This key will allow GitLab CI to have read access to chosen repositories:

sudo su gitlab_ci -c "ssh-keygen -t rsa"
    3. Add this key as "Deploy Keys" on the GitLab project. On GitLab, go to Projects -> BitNami sample project -> Settings -> Deploy Keys -> Add deploy key and paste the key generated previously and save it with any name you want.

    4. On your personal machine start the repository as is described at GitLab. This step is not related to the integration with GitLab CI but the repository should be started to be able to perform the remaining steps.

    5. Clone the repository with the gitlab_ci user on the GitLab server.
        $ sudo su gitlab_ci
        $ mkdir /opt/bitnami/apps/gitlabci/repositories
        $ /opt/bitnami/git/bin/git config --global 'Administrator'
        $ /opt/bitnami/git/bin/git config --global ''
        $ cd /opt/bitnami/apps/gitlabci/repositories/
        $ /opt/bitnami/git/bin/git clone git@<hostname_gitlab_server>:bitnami-sample-project.git"
        Cloning into 'bitnami-sample-project'...
        remote: Counting objects: 3, done.
        Receiving objects: 100% (3/3), 201 bytes, done. remote: Total 3 (delta 0), reused 0 (delta 0)

        6. Create the project on GitLab CI by selecting 'Add project' on the GitLab CI application with the following parameters and saving it.
         - Name: bitnami-sample-project
         - Token: (blank)
         - Path: /opt/bitnami/apps/gitlabci/repositories/bitnami-sample-project
         - Follow branches: master
         - Scripts: ls

        Once created, press "Details" because the "Project URL" and "Project Token" are required for the next step.

        7. Enable GitLab CI on the repository created on GitLab. To do so, go to GitLab -> Projects -> BitNami sample project -> Settings -> Services -> GitLab CI. Select "Active" and fill "Project URL" and "Project Token" with the values from the previous step and press Save.

        8. GitLab integration with GitLab CI is complete! To test it is working, just commit a new file from your personal machine. Then on GitLab CI you should be able to see something similar to the following:
            GitLab CI running tasks when commiting on GitLab
            BitNami Gitlab Stack provides a one-click install solution for GitLab. Download installers and virtual machines or run your own GitLab server in the cloud.