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