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-v12.2.0
    restart: always
    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'
    networks:
      gitlab-runner:
        aliases:
          - gitlab-runner
    ports:
      - '8093:8093'
    environment:
      DEBUG: 'True'
      #DOCKER_HOST: 'tcp://docker:2375/'
    deploy:
        #endpoint_mode: dnsrr
        #mode: replicated
        replicas: 1
        resources:
          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 ]
  docker:
    image: docker:18-dind
    restart: always
    privileged: true
    environment:
      DOCKER_DRIVER: overlay2
      #DOCKER_TLS: 'False'
    volumes:
      - dind:/var/lib/docker
      - 'gitlab-runner-cache:/cache'
      - 'gitlab-runner-cache-docker:/dockercache'
    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:
  runner-config:
  dind:
  gitlab-runner-cache:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: /temp/gitlab-runner-cache
  gitlab-runner-cache-docker:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: /temp/gitlab-runner-cache-docker
##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 = 3
check_interval = 0
log_level = 'debug'
[session_server]
  listen_address = '0.0.0.0:8093'
  advertise_address = 'gitlab-runner:8093'
  session_timeout = 1800
[[runners]]
  name = 'my-runner'
  url = 'https://gitlab.com/'
  token = 'TOKEN'
  executor = 'docker'
  limit = 0
  output_limit = 20000000000
  #[runners.custom_build_dir]
  [runners.docker]
    environment = ["DOCKER_TLS_CERTDIR="]
    host = 'tcp://docker:2375/'
    tls_verify = false
    #image = 'alpine:3.9.4'
    image = 'alpine/git:1.0.7'
    helper_image = 'gitlab/gitlab-runner-helper:x86_64-3936b058'
    privileged = true
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    cache_dir = '/dockercache'
    volumes = ['/cache']
    shm_size = 0
    output_limit = 228192000
  [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_BUILD_VERSION: '19.03.2-ce'
    DOCKER_TLS_CERTDIR: ""

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

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

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

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

 

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