diff --git a/Changelog.md b/Changelog.md index 3fdf98c..0077fad 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,40 @@ # Changelog +**1.11.2** + - bumped to runner 1.11.2 and sameersbn/ubuntu:14.04.20170228 + +**1.11.0** + - added RUNNER_AUTOUNREGISTER option + +**1.10.4-2** + - added RUNNER_AUTOUNREGISTER option + +**1.10.4** + - gitlab-ci-multi-runner: upgrade to 1.10.4 + +**1.10.2** + - gitlab-ci-multi-runner: upgrade to 1.10.2 + +**1.9.3** + - gitlab-ci-multi-runner: upgrade to 1.9.3 + - added support of RUNNER_OUTPUT_LIMIT + +**1.9.0-1** + - fix restart of container + +**1.9.0** + - gitlab-ci-multi-runner: upgrade to 1.9.0 + - added concurrent jobs support + +**1.8.0** + - gitlab-ci-multi-runner: upgrade to 1.8.0 + +**v1.7.0** +- gitlab-ci-multi-runner: upgrade to v1.7.0 + +**1.1.4-6** + - added docker executor + **1.1.4** - gitlab-ci-multi-runner: upgrade to 1.1.4 diff --git a/Dockerfile b/Dockerfile index e69fada..a9df412 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,26 @@ -FROM sameersbn/ubuntu:14.04.20170110 +FROM sameersbn/ubuntu:14.04.20170228 MAINTAINER sameer@damagehead.com -ENV GITLAB_CI_MULTI_RUNNER_VERSION=1.1.4 \ +ENV GITLAB_CI_MULTI_RUNNER_VERSION=1.11.2 \ GITLAB_CI_MULTI_RUNNER_USER=gitlab_ci_multi_runner \ GITLAB_CI_MULTI_RUNNER_HOME_DIR="/home/gitlab_ci_multi_runner" ENV GITLAB_CI_MULTI_RUNNER_DATA_DIR="${GITLAB_CI_MULTI_RUNNER_HOME_DIR}/data" +ENV CA_CERTIFICATES_PATH='' +ENV RUNNER_CONCURRENT='' +ENV CI_SERVER_URL='' +ENV RUNNER_TOKEN='' +ENV RUNNER_EXECUTOR='docker' +ENV RUNNER_DESCRIPTION='' + +ENV RUNNER_DOCKER_IMAGE='docker:latest' +ENV RUNNER_DOCKER_MODE='socket' +ENV RUNNER_DOCKER_PRIVATE_REGISTRY_URL='' +ENV RUNNER_DOCKER_PRIVATE_REGISTRY_TOKEN='' +ENV RUNNER_DOCKER_ADDITIONAL_VOLUME='' +ENV RUNNER_OUTPUT_LIMIT='4096' +ENV RUNNER_AUTOUNREGISTER='false' + RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv E1DD270288B4E6030699E45FA1715D88E1DF1F24 \ && echo "deb http://ppa.launchpad.net/git-core/ppa/ubuntu trusty main" >> /etc/apt/sources.list \ && apt-get update \ diff --git a/README.md b/README.md index 10f8fbe..5188943 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![Docker Repository on Quay.io](https://quay.io/repository/sameersbn/gitlab-ci-multi-runner/status "Docker Repository on Quay.io")](https://quay.io/repository/sameersbn/gitlab-ci-multi-runner) -# sameersbn/gitlab-ci-multi-runner:1.1.4-7 +# sameersbn/gitlab-ci-multi-runner:1.11.2 - [Introduction](#introduction) - [Contributing](#contributing) @@ -51,7 +51,7 @@ Automated builds of the image are available on [Dockerhub](https://hub.docker.co > **Note**: Builds are also available on [Quay.io](https://quay.io/repository/sameersbn/gitlab-ci-multi-runner) ```bash -docker pull sameersbn/gitlab-ci-multi-runner:1.1.4-7 +docker pull sameersbn/gitlab-ci-multi-runner:1.11.2 ``` Alternatively you can build the image yourself. @@ -64,18 +64,76 @@ docker build -t sameersbn/gitlab-ci-multi-runner github.com/sameersbn/docker-git Before a runner can process your CI jobs, it needs to be authorized to access the the GitLab CI server. The `CI_SERVER_URL`, `RUNNER_TOKEN`, `RUNNER_DESCRIPTION` and `RUNNER_EXECUTOR` environment variables are used to register the runner on GitLab CI. +You can use any ENV variable supported by the gitlab ci runner. + ```bash docker run --name gitlab-ci-multi-runner -d --restart=always \ --volume /srv/docker/gitlab-runner:/home/gitlab_ci_multi_runner/data \ --env='CI_SERVER_URL=http://git.example.com/ci' --env='RUNNER_TOKEN=xxxxxxxxx' \ --env='RUNNER_DESCRIPTION=myrunner' --env='RUNNER_EXECUTOR=shell' \ - sameersbn/gitlab-ci-multi-runner:1.1.4-7 + sameersbn/gitlab-ci-multi-runner:1.11.2 ``` *Alternatively, you can use the sample [docker-compose.yml](docker-compose.yml) file to start the container using [Docker Compose](https://docs.docker.com/compose/)* Update the values of `CI_SERVER_URL`, `RUNNER_TOKEN` and `RUNNER_DESCRIPTION` in the above command. If these enviroment variables are not specified, you will be prompted to enter these details interactively on first run. +## Available variables + +You can customise the runner with the following env variables: +- CA_CERTIFICATES_PATH: the path to your certificate +- RUNNER_CONCURRENT: the number of concurrent job the runner can start +- CI_SERVER_URL: your server URL (suffixed by /ci) +- RUNNER_TOKEN: the runner token corresponding to your project +- RUNNER_EXECUTOR: the executor to start +- RUNNER_DESCRIPTION: the description of the runner, displayed in gitlab ui +- RUNNER_DOCKER_IMAGE: the default image to run when starting a build +- RUNNER_DOCKER_MODE: the docker mode to use, socket or dind +- RUNNER_DOCKER_PRIVATE_REGISTRY_URL: url of private registry the runner should access +- RUNNER_DOCKER_PRIVATE_REGISTRY_TOKEN: token of private registry the runner should access +- RUNNER_DOCKER_ADDITIONAL_VOLUME: additionals volumes to share between host and jobs +- RUNNER_OUTPUT_LIMIT: output limit in KB that a build can produce +- RUNNER_AUTOUNREGISTER: auto unregister the runner when the container stops + +## Using docker executor + +You can use the docker executor by using `RUNNER_EXECUTOR=docker`. You must provide a docker image to use in `RUNNER_DOCKER_IMAGE` (e.g. docker:latest) + +If `RUNNER_DOCKER_MODE` is set to `socket`, the docker socket is shared between the runner and the build container. If it is not, you must use docker in docker service in your .gitlabci.yml definitions. + +Start the docker runner in socket mode : +```bash +docker run --name gitlab-ci-multi-runner -d --restart=always \ + --volume /var/run/docker.sock:/var/run/docker.sock + --volume /srv/docker/gitlab-runner:/home/gitlab_ci_multi_runner/data \ + --env='CI_SERVER_URL=http://git.example.com/ci' --env='RUNNER_TOKEN=xxxxxxxxx' \ + --env='RUNNER_DESCRIPTION=myrunner' --env='RUNNER_EXECUTOR=docker' \ + --env='RUNNER_DOCKER_IMAGE=docker:latest' --env='RUNNER_DOCKER_MODE=socket' + sameersbn/gitlab-ci-multi-runner:1.11.2 +``` + +Start the docker runner in dind mode : +```bash +docker run --name gitlab-ci-multi-runner -d --restart=always \ + --volume /var/run/docker.sock:/var/run/docker.sock + --volume /srv/docker/gitlab-runner:/home/gitlab_ci_multi_runner/data \ + --env='CI_SERVER_URL=http://git.example.com/ci' --env='RUNNER_TOKEN=xxxxxxxxx' \ + --env='RUNNER_DESCRIPTION=myrunner' --env='RUNNER_EXECUTOR=docker' \ + --env='RUNNER_DOCKER_IMAGE=docker:latest' --env='RUNNER_DOCKER_MODE=dind' + sameersbn/gitlab-ci-multi-runner:1.11.2 +``` + +If you want to share volumes between your containers and the runner in socket mode, use the `RUNNER_DOCKER_ADDITIONAL_VOLUME` variable to share `/builds:/builds`. + +You can increase the log maximum size by setting the RUNNER_OUTPUT_LIMIT variable (in kb) + + +See https://docs.gitlab.com/ce/ci/docker/using_docker_build.html for more info. + +## Concurrent jobs +You an setup your runner to start multiple job in parallel by setting the environment variable `RUNNER_CONCURRENT` to the number of jobs you want to run concurrently. + + ## Command-line arguments You can customize the launch command by specifying arguments to `gitlab-ci-multi-runner` on the `docker run` command. For example the following command prints the help menu of `gitlab-ci-multi-runner` command: @@ -83,7 +141,7 @@ You can customize the launch command by specifying arguments to `gitlab-ci-multi ```bash docker run --name gitlab-ci-multi-runner -it --rm \ --volume /srv/docker/gitlab-runner:/home/gitlab_ci_multi_runner/data \ - sameersbn/gitlab-ci-multi-runner:1.1.4-7 --help + sameersbn/gitlab-ci-multi-runner:1.11.2 --help ``` ## Persistence @@ -131,7 +189,7 @@ To upgrade to newer releases: 1. Download the updated Docker image: ```bash - docker pull sameersbn/gitlab-ci-multi-runner:1.1.4-7 + docker pull sameersbn/gitlab-ci-multi-runner:1.11.2 ``` 2. Stop the currently running image: @@ -151,7 +209,7 @@ To upgrade to newer releases: ```bash docker run -name gitlab-ci-multi-runner -d \ [OPTIONS] \ - sameersbn/gitlab-ci-multi-runner:1.1.4-7 + sameersbn/gitlab-ci-multi-runner:1.11.2 ``` ## Shell Access diff --git a/VERSION b/VERSION index 8bc74c6..ca71766 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.4-7 +1.11.2 diff --git a/docker-compose.yml b/docker-compose.yml index fb20df5..8eda950 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,5 @@ GitlabCIMultiRunner: - image: sameersbn/gitlab-ci-multi-runner:1.1.4-7 + image: sameersbn/gitlab-ci-multi-runner:1.11.2 volumes: - /srv/docker/gitlab-runner:/home/gitlab_ci_multi_runner/data environment: diff --git a/entrypoint.sh b/entrypoint.sh index 3e2c19c..760e234 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -47,16 +47,38 @@ grant_access_to_docker_socket() { fi } +configure_docker_credentials() { + if [[ -n "${RUNNER_DOCKER_PRIVATE_REGISTRY_URL}" && -n "${RUNNER_DOCKER_PRIVATE_REGISTRY_TOKEN}" && ! -e "${GITLAB_CI_MULTI_RUNNER_HOME_DIR}/.docker/config.json" ]];then + sudo -HEu ${GITLAB_CI_MULTI_RUNNER_USER} mkdir "${GITLAB_CI_MULTI_RUNNER_HOME_DIR}/.docker" + sudo -HEu ${GITLAB_CI_MULTI_RUNNER_USER} \ + echo "{\"auths\": {\"${RUNNER_DOCKER_PRIVATE_REGISTRY_URL}\": {\"auth\": \"${RUNNER_DOCKER_PRIVATE_REGISTRY_TOKEN}\"}}}" > "${GITLAB_CI_MULTI_RUNNER_HOME_DIR}/.docker/config.json" + fi +} + configure_ci_runner() { if [[ ! -e ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/config.toml ]]; then if [[ -n ${CI_SERVER_URL} && -n ${RUNNER_TOKEN} && -n ${RUNNER_DESCRIPTION} && -n ${RUNNER_EXECUTOR} ]]; then + if [[ "${RUNNER_EXECUTOR}" == "docker" ]];then + if [[ -n ${RUNNER_DOCKER_IMAGE} ]];then + RUNNER_DOCKER_ARGS="--docker-privileged --docker-image ${RUNNER_DOCKER_IMAGE}" + fi + if [[ "${RUNNER_DOCKER_MODE}" == "socket" ]];then + RUNNER_DOCKER_ARGS="$RUNNER_DOCKER_ARGS --docker-volumes /var/run/docker.sock:/var/run/docker.sock" + fi + if [[ -n ${RUNNER_DOCKER_ADDITIONAL_VOLUME} ]];then + RUNNER_DOCKER_ARGS="$RUNNER_DOCKER_ARGS --docker-volumes ${RUNNER_DOCKER_ADDITIONAL_VOLUME}" + fi + fi sudo -HEu ${GITLAB_CI_MULTI_RUNNER_USER} \ gitlab-ci-multi-runner register --config ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/config.toml \ - -n -u "${CI_SERVER_URL}" -r "${RUNNER_TOKEN}" --name "${RUNNER_DESCRIPTION}" --executor "${RUNNER_EXECUTOR}" + -n -u "${CI_SERVER_URL}" -r "${RUNNER_TOKEN}" --name "${RUNNER_DESCRIPTION}" --executor "${RUNNER_EXECUTOR}" --output-limit "${RUNNER_OUTPUT_LIMIT}" ${RUNNER_DOCKER_ARGS} else sudo -HEu ${GITLAB_CI_MULTI_RUNNER_USER} \ gitlab-ci-multi-runner register --config ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/config.toml fi + if [[ -n ${RUNNER_CONCURRENT} ]];then + sed -i "s/concurrent = .*/concurrent = ${RUNNER_CONCURRENT}/" ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/config.toml + fi fi } @@ -76,12 +98,19 @@ if [[ -z ${1} ]]; then generate_ssh_deploy_keys grant_access_to_docker_socket configure_ci_runner + configure_docker_credentials start-stop-daemon --start \ --chuid ${GITLAB_CI_MULTI_RUNNER_USER}:${GITLAB_CI_MULTI_RUNNER_USER} \ --exec $(which gitlab-ci-multi-runner) -- run \ --working-directory ${GITLAB_CI_MULTI_RUNNER_DATA_DIR} \ --config ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/config.toml ${EXTRA_ARGS} + echo "Stopping runner" + if [[ "${RUNNER_AUTOUNREGISTER}" == "true" ]];then + echo "Unregistering runner from ${CI_SERVER_URL}" + sudo -HEu ${GITLAB_CI_MULTI_RUNNER_USER} \ + gitlab-ci-multi-runner unregister --url ${CI_SERVER_URL} --token $(grep token ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/config.toml | awk '{print $3}' | tr -d '"') + fi else exec "$@" fi