Allow setting the "concurrent" builds number at startup
Description
There is a concurrent
setting in the runner you can add to the config.toml as described here: https://docs.gitlab.com/runner/configuration/advanced-configuration.html. There is two problems with that file. First, you need to create the file yourself or wait for the runner to create it, because it is not installed by default. Second, it is written by the runner when registering to a server, so placing a predefined config is not possible after the runner has registered. This makes automation of the setup (e.g. using puppet) very hard.
My particular setup includes a Puppet-delivered Systemd service. Here's the relevant part of the systemd unit file:
ExecStartPre=-/usr/bin/docker kill gitlab-runner
ExecStartPre=-/usr/bin/docker rm gitlab-runner
ExecStart=/usr/bin/bash -c '/usr/bin/docker run --name gitlab-runner --hostname "<%= @runner_name %>" --volume /var/run/docker.sock:/var/run/docker.sock --volume /opt/gitlab-runner-docker/ca.crt:/etc/gitlab-runner/certs/ca.crt gitlab/gitlab-runner:latest'
ExecStartPost=/usr/bin/sleep 10s
ExecStartPost=/usr/bin/docker exec gitlab-runner gitlab-runner register --non-interactive --registration-token "<%= @gitlab_token %>" --url <%= @gitlab_url %>/ci --executor docker --docker-image docker:latest --docker-volumes /var/run/docker.sock:/var/run/docker.sock
ExecStop=/usr/bin/bash -c '/usr/bin/docker exec gitlab-runner gitlab-runner unregister --name "<%= @runner_name %>"'
ExecStop=/usr/bin/docker stop gitlab-runner
As you can see, the whole process is automated and doesn't allow interactive control except for stopping and starting. In order to set the allowed concurrent builds I'd have to add a line that echoes "concurrent = 10" into the /etc/gitlab-runner/config.toml inside the container after start. This is kinda ugly and error-prone. I'd prefer to add the option on the command line to the docker-run line (which has gitlab-runner run as default entrypoint).
Proposal
Either add a command line switch to set global options or set the options based on environment variables.