Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #100 from tobiashuste/99-allow-to-configure-cpus-m…
Browse files Browse the repository at this point in the history
…emory-and-gpus

Allow to configure cpus, memory and gpus
  • Loading branch information
tobiashuste authored Nov 17, 2022
2 parents f016250 + 1cb14e7 commit eec7d7b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ specify for registering your GitLab-Runner with this Ansible role.
| `docker_devices` | `["/dev/kfd", "/dev/dri"]` | Add a host device to the container. Same syntax as the Docker `--device` flag. |
| `docker_volumes` | `["/cache", "/certs/client"]` | Additional volumes that should be mounted. Same syntax as the Docker -v flag. |
| `docker_shm_size` | `2147483648` | Shared memory size for images (in bytes). Default is 0 resulting in a fallback to the Docker default. |
| `docker_cpus` | `2` | Number of CPUs. Unset by default. |
| `docker_memory` | `2g` | Docker container memory limit. Unset by default. |
| `docker_gpus` | `all` | Specify GPUs to make available in Docker containers. Unset by default. |
| `docker_privileged` | `False` | Specify, if the container runs in privileged mode (insecure). Default is `False`. |
| `docker_tls_verify` | `True` | Specify, if TLS connections to the Docker daemon should be verified. Default is `False`. |
| `run_untagged` | `False` | Specify, if the runner can run jobs without tags. |
Expand Down
3 changes: 3 additions & 0 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ provisioner:
docker_security_opts: ["seccomp=unconfined"]
docker_volumes: ["/cache", "/certs/client"]
docker_devices: ["/dev/kfd", "/dev/dri"]
docker_cpus: 2
docker_gpus: "all"
docker_memory: "2g"
docker_image: "python:3.8"
tags: ["docker", "hifis"]
locked: True
Expand Down
9 changes: 9 additions & 0 deletions tasks/register.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
--docker-privileged="{{ gitlab_runner.docker_privileged | default(false) }}"
--docker-tlsverify="{{ gitlab_runner.docker_tls_verify | default(false) }}"
--docker-shm-size="{{ gitlab_runner.docker_shm_size | default(0) }}"
{% if gitlab_runner.docker_cpus is defined %}
--docker-cpus="{{ gitlab_runner.docker_cpus }}"
{% endif %}
{% if gitlab_runner.docker_memory is defined %}
--docker-memory="{{ gitlab_runner.docker_memory }}"
{% endif %}
{% if gitlab_runner.docker_gpus is defined %}
--docker-cpus="{{ gitlab_runner.docker_gpus }}"
{% endif %}
{% for security_opt in gitlab_runner.docker_security_opts | default([]) %}
--docker-security-opt "{{ security_opt }}"
{% endfor %}
Expand Down
33 changes: 33 additions & 0 deletions tasks/update-runner-configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,39 @@
check_mode: no
notify:
- Restart GitLab-Runner
- name: "Configure cpus parameter"
when: "gitlab_runner.docker_cpus is defined"
ansible.builtin.lineinfile:
dest: "{{ tmp_runner_config_file.path }}"
regexp: '^(\s*)cpus =.*'
line: '\1cpus = {{ gitlab_runner.docker_cpus }}'
state: present
backrefs: yes
check_mode: no
notify:
- Restart GitLab-Runner
- name: "Configure memory parameter"
when: "gitlab_runner.docker_memory is defined"
ansible.builtin.lineinfile:
dest: "{{ tmp_runner_config_file.path }}"
regexp: '^(\s*)memory =.*'
line: '\1memory = {{ gitlab_runner.docker_memory }}'
state: present
backrefs: yes
check_mode: no
notify:
- Restart GitLab-Runner
- name: "Configure gpus parameter"
when: "gitlab_runner.docker_gpus is defined"
ansible.builtin.lineinfile:
dest: "{{ tmp_runner_config_file.path }}"
regexp: '^(\s*)gpus =.*'
line: '\1gpus = {{ gitlab_runner.docker_gpus }}'
state: present
backrefs: yes
check_mode: no
notify:
- Restart GitLab-Runner

- name: Configure [runners.machine] section
when: 'gitlab_runner.executor == "docker+machine"'
Expand Down

0 comments on commit eec7d7b

Please sign in to comment.