Centos 7 - Gitlab CI

Install gitlab runner

Git

For shell executor we need git with fetch-pack support (git  2.x ?)

$ git --version

Remove git 1.8 and install git 2.2:

# yum install -y https://repo.ius.io/ius-release-el7.rpm
# rpm -e --nodeps git
# rpm -e --nodeps perl-Git
# yum install -y git222

Network forwarding

Make sure ip forwarding is enabled:

# cat /proc/sys/net/ipv4/ip_forward
# vim /etc/sysctl.conf
...
net.ipv4.ip_forward = 1

# sysctl -p /etc/sysctl.conf
# cat /proc/sys/net/ipv4/ip_forward

Gitlab-runner install from repo

Get <TOKEN> from gitlab -> project -> settings -> CI/CD -> Runners -> Set up a specific runner manually

# curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh" | sudo bash
# export GITLAB_RUNNER_DISABLE_SKEL=true; yum install gitlab-runner

Regiter non-interactively:

# gitlab-runner register --non-interactive --url https://gitlab.com/ --registration-token <TOKEN> --executor shell --docker-image "7.4-fpm-alpine" --docker-privileged=true --tag-list <tag_name,other_tag_name>

( or register interactively):

# gitlab-runner register

Enter the GitLab instance URL (for example, https://gitlab.com/):
https://gitlab.com/

Enter the registration token:
<TOKEN>

Enter an executor: custom, parallels, ssh, docker-ssh+machine, kubernetes, docker, docker-ssh, shell, virtualbox, docker+machine:
shell

Enter the default Docker image (for example, ruby:2.6):
7.4-fpm-alpine

Add gitlab-runner user to docker group:

# usermod -aG docker gitlab-runner

Run:

# systemctl start gitlab-runner; systemctl status gitlab-runner

Install docker

http://codingtools.net/cheatsheet/centos7-docker

Start docker swarm

# docker swarm init --advertise-addr=eth0

Push docker image to gitlab registry

Add gitlab personal access token:

  1. go to: https://gitlab.com/-/profile/personal_access_tokens
  2. add permissions:
    1. read registry
    2. write registry
  3. save token

Login to gitlab registry:

$ docker login registry.gitlab.com
Username: <gitlab_email>
Password: <token>

Tag the local container with gitlab full path & tag:

$ docker tag <ID_of_the_image> registry.gitlab.com/project-path/project-name/image-name:version-tag

Push it to gitlab registry:

$ docker push registry.gitlab.com/project-path/project-name/image-name:version-tag