Add gitlab-runner in docker-swarm mode

How add gitlab runner to gitlab in swarm mode(fuck kubernetes).
Create docker-compose.yml

#docker stack deploy --compose-file=docker-compose.yml gitlab-runner
version: '3.3'
services:
  gitlab-runner:
    image: gitlab/gitlab-runner:alpine-v10.6.0
    restart: always
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      ###comment for first run
      #- ./configs/gitlab-runner:/etc/gitlab-runner
    networks:
      gitlab-runner:
        aliases:
          - gitlab-runner
    deploy:
        #endpoint_mode: dnsrr
        #mode: replicated
        replicas: 1
        resources:
          # Hard limit - Docker does not allow to allocate more
          limits:
            cpus: '2'
            memory: 1200M
          # Soft limit - Docker makes best effort to return to it
          reservations:
            #cpus: '0.25'
            memory: 16M
        # service restart policy
        restart_policy:
          condition: on-failure
          delay: 5s
          max_attempts: 8
          window: 3s
        # service update configuration
        update_config:
          parallelism: 1
          delay: 10s
          failure_action: continue
          monitor: 60s
          max_failure_ratio: 0.3
        # placement constraint - in this case on 'worker' nodes only
        placement:
          constraints: [node.role == manager]
##NETWORKS
networks:
  gitlab-runner:
    driver: overlay

Deploy to swarm

docker stack deploy --compose-file=docker-compose.yml gitlab-runner

Add runner to gitlab.
1. Obtain a token for a shared or specific Runner via GitLab’s interface

https://gitlab.itc-life.ru/admin/runners

2. Register runner
Docker
To register a Runner using a Docker container:

Run the following command:

docker exec -it gitlab-runner gitlab-runner register

Enter your GitLab instance URL:

Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com )
https://gitlab.com

Enter the token you obtained to register the Runner:

Please enter the gitlab-ci token for this runner
xxx

Enter a description for the Runner, you can change this later in GitLab’s UI:

Please enter the gitlab-ci description for this runner
[hostame] my-runner

Enter the tags associated with the Runner, you can change this later in GitLab’s UI:

Please enter the gitlab-ci tags for this runner (comma separated):
my-tag,another-tag

Choose whether the Runner should pick up jobs that do not have tags, you can change this later in GitLab’s UI (defaults to false):

Whether to run untagged jobs [true/false]:
[false]: true

Choose whether to lock the Runner to the current project, you can change this later in GitLab’s UI. Useful when the Runner is specific (defaults to true):

Whether to lock Runner to current project [true/false]:
[true]: true

Enter the Runner executor:

Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell:
docker

If you chose Docker as your executor, you'll be asked for the default image to be used for projects that do not define one in .gitlab-ci.yml:

Please enter the Docker image (eg. ruby:2.1):
alpine:latest

3. Save config persist

mkdir -p configs/gitlab-runner
cd configs/gitlab-runner
docker cp gitlab-runner_gitlab-runner.1.th8m8ajzsa1p3ynjjs9yzyioi:/etc/gitlab-runner/config.toml .

4. Unncomment line in docker-compose.yml

    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      ###comment for first run
      - ./configs/gitlab-runner:/etc/gitlab-runner

5. Change line in config config.toml

privileged = true

6. My gitlabrunner config.toml file as example

concurrent = 10
check_interval = 0
[[runners]]
  name = "itc_runner"
  url = "https://git.itc-life.ru"
  token = "878680df32323232322f248734e9"
  executor = "docker"
  limit = 0
  output_limit = 20000000000
  [runners.docker]
    tls_verify = false
    image = "alpine:latest"
    privileged = true
    disable_cache = false
    volumes = ["/cache"]
    shm_size = 0
    ##Для того чтобы не было Job's log exceeded limit of 4194304 bytes.
    output_limit = 2228192
  [runners.cache]

I set custom dns serveer and increase running job at once to 10.
Profit.

Добавить комментарий

Войти с помощью: 

Ваш e-mail не будет опубликован. Обязательные поля помечены *

 

Этот сайт использует Akismet для борьбы со спамом. Узнайте как обрабатываются ваши данные комментариев.