github.com/ssube/gitlab-ci-multi-runner@v1.2.1-0.20160607142738-b8d1285632e6/docs/configuration/advanced-configuration.md (about) 1 # Advanced configuration 2 3 GitLab Runner configuration uses the [TOML][] format. 4 5 The file to be edited can be found in: 6 7 1. `/etc/gitlab-runner/config.toml` on \*nix systems when gitlab-runner is 8 executed as root (**this is also path for service configuration**) 9 1. `~/.gitlab-runner/config.toml` on \*nix systems when gitlab-runner is 10 executed as non-root 11 1. `./config.toml` on other systems 12 13 ## The global section 14 15 This defines global settings of multi-runner. 16 17 | Setting | Description | 18 | ------- | ----------- | 19 | `concurrent` | limits how many jobs globally can be run concurrently. The most upper limit of jobs using all defined runners | 20 21 Example: 22 23 ```bash 24 concurrent = 4 25 ``` 26 27 ## The [[runners]] section 28 29 This defines one runner entry. 30 31 | Setting | Description | 32 | ------- | ----------- | 33 | `name` | not used, just informatory | 34 | `url` | CI URL | 35 | `token` | runner token | 36 | `tls-ca-file` | file containing the certificates to verify the peer when using HTTPS | 37 | `tls-skip-verify` | whether to verify the TLS certificate when using HTTPS, default: false | 38 | `limit` | limit how many jobs can be handled concurrently by this token. 0 simply means don't limit | 39 | `executor` | select how a project should be built, see next section | 40 | `shell` | the name of shell to generate the script (default value is platform dependent) | 41 | `builds_dir` | directory where builds will be stored in context of selected executor (Locally, Docker, SSH) | 42 | `cache_dir` | directory where build caches will be stored in context of selected executor (Locally, Docker, SSH). If the `docker` executor is used, this directory needs to be included in its `volumes` parameter. | 43 | `environment` | append or overwrite environment variables | 44 | `disable_verbose` | don't print run commands | 45 | `output_limit` | set maximum build log size in kilobytes, by default set to 4096 (4MB) | 46 47 Example: 48 49 ```bash 50 [[runners]] 51 name = "ruby-2.1-docker" 52 url = "https://CI/" 53 token = "TOKEN" 54 limit = 0 55 executor = "docker" 56 builds_dir = "" 57 shell = "" 58 environment = ["ENV=value", "LC_ALL=en_US.UTF-8"] 59 disable_verbose = false 60 ``` 61 62 ## The EXECUTORS 63 64 There are a couple of available executors currently. 65 66 | Executor | Description | 67 | -------- | ----------- | 68 | `shell` | run build locally, default | 69 | `docker` | run build using Docker container - this requires the presence of `[runners.docker]` and [Docker Engine][] installed on the system that the Runner runs | 70 | `docker-ssh` | run build using Docker container, but connect to it with SSH - this requires the presence of `[runners.docker]` , `[runners.ssh]` and [Docker Engine][] installed on the system that the Runner runs. **Note: This will run the docker container on the local machine, it just changes how the commands are run inside that container. If you want to run docker commands on an external machine, then you should change the `host` parameter in the `runners.docker` section.**| 71 | `ssh` | run build remotely with SSH - this requires the presence of `[runners.ssh]` | 72 | `parallels` | run build using Parallels VM, but connect to it with SSH - this requires the presence of `[runners.parallels]` and `[runners.ssh]` | 73 | `virtualbox` | run build using VirtualBox VM, but connect to it with SSH - this requires the presence of `[runners.virtualbox]` and `[runners.ssh]` | 74 | `docker+machine` | like `docker`, but uses [auto-scaled docker machines](autoscale.md) - this requires the presence of `[runners.docker]` and `[runners.machine]` | 75 | `docker-ssh+machine` | like `docker-ssh`, but uses [auto-scaled docker machines](autoscale.md) - this requires the presence of `[runners.docker]` and `[runners.machine]` | 76 77 ## The SHELLS 78 79 There are a couple of available shells that can be run on different platforms. 80 81 | Shell | Description | 82 | ----- | ----------- | 83 | `bash` | generate Bash (Bourne-shell) script. All commands executed in Bash context (default for all Unix systems) | 84 | `sh` | generate Sh (Bourne-shell) script. All commands executed in Sh context (fallback for `bash` for all Unix systems) | 85 | `cmd` | generate Windows Batch script. All commands are executed in Batch context (default for Windows) | 86 | `powershell` | generate Windows PowerShell script. All commands are executed in PowerShell context | 87 88 ## The [runners.docker] section 89 90 This defines the Docker Container parameters. 91 92 | Parameter | Description | 93 | --------- | ----------- | 94 | `host` | specify custom Docker endpoint, by default `DOCKER_HOST` environment is used or `unix:///var/run/docker.sock` | 95 | `hostname` | specify custom hostname for Docker container | 96 | `tls_cert_path` | when set it will use `ca.pem`, `cert.pem` and `key.pem` from that folder to make secure TLS connection to Docker (useful in boot2docker) | 97 | `image` | use this image to run builds | 98 | `cpuset_cpus` | string value containing the cgroups CpusetCpus to use | 99 | `dns` | a list of DNS servers for the container to use | 100 | `dns_search` | a list of DNS search domains | 101 | `privileged` | make container run in Privileged mode (insecure) | 102 | `cap_add` | add additional Linux capabilities to the container | 103 | `cap_drop` | drop additional Linux capabilities from the container | 104 | `devices` | share additional host devices with the container | 105 | `disable_cache` | disable automatic | 106 | `wait_for_services_timeout` | specify how long to wait for docker services, set to 0 to disable, default: 30 | 107 | `cache_dir` | specify where Docker caches should be stored (this can be absolute or relative to current working directory) | 108 | `volumes` | specify additional volumes that should be mounted (same syntax as Docker -v option) | 109 | `extra_hosts` | specify hosts that should be defined in container environment | 110 | `links` | specify containers which should be linked with building container | 111 | `services` | specify additional services that should be run with build. Please visit [Docker Registry](https://registry.hub.docker.com/) for list of available applications. Each service will be run in separate container and linked to the build. | 112 | `allowed_images` | specify wildcard list of images that can be specified in .gitlab-ci.yml. If not present all images are allowed (equivalent to `["*/*:*"]`) | 113 | `allowed_services` | specify wildcard list of services that can be specified in .gitlab-ci.yml. If not present all images are allowed (equivalent to `["*/*:*"]`) | 114 | `pull_policy` | specify the image pull policy: never, if-not-present or always (default) | 115 116 Example: 117 118 ```bash 119 [runners.docker] 120 host = "" 121 hostname = "" 122 tls_cert_path = "/Users/ayufan/.boot2docker/certs" 123 image = "ruby:2.1" 124 cpuset_cpus = "0,1" 125 dns = ["8.8.8.8"] 126 dns_search = [""] 127 privileged = false 128 cap_add = ["NET_ADMIN"] 129 cap_drop = ["DAC_OVERRIDE"] 130 devices = ["/dev/net/tun"] 131 disable_cache = false 132 wait_for_services_timeout = 30 133 cache_dir = "" 134 volumes = ["/data", "/home/project/cache"] 135 extra_hosts = ["other-host:127.0.0.1"] 136 links = ["mysql_container:mysql"] 137 services = ["mysql", "redis:2.8", "postgres:9"] 138 allowed_images = ["ruby:*", "python:*", "php:*"] 139 allowed_services = ["postgres:9.4", "postgres:latest"] 140 ``` 141 142 ### Volumes in the [runners.docker] section 143 144 You can find the complete guide of Docker volume usage 145 [here](https://docs.docker.com/userguide/dockervolumes/). 146 147 Let's use some examples to explain how it work (assuming you have a working 148 runner). 149 150 #### Example 1: adding a data volume 151 152 A data volume is a specially-designated directory within one or more containers 153 that bypasses the Union File System. Data volumes are designed to persist data, 154 independent of the container's life cycle. 155 156 ```bash 157 [runners.docker] 158 host = "" 159 hostname = "" 160 tls_cert_path = "/Users/ayufan/.boot2docker/certs" 161 image = "ruby:2.1" 162 privileged = false 163 disable_cache = true 164 volumes = ["/path/to/volume/in/container"] 165 ``` 166 167 This will create a new volume inside the container at `/path/to/volume/in/container`. 168 169 #### Example 2: mount a host directory as a data volume 170 171 In addition to creating a volume using you can also mount a directory from your 172 Docker daemon's host into a container. It's useful when you want to store 173 builds outside the container. 174 175 ```bash 176 [runners.docker] 177 host = "" 178 hostname = "" 179 tls_cert_path = "/Users/ayufan/.boot2docker/certs" 180 image = "ruby:2.1" 181 privileged = false 182 disable_cache = true 183 volumes = ["/path/to/bind/from/host:/path/to/bind/in/container:rw"] 184 ``` 185 186 This will use `/path/to/bind/from/host` of the CI host inside the container at 187 `/path/to/bind/in/container`. 188 189 ### Using a private Docker registry 190 191 _This feature requires GitLab Runner v0.6.0 or higher_ 192 193 In order to use a docker image from a private registry which needs 194 authentication, you must first authenticate against the docker registry in 195 question. 196 197 If you are using our Linux packages, then `gitlab-runner` is run by the user 198 root (for non-root users, see the **Notes** section below). 199 200 As root run: 201 202 ```bash 203 docker login <registry> 204 ``` 205 206 Replace `<registry>` with the Fully Qualified Domain Name of the registry and 207 optionally a port, for example: 208 209 ```bash 210 docker login my.registry.tld:5000 211 ``` 212 213 The default value is `docker.io` which is the official registry Docker Inc. 214 provides. If you omit the registry name, `docker.io` will be implied. 215 216 After you enter the needed credentials, docker will inform you that the 217 credentials are saved in `/root/.docker/config.json`. 218 219 In case you are running an older Docker Engine (< 1.7.0), then the credentials 220 will be stored in `/root/.dockercfg`. GitLab Runner supports both locations for 221 backwards compatibility. 222 223 The steps performed by the Runner can be summed up to: 224 225 1. The registry name is found from the image name 226 1. If the value is not empty, the executor will try to look at `~/.dockercfg` 227 (Using `NewAuthConfigurationsFromDockerCfg()` method in go-dockerclient) 228 1. If that fails for some reason, the executor will then look at 229 `~/.docker/config.json` (Which should be the new default from Docker 1.7.0) 230 1. Finally, if an Authentication corresponding to the specified registry is 231 found, subsequent Pull will make use of it 232 233 Now that the Runner is set up to authenticate against your private registry, 234 learn [how to configure .gitlab-ci.yml][yaml-priv-reg] in order to use that 235 registry. 236 237 **Notes** 238 239 If you are running `gitlab-runner` with a non-root user, you must use that user 240 to login to the private docker registry. This user will also need to be in the 241 `docker` group in order to be able to run any docker commands. To add a user to 242 the `docker` group use: `sudo usermod -aG user docker`. 243 244 For reference, if you want to set up your own personal registry you might want 245 to have a look at <https://docs.docker.com/registry/deploying/>. 246 247 ### Restrict `allowed_images` to private registry 248 For certain setups you will restrict access of the build jobs to docker images 249 which comes from your private docker registry. In that case set 250 251 ```bash 252 [runners.docker] 253 … 254 allowed_images = ["my.registry.tld:5000/*:*"] 255 ``` 256 257 ## The [runners.parallels] section 258 259 This defines the Parallels parameters. 260 261 | Parameter | Description | 262 | --------- | ----------- | 263 | `base_name` | name of Parallels VM which will be cloned | 264 | `template_name` | custom name of Parallels VM linked template (optional) | 265 | `disable_snapshots` | if disabled the VMs will be destroyed after build | 266 267 Example: 268 269 ```bash 270 [runners.parallels] 271 base_name = "my-parallels-image" 272 template_name = "" 273 disable_snapshots = false 274 ``` 275 276 ## The [runners.virtualbox] section 277 278 This defines the VirtualBox parameters. This executor relies on 279 `vboxmanage` as executable to control VirtualBox machines so you have to adjust 280 your `PATH` environment variable on Windows hosts: 281 `PATH=%PATH%;C:\Program Files\Oracle\VirtualBox`. 282 283 | Parameter | Explanation | 284 | --------- | ----------- | 285 | `base_name` | name of VirtualBox VM which will be cloned | 286 | `disable_snapshots` | if disabled the VMs will be destroyed after build | 287 288 Example: 289 290 ```bash 291 [runners.virtualbox] 292 base_name = "my-virtualbox-image" 293 disable_snapshots = false 294 ``` 295 296 ## The [runners.ssh] section 297 298 This defines the SSH connection parameters. 299 300 | Parameter | Description | 301 | ---------- | ----------- | 302 | `host` | where to connect (overridden when using `docker-ssh`) | 303 | `port` | specify port, default: 22 | 304 | `user` | specify user | 305 | `password` | specify password | 306 | `identity_file` | specify file path to SSH private key (id_rsa, id_dsa or id_edcsa). The file needs to be stored unencrypted | 307 308 Example: 309 310 ``` 311 [runners.ssh] 312 host = "my-production-server" 313 port = "22" 314 user = "root" 315 password = "production-server-password" 316 identity_file = "" 317 ``` 318 319 ## The [runners.machine] section 320 321 >**Note:** 322 Added in GitLab Runner v1.1.0. 323 324 This defines the Docker Machine based autoscaling feature. More details can be 325 found in the separate [runners autoscale documentation](autoscale.md). 326 327 | Parameter | Description | 328 |------------------|-------------| 329 | `IdleCount` | Number of machines, that need to be created and waiting in _Idle_ state. | 330 | `IdleTime` | Time (in seconds) for machine to be in _Idle_ state before it is removed. | 331 | `MaxBuilds` | Builds count after which machine will be removed. | 332 | `MachineName` | Name of the machine. It **must** contain `%s`, which will be replaced with a unique machine identifier. | 333 | `MachineDriver` | Docker Machine `driver` to use. More details can be found in the [Docker Machine configuration section](autoscale.md#what-are-the-supported-cloud-providers). | 334 | `MachineOptions` | Docker Machine options. More details can be found in the [Docker Machine configuration section](autoscale.md#what-are-the-supported-cloud-providers). | 335 336 Example: 337 338 ```bash 339 [runners.machine] 340 IdleCount = 5 341 IdleTime = 600 342 MaxBuilds = 100 343 MachineName = "auto-scale-%s" 344 MachineDriver = "digitalocean" 345 MachineOptions = [ 346 "digitalocean-image=coreos-beta", 347 "digitalocean-ssh-user=core", 348 "digitalocean-access-token=DO_ACCESS_TOKEN", 349 "digitalocean-region=nyc2", 350 "digitalocean-size=4gb", 351 "digitalocean-private-networking", 352 "engine-registry-mirror=http://10.11.12.13:12345" 353 ] 354 ``` 355 356 ## The [runners.cache] section 357 358 >**Note:** 359 Added in GitLab Runner v1.1.0. 360 361 This defines the distributed cache feature. More details can be found 362 in the [runners autoscale documentation](autoscale.md#distributed-runners-caching). 363 364 | Parameter | Type | Description | 365 |------------------|------------------|-------------| 366 | `Type` | string | As of now, only S3-compatible services are supported, so only `s3` can be used. | 367 | `ServerAddress` | string | A `host:port` to the used S3-compatible server. | 368 | `AccessKey` | string | The access key specified for your S3 instance. | 369 | `SecretKey` | string | The secret key specified for your S3 instance. | 370 | `BucketName` | string | Name of the bucket where cache will be stored. | 371 | `BucketLocation` | string | Name of S3 region. | 372 | `Insecure` | boolean | Set to `true` if the S3 service is available by `HTTP`. Is set to `false` by default. | 373 374 Example: 375 376 ```bash 377 [runners.cache] 378 Type = "s3" 379 ServerAddress = "s3.amazonaws.com" 380 AccessKey = "AMAZON_S3_ACCESS_KEY" 381 SecretKey = "AMAZON_S3_SECRET_KEY" 382 BucketName = "runners" 383 BucketLocation = "eu-west-1" 384 Insecure = false 385 ``` 386 387 > **Note:** For Amazon's S3 service the `ServerAddress` should always be `s3.amazonaws.com`. Minio S3 client will 388 > get bucket metadata and modify the URL to point to the valid region (eg. `s3-eu-west-1.amazonaws.com`) itself. 389 390 ## Note 391 392 If you'd like to deploy to multiple servers using GitLab CI, you can create a 393 single script that deploys to multiple servers or you can create many scripts. 394 It depends on what you'd like to do. 395 396 [TOML]: https://github.com/toml-lang/toml 397 [Docker Engine]: https://www.docker.com/docker-engine 398 [yaml-priv-reg]: http://doc.gitlab.com/ce/ci/yaml/README.html#using-a-private-docker-registry