Add gitlab-runner in docker-swarm mode

How add gitlab runner to gitlab in swarm mode(fuck kubernetes).

In this example version docker 19.03.2

Create docker-compose.yml

sudo mkdir -p /docker-compose/SWARM/gitlab-runner
cd /docker-compose/SWARM/gitlab-runner
vim docker-compose.yml

Add data

version: '3.7'
services:
  gitlab-runner:
    image: gitlab/gitlab-runner:ubuntu-v14.4.0
    restart: always
    volumes:
      - '/var/run/docker.sock:/var/run/docker.sock'
      - './configs/gitlab-runner:/etc/gitlab-runner'
    networks:
      gitlab-runner:
        aliases:
          - gitlab-runner
    environment:
      DEBUG: 'True'
    deploy:
        replicas: 1
        resources:
          reservations:
            #cpus: '0.25'
            memory: 16M
        restart_policy:
          condition: on-failure
          delay: 5s
          max_attempts: 8
          window: 3s
        update_config:
          parallelism: 1
          delay: 10s
          failure_action: continue
          monitor: 60s
          max_failure_ratio: 0.3
        placement:
           constraints:  [ node.role == manager ]
  docker:
    image: docker:20.10.10-dind
    restart: always
    privileged: true
    environment:
      DOCKER_DRIVER: "overlay2"
      DOCKER_TLS_CERTDIR: ""
    volumes:
      - dind:/var/lib/docker
    dns:
      - 8.8.8.8
    networks:
      gitlab-runner:
        aliases:
          - docker
    deploy:
        replicas: 1
        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 ]
volumes:
  dind:
##NETWORKS
networks:
  gitlab-runner:
    driver: overlay

Deploy to swarm

sudo mkdir -p {/temp/gitlab-runner-cache,/temp/gitlab-runner-cache-docker}
docker-compose pull && docker-compose up -d 

Add runner to gitlab.

  1. Obtain a token for a shared or specific Runner via GitLab’s interface
https://gitlab.com/PROJECTURL/-/settings/ci_cd
  1. Register runner

To register a Runner using a Docker container:

Run the following command:

docker exec -it gitlab-runner_gitlab-runner_1 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
---CI_TOKEN

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

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/git:1.0.7
  1. Save config persist
mkdir -p configs/gitlab-runner
cd configs/gitlab-runner
docker cp gitlab-runner_gitlab-runner_1:/etc/gitlab-runner/config.toml .
  1. Unncomment line in docker-compose.yml

    volumes:
      - '/var/run/docker.sock:/var/run/docker.sock'
      - '/docker-compose/SWARM/gitlab-runner/configs/gitlab-runner:/etc/gitlab-runner'
      #- '/root/.docker/config.json:/root/.docker/config.json'
      - 'gitlab-runner-cache:/cache'
      - 'gitlab-runner-cache-docker:/dockercache'
  1. Change line in config config.toml
privileged = true
  1. My gitlabrunner config.toml file as example
concurrent = 5
check_interval = 0
log_level = "debug"
[[runners]]
  name = "runner-1"
  url = "https://git.linux2be.com"
  token = "sx-dsdsdsdHJjdsdsd"
  executor = "docker"
  environment = ["DOCKER_TLS_CERTDIR=","GIT_SSL_NO_VERIFY=true"]
  limit = 0
  output_limit = 20000000000
  cache_dir="/cache"
  [runners.custom_build_dir]
  [runners.docker]
    host = "tcp://docker:2375/"
    tls_verify = false
    image = "alpine/git:v2.32.0"
    helper_image = 'gitlab/gitlab-runner-helper:ubuntu-x86_64-bleeding'
    privileged = true
    extra_hosts = ["git.linux2be.com:10.28.0.1"]
    disable_entrypoint_overwrite = false
    oom_kill_disable = true
    disable_cache = false
    volumes = ["/cache"]
    shm_size = 0
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]

Stop docker-compose and deploy to swarm

docker-compose down

Deploy yo swarm

docker stack deploy -c docker-compose.yml gitlab-runner

Read about error connecting to docker via 2375

https://gitlab.com/gitlab-org/gitlab-ce/issues/64959

To fix this error add to .gitlab-vci.yml

variables:
    DOCKER_TLS_CERTDIR: ""

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

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

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

 

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