LinuxDay 2016 GitLab Workshop
First of all you need to install docker, we'll use Ubuntu 16.04 as base system, and you can just follow some simple instruction provided by digital ocean
For sake of completeness we provide the instruction here:
sudo apt-get update sudo apt-get upgrade sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | sudo tee /etc/apt/sources.list.d/docker.list sudo apt-get update sudo apt-get install -y docker-engine sudo systemctl status docker sudo usermod -aG docker $(whoami)
Now logout and login back again to apply the new group policy to your user.
The easier way to that everything went fine, is to run the sample hello-world container:
docker run hello-world
Now that docker is ready to go, we can start with GitLab. The official instruction can be found here
In one single command line:
docker run --detach \ --hostname gitlab \ --publish 443:443 --publish 80:80 --publish 22:22 \ --name gitlab \ --restart always \ --volume /srv/gitlab/config:/etc/gitlab \ --volume /srv/gitlab/logs:/var/log/gitlab \ --volume /srv/gitlab/data:/var/opt/gitlab \ gitlab/gitlab-ce:latest
Please note that we choose just
gitlab as hostname. This will ease
container connection later.
Play around with GitLab by opening your browser to http://localhost : the first time
you connect the system will ask you to configure a password for the
Now we want to setup GitLab CI which is a bit harder
The official docs can be found here:
First of all we need to create a runner. A GitLab runner is the worker which will be called by GitLab CI to execute the CI commands.
docker run -d --name gitlab-runner --restart always \ -v /var/run/docker.sock:/var/run/docker.sock \ -v /srv/gitlab-runner/config:/etc/gitlab-runner \ --link gitlab \ gitlab/gitlab-runner:latest
Please note that we connect this with the previously create GitLab instance with
--link parameter, which, in simple words, allow
the gitlab-runner container to resolve
gitlab hostname in the IP address of the container.
We also provision the docker socket because later docker will be used to execute the CI script.
Now is time to connect the two: in GitLab go into the admin area, and click on Overview -> Runners. Copy the registration token into the clipboard, you'll use it in a minute!
At shell prompt, run the follwing command, which will execute the gitlab-runner registration wizard:
docker exec -it gitlab-runner gitlab-runner register
Enter the follwing parameters:
- paste the token
- description: docker-runner
- executor: docker
- default docker image ruby:2.1
The executor is the way gitlab-runner will execute the GitLab CI script. Choosing docker will execute the CI script inside a container (which will be configured by the CI script itself). A simpler setup is the shell executor which will be execute the CI script locally in the docker-runner container.
However, due the fact that we don't have a real DNS setup, we need to configure gitlab runner to link the container it creates as executor to the GitLab container.
Connect to the runner container and open a shell in it:
docker exec -it gitlab-runner bash
Open with your favorit editor
links = [ "gitlab" ]
Easy to guess, this will just add
--link gitlab to the docker command line of the executor.
Everything is now ready for you first CI project!
Create a project, e.g. helloworld, with the following
#!/bin/bash echo hello GitLab CI world exit 0
Now create a
image: busybox job: script: - chmod +x helloworld.sh - ./helloworld.sh
Here it is:
- this will instruct the runner to use the busybox docker image as executor
- once the container starts, it will clone our project (this is where the
--linkwill come into)
- and it finally run the
scriptfor the CI
Make it fail!
The above CI will be successfull because all the commands return a zero exit code. Is preatty easy to break the CI: just edit
the code, directly from GitLab web interface if you want, to
exit 1, commit and.. you break the build!
Fixin it is left as an excercise to the reader.
Code Review Steps (s: senior, j: junior):
- s: helloworld, con exit 0
- s: .gitlab-ci.yml
- s: creare issue con modifica
- assegnare a junior
- j: new branch
- j: modifica readme + [ci skip]
- j: modifica exit 1 + this closes #1
- j: CI break build
- j: submit merge request + assign to s:
- s: code review
- j: fix issue with new branch
- auto-close issue with merge