Deploy Gitlab Runner stack with docker swarm

2k Views Asked by At

I'm trying to deploy a gitlab runner stack in docker-compose above:

version: '3.8'

services:
     
  dind:
    image: docker:stable
    deploy:
      mode: replicated
      placement:
        constraints:
          - "node.role==worker"
      restart_policy:
        condition: any
    volumes:
      - /var/lib/docker
    command: 
      - --storage-driver=overlay2
    networks:
      - netrunner

  runner:
    image: gitlab/gitlab-runner:alpine
    deploy:
      mode: replicated
      placement:
        constraints:
          - "node.role==worker"
      restart_policy:
        condition: any
    volumes:
      - ./gitlab/runner:/etc/gitlab-runner:Z
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      - DOCKER_HOST=tcp://dind:2375
    depends_on:
      - dind
    networks:
      - netrunner

  register-runner:
    image: gitlab/gitlab-runner:alpine
    deploy:
      mode: replicated
      placement:
        constraints:
          - "node.role==worker"
      restart_policy:
        condition: none
    volumes:
      - ./gitlab/runner:/etc/gitlab-runner:Z
    command:
      - register
      - --non-interactive
      - --locked=false
      - --name=Docker Runner
      - --executor=docker
      - --docker-image=docker:stable
      - --docker-volumes=/var/run/docker.sock:/var/run/docker.sock
    environment:
      - CI_SERVER_URL=https://gitlab.com/
      - REGISTRATION_TOKEN=xxxxxxxxxxxxxx
    networks:
      - netrunner

networks:
  netrunner:
    driver: overlay
    driver_opts:
      foo: "1"

Then, with docker swarm initialized, I try the deployment with this pattern:

docker stack deploy --compose-file docker-compose.yml ci

After that, when I check services I get this:

$ docker stack services ci
ID                  NAME                 MODE                REPLICAS            IMAGE                         PORTS
8ahvxamblhmc        ci_dind              replicated          0/1                 docker:stable                 
fli2u5wszrvp        ci_register-runner   replicated          0/1                 gitlab/gitlab-runner:alpine   
zftmedknrwma        ci_runner            replicated          0/1                 gitlab/gitlab-runner:alpine  

I'm testing all the steps in docker playground using one manager and three workers. I have tried lots of variation of the compose.yml above. That one is the closest to correct, in my opinion. Replicas are not running. What should I do ?

0

There are 0 best solutions below