github.com/ssube/gitlab-ci-multi-runner@v1.2.1-0.20160607142738-b8d1285632e6/docs/install/autoscaling.md (about) 1 # Install and configure GitLab Runner for auto-scaling 2 3 > The auto scale feature was introduced in GitLab Runner 1.1.0. 4 5 For an overview of the auto-scale architecture, take a look at the 6 [comprehensive documentation on auto-scaling](../configuration/autoscale.md). 7 8 --- 9 10 <!-- START doctoc generated TOC please keep comment here to allow auto update --> 11 <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> 12 **Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* 13 14 - [Prepare the environment](#prepare-the-environment) 15 - [Prepare the Docker Registry and Cache Server](#prepare-the-docker-registry-and-cache-server) 16 - [Install Docker Registry](#install-docker-registry) 17 - [Install the cache server](#install-the-cache-server) 18 - [Configure GitLab Runner](#configure-gitlab-runner) 19 - [Upgrading the Runner](#upgrading-the-runner) 20 - [Manage the Docker Machines](#manage-the-docker-machines) 21 22 <!-- END doctoc generated TOC please keep comment here to allow auto update --> 23 24 ## Prepare the environment 25 26 In order to use the auto-scale feature, Docker and GitLab Runner must be 27 installed in the same machine: 28 29 1. Login to a new Linux-based machine that will serve as a bastion server and 30 where Docker will spawn new machines from 31 1. Install GitLab Runner following the 32 [GitLab Runner installation documentation][runner-installation] 33 1. Install Docker Machine following the 34 [Docker Machine installation documentation][docker-machine-installation] 35 36 ## Prepare the Docker Registry and Cache Server 37 38 To speedup the builds we advise to setup a personal Docker registry server 39 working in proxy mode. A cache server is also recommended. 40 41 ### Install Docker Registry 42 43 >**Note:** 44 Read more in [Distributed registry mirroring][registry]. 45 46 1. Login to a dedicated machine where Docker registry proxy will be running 47 2. Make sure that Docker Engine is installed on this machine 48 3. Create a new Docker registry: 49 50 ```bash 51 docker run -d -p 6000:5000 \ 52 -e REGISTRY_PROXY_REMOTEURL=https://registry-1.docker.io \ 53 --restart always \ 54 --name registry registry:2 55 ``` 56 57 You can modify the port number (`6000`) to expose Docker registry on a 58 different port. 59 60 4. Check the IP address of the server: 61 62 ```bash 63 hostname --ip-address 64 ``` 65 66 You should preferably choose the private networking IP address. The private 67 networking is usually the fastest solution for internal communication 68 between machines of a single provider (DigitalOcean, AWS, Azure, etc,) 69 Usually the private networking is also not accounted to your monthly 70 bandwidth limit. 71 72 5. Docker registry will be accessible under `MY_REGISTRY_IP:6000`. 73 74 ### Install the cache server 75 76 >**Note:** 77 You can use any other S3-compatible server, including [Amazon S3][S3]. Read 78 more in [Distributed runners caching][caching]. 79 80 1. Login to a dedicated machine where the cache server will be running 81 1. Make sure that Docker Engine is installed on that machine 82 1. Start [minio], a simple S3-compatible server written in Go: 83 84 ```bash 85 docker run -it --restart always -p 9005:9000 \ 86 -v /.minio:/root/.minio -v /export:/export \ 87 --name minio \ 88 minio/minio:latest /export 89 ``` 90 91 You can modify the port `9005` to expose the cache server on different port. 92 93 1. Check the IP address of the server: 94 95 ```bash 96 hostname --ip-address 97 ``` 98 99 1. Your cache server will be available at `MY_CACHE_IP:9005` 100 1. Read the Access and Secret Key of minio with: `sudo cat /.minio/config.json` 101 1. Create a bucket that will be used by the Runner: `sudo mkdir /export/runner`. 102 `runner` is the name of the bucket in that case. If you choose a different 103 bucket then it will be different 104 1. All caches will be stored in the `/export` directory 105 106 ## Configure GitLab Runner 107 108 1. Register a GitLab Runner, selecting the `docker+machine` executor: 109 110 ```bash 111 sudo gitlab-ci-multi-runner register 112 ``` 113 114 Example output: 115 116 ```bash 117 Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/ci ) 118 https://gitlab.com/ci 119 Please enter the gitlab-ci token for this runner 120 xxx 121 Please enter the gitlab-ci description for this runner 122 my-autoscale-runner 123 INFO[0034] fcf5c619 Registering runner... succeeded 124 Please enter the executor: shell, docker, docker-ssh, docker+machine, docker-ssh+machine, ssh? 125 docker+machine 126 Please enter the Docker image (eg. ruby:2.1): 127 ruby:2.1 128 INFO[0037] Runner registered successfully. Feel free to start it, but if it's 129 running already the config should be automatically reloaded! 130 ``` 131 132 1. Edit [`config.toml`][toml]. You need to fill in the options for 133 `[runners.machine]` and `[runners.cache]` and configure the `MachineDriver` 134 selecting your provider. Also configure `MachineOptions`, `limit` and 135 `IdleCount`. 136 137 For more information visit the dedicated page covering detailed information 138 about [GitLab Runner Autoscaling][runner-autoscaling]. 139 140 Example configuration using DigitalOcean: 141 142 ```toml 143 concurrent = 20 144 145 [[runners]] 146 executor = "docker+machine" 147 limit = 20 148 [runners.machine] 149 IdleCount = 5 150 MachineDriver = "digitalocean" 151 MachineName = "auto-scale-runners-%s.my.domain.com" 152 MachineOptions = [ 153 "digitalocean-image=coreos-beta", 154 "digitalocean-ssh-user=core", 155 "digitalocean-access-token=MY_DIGITAL_OCEAN_TOKEN", 156 "digitalocean-region=nyc2", 157 "digitalocean-private-networking", 158 "engine-registry-mirror=http://MY_REGISTRY_IP:6000" 159 ] 160 [runners.cache] 161 Type = "s3" 162 ServerAddress = "MY_CACHE_IP:9005" 163 AccessKey = "ACCESS_KEY" 164 SecretKey = "SECRET_KEY" 165 BucketName = "runner" 166 Insecure = true # Use Insecure only when using with Minio, without the TLS certificate enabled 167 ``` 168 169 1. Try to build your project. In a few seconds, if you run `docker-machine ls` 170 you should see a new machine being created. 171 172 ## Upgrading the Runner 173 174 1. Stop the runner: 175 176 ```bash 177 killall -SIGQUIT gitlab-runner 178 ``` 179 180 Sending the [`SIGQUIT` signal][signals] will make the Runner to stop 181 gracefully. It will stop accepting new jobs, and will exit as soon as the 182 current builds are finished. 183 184 1. Wait until the Runner exits. You can check its status with: `gitlab-runner status` 185 1. You can now safely upgrade the Runner without interrupting any builds 186 187 ## Manage the Docker Machines 188 189 1. Stop the Runner: 190 191 ```bash 192 killall -SIGQUIT gitlab-runner 193 ``` 194 195 1. Wait until the Runner exits. You can check its status with: `gitlab-runner status` 196 1. You can now manage (upgrade or remove) any Docker Machines with the 197 [`docker-machine` command][docker-machine] 198 199 [runner-installation]: https://gitlab.com/gitlab-org/gitlab-ci-multi-runner#installation 200 [docker-machine-installation]: https://docs.docker.com/machine/install-machine/ 201 [runner-autoscaling]: ../configuration/autoscale.md 202 [s3]: https://aws.amazon.com/s3/ 203 [minio]: https://www.minio.io/ 204 [caching]: ../configuration/autoscale.md#distributed-runners-caching 205 [registry]: ../configuration/autoscale.md#distributed-docker-registry-mirroring 206 [toml]: ../commands/README.md#configuration-file 207 [signals]: ../commands/README.md#signals 208 [docker-machine]: https://docs.docker.com/machine/reference/