Skip to content
Snippets Groups Projects
Commit 8e0fbdd7 authored by Erick Hitter's avatar Erick Hitter
Browse files

Merge branch 'add/machine-opts' into 'master'

Support runner options for Docker Machine

See merge request !1
parents b932ca07 2c77c7f8
No related branches found
No related tags found
1 merge request!1Support runner options for Docker Machine
GitLab Runner [![pipeline status](https://git.ethitter.com/ansible/gitlab-runner/badges/master/pipeline.svg)](https://git.ethitter.com/ansible/gitlab-runner/commits/master) GitLab Runner [![pipeline status](https://git.ethitter.com/ansible/gitlab-runner/badges/master/pipeline.svg)](https://git.ethitter.com/ansible/gitlab-runner/commits/master)
============= =============
This role will install the [official GitLab Runner](https://gitlab.com/gitlab-org/gitlab-runner) Install GitLab Runner using Docker Machine and Digital Ocean for on-demand instance creation. See https://www.digitalocean.com/community/tutorials/how-to-autoscale-gitlab-continuous-deployment-with-gitlab-runner-on-digitalocean.
(fork from haroldb) with updates. Needed something simple and working, this did the trick for me. Open for changes though.
This is intended to be installed on the same host as the GitLab instance, spinning up hosts as needed and quickly tearing them down. If your CI activity is frequent, the `gitlab_runner_machine_idle_time` variable should be increased so hosts can be reused.
Requirements Requirements
------------ ------------
...@@ -12,47 +13,77 @@ This role requires Ansible 2.0 or higher. ...@@ -12,47 +13,77 @@ This role requires Ansible 2.0 or higher.
Role Variables Role Variables
-------------- --------------
`gitlab_runner_package_name` ###### `gitlab_runner_package_name`
**Since Gitlab 10.x** The package name of `gitlab-ci-multi-runner` has been renamed to `gitlab-runner`. In order to install a version >= 10.x you will need to define this variable `gitlab_runner_package_name: gitlab-runner`. **Since Gitlab 10.x** The package name of `gitlab-ci-multi-runner` has been renamed to `gitlab-runner`. In order to install a version >= 10.x you will need to define this variable `gitlab_runner_package_name: gitlab-runner`.
`gitlab_runner_concurrent` ###### `gitlab_runner_concurrent`
The maximum number of global jobs to run concurrently. The maximum number of global jobs to run concurrently.
Defaults to the number of processor cores. Defaults to the number of processor cores.
`gitlab_runner_registration_token` ###### `gitlab_runner_registration_token`
The GitLab registration token. If this is specified, a runner will be registered to a GitLab server. The GitLab registration token. If this is specified, a runner will be registered to a GitLab server.
`gitlab_runner_coordinator_url` ###### `gitlab_runner_coordinator_url`
The GitLab coordinator URL. The GitLab coordinator URL.
Defaults to `https://gitlab.com/ci`. Defaults to `https://gitlab.com/ci`.
`gitlab_runner_description` ###### `gitlab_runner_description_base`
The description of the runner. Base description of the runner.
Defaults to the hostname. Defaults to the hostname.
`gitlab_runner_executor` ###### `gitlab_runner_executor`
The executor used by the runner. The executor used by the runner.
Defaults to `shell`. Defaults to `shell`.
`gitlab_runner_concurrent_specific` ###### `gitlab_runner_concurrent_specific`
The maximum number of jobs to run concurrently on this specific runner. The maximum number of jobs to run concurrently on this specific runner.
Defaults to 0, simply means don't limit. Defaults to 0, simply means don't limit.
`gitlab_runner_docker_image` ###### `gitlab_runner_docker_image`
The default Docker image to use. Required when executor is `docker`. The default Docker image to use. Required when executor is `docker`.
`gitlab_runner_tags` ###### `gitlab_runner_tags`
The tags assigned to the runner,
Default tags assigned to the runner,
Defaults to an empty list. Defaults to an empty list.
`gitlab_runner_cache_type` ###### `gitlab_runner_machine_idle_nodes`
Variables to set s3 as a shared cache server. If set it requires variables listed below:
`gitlab_runner_cache_s3_server_address` How many idle machines to maintain. Defaults to `0`, meaning all hosts are created on-demand then culled after `gitlab_runner_machine_idle_time` minutes.
`gitlab_runner_cache_s3_access_key`
`gitlab_runner_cache_s3_access_key` ###### `gitlab_runner_machine_idle_time`
`gitlab_runner_cache_s3_bucket_name`
`gitlab_runner_cache_s3_insecure` How long, in minutes, a machine can be idle before it's destroyed. Default is `3`.
`gitlab_runner_cache_cache_shared`
###### `gitlab_runners`
Dict of runners
```yml
gitlab_runners:
- {
description: '{{ gitlab_runner_description_base }}',
tags: [],
locked: false,
token: ''
}
```
###### `gitlab_runner_cache_type`
Variables to set `s3` as a shared cache server. If set it requires variables listed below:
* `gitlab_runner_cache_s3_server_address`
* `gitlab_runner_cache_s3_access_key`
* `gitlab_runner_cache_s3_secret_key`
* `gitlab_runner_cache_s3_bucket_name`
* `gitlab_runner_cache_s3_insecure`
* `gitlab_runner_cache_cache_shared`
See the [config for more options](https://github.com/riemers/ansible-gitlab-runner/blob/master/tasks/register-runner.yml) See the [config for more options](https://github.com/riemers/ansible-gitlab-runner/blob/master/tasks/register-runner.yml)
......
...@@ -10,7 +10,7 @@ gitlab_runner_coordinator_url: 'https://gitlab.com/ci' ...@@ -10,7 +10,7 @@ gitlab_runner_coordinator_url: 'https://gitlab.com/ci'
# GitLab registration token # GitLab registration token
gitlab_runner_registration_token: '' gitlab_runner_registration_token: ''
# Runner description # Runner description
gitlab_runner_description: '{{ ansible_hostname }}' gitlab_runner_description_base: '{{ ansible_hostname }}'
# Runner executor # Runner executor
gitlab_runner_executor: 'shell' gitlab_runner_executor: 'shell'
# Maximum number of jobs to run concurrently on this specific runner # Maximum number of jobs to run concurrently on this specific runner
...@@ -32,4 +32,18 @@ gitlab_runner_ssh_password: '' ...@@ -32,4 +32,18 @@ gitlab_runner_ssh_password: ''
# Runner SSH identity file # Runner SSH identity file
gitlab_runner_ssh_identity_file: '' gitlab_runner_ssh_identity_file: ''
# Runner Locked # Runner Locked
gitlab_runner_locked: 'false' gitlab_runner_locked: false
# Individual runners
gitlab_runners:
- {
description: '{{ gitlab_runner_description_base }}'
}
# Runner machine
gitlab_runner_machine_idle_nodes: 0
gitlab_runner_machine_idle_time: 3
# Docker Machine
docker_machine_version: 'v0.15.0'
docker_machine_binary_dest: /usr/local/bin/docker-machine
--- ---
galaxy_info: galaxy_info:
author: Erik-jan Riemers author: Erick Hitter, Erik-jan Riemers
description: GitLab Runner description: GitLab Runner
issue_tracker_url: https://git.ethitter.com/ansible/gitlab-runner/issues
license: MIT license: MIT
min_ansible_version: 2.0 min_ansible_version: 2.0
platforms: platforms:
- name: EL - name: Debian
versions: version:
- all - all
- name: Ubuntu
versions:
- all
- name: Debian
version:
- all
galaxy_tags: galaxy_tags:
- gitlab - gitlab
- runner - runner
......
...@@ -16,4 +16,3 @@ ...@@ -16,4 +16,3 @@
state: present state: present
backrefs: yes backrefs: yes
notify: restart_gitlab_runner notify: restart_gitlab_runner
---
- name: Get Docker Machine
get_url:
url: "https://github.com/docker/machine/releases/download/{{ docker_machine_version | default('v0.15.0') }}/docker-machine-{{ ansible_system }}-{{ ansible_architecture }}"
dest: /tmp/docker-machine
- name: Install Docker Machine
command: 'install /tmp/docker-machine {{ docker_machine_binary_dest }}'
---
- name: RHEL | Install GitLab GPG key
rpm_key:
state: present
key: https://packages.gitlab.com/gpg.key
when: ansible_os_family == 'RedHat'
tags:
- gitlab
- gitlab-gpg
- name: Install GitLab Runner dependencies
yum:
name: '{{ item }}'
state: present
with_items:
- pygpgme
- yum-utils
- name: Add GitLab Runner rpm repo
template:
src: "runner.repo.j2"
dest: "/etc/yum.repos.d/runner_{{ gitlab_runner_package_name }}.repo"
- name: Install GitLab Runner
yum:
name: "{{ gitlab_runner_package_name }}"
state: latest
update_cache: yes
File moved
--- ---
- name: Install GitLab Runner (Debian) - name: Install GitLab Runner
import_tasks: install-debian.yml import_tasks: install-runner.yml
when: ansible_os_family == 'Debian'
- name: Install GitLab Runner (RedHat) - name: Install Docker Machine
import_tasks: install-redhat.yml import_tasks: install-docker-machine.yml
when: ansible_os_family == 'RedHat'
- name: Set global options
import_tasks: global-setup.yml
- name: Register GitLab Runner - name: Register GitLab Runner
import_tasks: register-runner.yml import_tasks: register-runner.yml
when: gitlab_runner_registration_token != '' when: gitlab_runner_registration_token != ''
- name: Set global options
import_tasks: global-setup.yml
...@@ -9,12 +9,12 @@ ...@@ -9,12 +9,12 @@
command: gitlab-runner register > command: gitlab-runner register >
--non-interactive --non-interactive
--url '{{ gitlab_runner_coordinator_url }}' --url '{{ gitlab_runner_coordinator_url }}'
--registration-token '{{ gitlab_runner_registration_token }}' --registration-token '{{ item.token | default( gitlab_runner_registration_token ) }}'
--description '{{ gitlab_runner_description }}' --description '{{ item.description }}'
--tag-list '{{ gitlab_runner_tags | join(",") }}' --tag-list '{{ ( item.tags | default( gitlab_runner_tags ) ) | join(",") }}'
--executor '{{ gitlab_runner_executor }}' --executor '{{ gitlab_runner_executor }}'
--limit '{{ gitlab_runner_concurrent_specific }}' --limit '{{ gitlab_runner_concurrent_specific }}'
--locked='{{gitlab_runner_locked}}' --locked='{{ item.locked | default( gitlab_runner_locked ) }}'
--docker-image '{{ gitlab_runner_docker_image }}' --docker-image '{{ gitlab_runner_docker_image }}'
{% if gitlab_runner_docker_volumes is defined %} {% if gitlab_runner_docker_volumes is defined %}
--docker-volumes "{{ gitlab_runner_docker_volumes | join('" "') }}" --docker-volumes "{{ gitlab_runner_docker_volumes | join('" "') }}"
...@@ -30,7 +30,18 @@ ...@@ -30,7 +30,18 @@
--cache-s3-access-key '{{ gitlab_runner_cache_s3_access_key }}' --cache-s3-access-key '{{ gitlab_runner_cache_s3_access_key }}'
--cache-s3-secret-key '{{ gitlab_runner_cache_s3_secret_key }}' --cache-s3-secret-key '{{ gitlab_runner_cache_s3_secret_key }}'
--cache-s3-bucket-name '{{ gitlab_runner_cache_s3_bucket_name }}' --cache-s3-bucket-name '{{ gitlab_runner_cache_s3_bucket_name }}'
--cache-s3-insecure '{{ gitlab_runner_cache_s3_insecure }}' --cache-s3-insecure='{{ gitlab_runner_cache_s3_insecure }}'
--cache-cache-shared '{{ gitlab_runner_cache_cache_shared }}' --cache-cache-shared='{{ gitlab_runner_cache_cache_shared }}'
{% endif %} {% endif %}
when: configured_runners.stderr.find('\n' + gitlab_runner_description) == -1 --machine-idle-nodes '{{ gitlab_runner_machine_idle_nodes }}'
--machine-idle-time '{{ gitlab_runner_machine_idle_time }}'
--machine-machine-driver 'digitalocean'
--machine-machine-name 'gitlab-%s'
--machine-machine-options 'digitalocean-image=coreos-stable'
--machine-machine-options 'digitalocean-ssh-user=core'
--machine-machine-options 'digitalocean-access-token={{ gitlab_runner_digital_ocean_token }}'
--machine-machine-options 'digitalocean-region={{ gitlab_runner_digital_ocean_region }}'
--machine-machine-options 'digitalocean-size={{ gitlab_runner_digital_ocean_size }}'
--machine-machine-options 'digitalocean-private-networking'
with_items: '{{ gitlab_runners }}'
when: configured_runners.stderr.find('\n' + item.description) == -1
[runner_{{ gitlab_runner_package_name }}]
name=runner_{{ gitlab_runner_package_name }}
baseurl=https://packages.gitlab.com/runner/{{ gitlab_runner_package_name }}/el/{{ ansible_distribution_major_version }}/$basearch
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
[runner_{{ gitlab_runner_package_name }}-source]
name=runner_{{ gitlab_runner_package_name }}-source
baseurl=https://packages.gitlab.com/runner/{{ gitlab_runner_package_name }}/el/{{ ansible_distribution_major_version }}/SRPMS
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment