question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for docker services in runner config

See original GitHub issue

Currently,

what I try to achieve is also to configure predinefed services for some runner. This could be done through runner/configuration/advanced-configuration.html#the-runnersdockerservices-section

So currently I don’t know how this could be achieved by using this role.

What I did try but without success was the following:

gitlab_runner_coordinator_url: "https://gitlab.example.com"
gitlab_runner_listen_address: "0.0.0.0:9097"
gitlab_runner_runners:
  - name: '{{ ansible_hostname }}'
    state: present
    executor: docker
    docker_image: 'docker:19.03-git'
    tags:
      - docker
      - dind
    env_vars: [
      "DOCKER_AUTH_CONFIG={\"auths\":{\"docker.example.com\":{\"auth\":\"<my-secret>\"}},\"HttpHeaders\":{\"User-Agent\":\"Docker-client/18.09.5 (linux)\"}}",
      "DOCKER_DRIVER=\"overlay2\"",
    ]
    run_untagged: false
    # Docker privileged mode
    docker_privileged: true
    docker_volumes:
      - "/cache"
      - "/etc/docker/certs.d:/etc/docker/certs.d"
      - "/var/lib/docker"
    extra_configs:
      runners.docker:
        wait_for_services_timeout: 15
      runners.docker.services: 
        - name: "docker:19.03-dind"

I hope someone can help me. Thanks in advance.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
riemerscommented, May 5, 2022

If your happy with the code and tested it, no reason not to make a PR for it. I have reverted PR’s in the past because of issues but that is the point of the test and its a community effort 😃

1reaction
marcelbruecknercommented, Mar 5, 2022

I quickly hacked something together to make this work. I say hacked as I’m not too deep into your role and I’m unsure if this is the way to go for adding that feature. However, it’s looking quite ok for a midnight development session 😃

  1. Added my services configuration as docker_services to gitlab_runner_runners

    gitlab_runner_runners:
      - name: "{{ inventory_hostname }}-docker"
        executor: docker
        # ... some other config omitted for readability ...
        docker_services:
          - name: docker:20.10.12-dind
            command: ["--insecure-registry=10.0.0.0/24"]
    
  2. Created a template file templates/config.runners.docker.services.j2

    {% for service in gitlab_runner.docker_services %}
        [[runners.docker.services]]
    {% for attr in service %}
          {{ attr }} = {{ service[attr] | to_json }}
    {% endfor %}
    {% endfor %}
    
  3. Added the following to tasks/update-config-runner.yml

    # Task named "{{ runn_name_prefix }} Set runner docker network option" comes before
    
    #### [[runners.docker.services]] section ####
    - name:  "{{ runn_name_prefix }} Set additional services"
      blockinfile:
        dest: "{{ temp_runner_config.path }}"
        content: "{{ lookup('template', 'config.runners.docker.services.j2') if gitlab_runner.docker_services is defined }}"
        state: "{{ 'present' if gitlab_runner.docker_services is defined else 'absent' }}"
        marker: "# {mark} runners.docker.services"
        insertafter: EOF
      check_mode: no
      notify:
      - restart_gitlab_runner
      - restart_gitlab_runner_macos
    
    #### [runners.custom_build_dir] section ##### comes next
    

That’s it. This looks like so in my GitLab runner configuration and works quite well for my needs.

[[runners]]
  name = "runner-docker"
  executor = "docker"
  # ... some other config omitted for readability ...
  [runners.cache]
  [runners.docker]
    volumes = ["/root/.docker/config.json:/root/.docker/config.json:ro", "/certs/client", "/cache"]
    image = "docker:20.10.12"
    privileged = true
    disable_entrypoint_overwrite = false
    oom_kill_disable = false

# BEGIN runners.docker.services
    [[runners.docker.services]]
      name = "docker:20.10.12-dind"
      command = ["--insecure-registry=10.0.0.1/8"]
# END runners.docker.services
Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced configuration - GitLab Docs
The [runners.docker] section. The following settings define the Docker container parameters. Docker-in-Docker as a service, or any container runtime configured ...
Read more >
Using docker build · Docker · Ci · Help · GitLab
To run Docker commands in your CI/CD jobs, you must configure GitLab Runner to support docker commands. Enable Docker commands in your CI/CD...
Read more >
Using docker images · Docker · Ci · Help · GitLab
Configuring services. Many services accept environment variables which allow you to easily change database names or set account names depending on the ...
Read more >
Docker Engine post-installation steps
Configure Docker to start on boot with systemd . Many modern Linux distributions use systemd to manage which services start when the...
Read more >
About service containers - GitHub Docs
You can configure jobs in a workflow to run directly on a runner machine or in a Docker container. Communication between a job...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found