├── .gitignore ├── VERSION ├── .dockerignore ├── Makefile ├── docker-compose.yml ├── Changelog.md ├── LICENSE ├── Dockerfile ├── entrypoint.sh └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 1.1.4-7 2 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | .git 2 | VERSION 3 | README.md 4 | Changelog.md 5 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: build 2 | 3 | build: 4 | @docker build --tag=sameersbn/gitlab-ci-multi-runner . 5 | 6 | release: build 7 | @docker build --tag=sameersbn/gitlab-ci-multi-runner:$(shell cat VERSION) . 8 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | GitlabCIMultiRunner: 2 | image: sameersbn/gitlab-ci-multi-runner:1.1.4-7 3 | volumes: 4 | - /srv/docker/gitlab-runner:/home/gitlab_ci_multi_runner/data 5 | environment: 6 | - CI_SERVER_URL= 7 | - RUNNER_TOKEN= 8 | - RUNNER_DESCRIPTION= 9 | - RUNNER_EXECUTOR=shell 10 | restart: always 11 | -------------------------------------------------------------------------------- /Changelog.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | **1.1.4** 4 | - gitlab-ci-multi-runner: upgrade to 1.1.4 5 | 6 | **1.1.3** 7 | - gitlab-ci-multi-runner: upgrade to 1.1.3 8 | 9 | **1.1.2** 10 | - gitlab-ci-multi-runner: upgrade to 1.1.2 11 | 12 | **1.1.1** 13 | - gitlab-ci-multi-runner: upgrade to 1.1.1 14 | 15 | **1.1.0** 16 | - gitlab-ci-multi-runner: upgrade to 1.1.0 17 | 18 | **1.0.4** 19 | - gitlab-ci-multi-runner: upgrade to 1.0.4 20 | 21 | **1.0.0** 22 | - gitlab-ci-multi-runner: upgrade to 1.0.0 23 | 24 | **0.7.2** 25 | - gitlab-ci-multi-runner: upgrade to 0.7.2 26 | 27 | **0.5.5-1** 28 | - initial creation, adapted from https://github.com/sameersbn/docker-gitlab-ci-runner 29 | - support `docker` executor. Fixes #5 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Sameer Naik 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM sameersbn/ubuntu:14.04.20170110 2 | MAINTAINER sameer@damagehead.com 3 | 4 | ENV GITLAB_CI_MULTI_RUNNER_VERSION=1.1.4 \ 5 | GITLAB_CI_MULTI_RUNNER_USER=gitlab_ci_multi_runner \ 6 | GITLAB_CI_MULTI_RUNNER_HOME_DIR="/home/gitlab_ci_multi_runner" 7 | ENV GITLAB_CI_MULTI_RUNNER_DATA_DIR="${GITLAB_CI_MULTI_RUNNER_HOME_DIR}/data" 8 | 9 | RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv E1DD270288B4E6030699E45FA1715D88E1DF1F24 \ 10 | && echo "deb http://ppa.launchpad.net/git-core/ppa/ubuntu trusty main" >> /etc/apt/sources.list \ 11 | && apt-get update \ 12 | && DEBIAN_FRONTEND=noninteractive apt-get install -y \ 13 | git-core openssh-client curl libapparmor1 \ 14 | && wget -O /usr/local/bin/gitlab-ci-multi-runner \ 15 | https://gitlab-ci-multi-runner-downloads.s3.amazonaws.com/v${GITLAB_CI_MULTI_RUNNER_VERSION}/binaries/gitlab-ci-multi-runner-linux-amd64 \ 16 | && chmod 0755 /usr/local/bin/gitlab-ci-multi-runner \ 17 | && adduser --disabled-login --gecos 'GitLab CI Runner' ${GITLAB_CI_MULTI_RUNNER_USER} \ 18 | && sudo -HEu ${GITLAB_CI_MULTI_RUNNER_USER} ln -sf ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/.ssh ${GITLAB_CI_MULTI_RUNNER_HOME_DIR}/.ssh \ 19 | && rm -rf /var/lib/apt/lists/* 20 | 21 | COPY entrypoint.sh /sbin/entrypoint.sh 22 | RUN chmod 755 /sbin/entrypoint.sh 23 | 24 | VOLUME ["${GITLAB_CI_MULTI_RUNNER_DATA_DIR}"] 25 | WORKDIR "${GITLAB_CI_MULTI_RUNNER_HOME_DIR}" 26 | ENTRYPOINT ["/sbin/entrypoint.sh"] 27 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | CA_CERTIFICATES_PATH=${CA_CERTIFICATES_PATH:-$GITLAB_CI_MULTI_RUNNER_DATA_DIR/certs/ca.crt} 5 | 6 | create_data_dir() { 7 | mkdir -p ${GITLAB_CI_MULTI_RUNNER_DATA_DIR} 8 | chown ${GITLAB_CI_MULTI_RUNNER_USER}:${GITLAB_CI_MULTI_RUNNER_USER} ${GITLAB_CI_MULTI_RUNNER_DATA_DIR} 9 | } 10 | 11 | generate_ssh_deploy_keys() { 12 | sudo -HEu ${GITLAB_CI_MULTI_RUNNER_USER} mkdir -p ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/.ssh/ 13 | 14 | if [[ ! -e ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/.ssh/id_rsa || ! -e ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/.ssh/id_rsa.pub ]]; then 15 | echo "Generating SSH deploy keys..." 16 | rm -rf ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/.ssh/id_rsa ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/.ssh/id_rsa.pub 17 | sudo -HEu ${GITLAB_CI_MULTI_RUNNER_USER} ssh-keygen -t rsa -N "" -f ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/.ssh/id_rsa 18 | 19 | echo "" 20 | echo -n "Your SSH deploy key is: " 21 | cat ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/.ssh/id_rsa.pub 22 | echo "" 23 | fi 24 | 25 | chmod 600 ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/.ssh/id_rsa ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/.ssh/id_rsa.pub 26 | chmod 700 ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/.ssh 27 | chown -R ${GITLAB_CI_MULTI_RUNNER_USER}:${GITLAB_CI_MULTI_RUNNER_USER} ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/.ssh/ 28 | } 29 | 30 | update_ca_certificates() { 31 | if [[ -f ${CA_CERTIFICATES_PATH} ]]; then 32 | echo "Updating CA certificates..." 33 | cp "${CA_CERTIFICATES_PATH}" /usr/local/share/ca-certificates/ca.crt 34 | update-ca-certificates --fresh >/dev/null 35 | fi 36 | } 37 | 38 | grant_access_to_docker_socket() { 39 | if [ -S /run/docker.sock ]; then 40 | DOCKER_SOCKET_GID=$(stat -c %g /run/docker.sock) 41 | DOCKER_SOCKET_GROUP=$(stat -c %G /run/docker.sock) 42 | if [[ ${DOCKER_SOCKET_GROUP} == "UNKNOWN" ]]; then 43 | DOCKER_SOCKET_GROUP=docker 44 | groupadd -g ${DOCKER_SOCKET_GID} ${DOCKER_SOCKET_GROUP} 45 | fi 46 | usermod -a -G ${DOCKER_SOCKET_GROUP} ${GITLAB_CI_MULTI_RUNNER_USER} 47 | fi 48 | } 49 | 50 | configure_ci_runner() { 51 | if [[ ! -e ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/config.toml ]]; then 52 | if [[ -n ${CI_SERVER_URL} && -n ${RUNNER_TOKEN} && -n ${RUNNER_DESCRIPTION} && -n ${RUNNER_EXECUTOR} ]]; then 53 | sudo -HEu ${GITLAB_CI_MULTI_RUNNER_USER} \ 54 | gitlab-ci-multi-runner register --config ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/config.toml \ 55 | -n -u "${CI_SERVER_URL}" -r "${RUNNER_TOKEN}" --name "${RUNNER_DESCRIPTION}" --executor "${RUNNER_EXECUTOR}" 56 | else 57 | sudo -HEu ${GITLAB_CI_MULTI_RUNNER_USER} \ 58 | gitlab-ci-multi-runner register --config ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/config.toml 59 | fi 60 | fi 61 | } 62 | 63 | # allow arguments to be passed to gitlab-ci-multi-runner 64 | if [[ ${1:0:1} = '-' ]]; then 65 | EXTRA_ARGS="$@" 66 | set -- 67 | elif [[ ${1} == gitlab-ci-multi-runner || ${1} == $(which gitlab-ci-multi-runner) ]]; then 68 | EXTRA_ARGS="${@:2}" 69 | set -- 70 | fi 71 | 72 | # default behaviour is to launch gitlab-ci-multi-runner 73 | if [[ -z ${1} ]]; then 74 | create_data_dir 75 | update_ca_certificates 76 | generate_ssh_deploy_keys 77 | grant_access_to_docker_socket 78 | configure_ci_runner 79 | 80 | start-stop-daemon --start \ 81 | --chuid ${GITLAB_CI_MULTI_RUNNER_USER}:${GITLAB_CI_MULTI_RUNNER_USER} \ 82 | --exec $(which gitlab-ci-multi-runner) -- run \ 83 | --working-directory ${GITLAB_CI_MULTI_RUNNER_DATA_DIR} \ 84 | --config ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/config.toml ${EXTRA_ARGS} 85 | else 86 | exec "$@" 87 | fi 88 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![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) 2 | 3 | # sameersbn/gitlab-ci-multi-runner:1.1.4-7 4 | 5 | - [Introduction](#introduction) 6 | - [Contributing](#contributing) 7 | - [Issues](#issues) 8 | - [Changelog](Changelog.md) 9 | - [Getting started](#getting-started) 10 | - [Installation](#installation) 11 | - [Quickstart](#quickstart) 12 | - [Command-line arguments](#command-line-arguments) 13 | - [Persistence](#persistence) 14 | - [Deploy Keys](#deploy-keys) 15 | - [Trusting SSL Server Certificates](#trusting-ssl-server-certificates) 16 | - [Maintenance](#maintenance) 17 | - [Upgrading](#upgrading) 18 | - [Shell Access](#shell-access) 19 | - [List of runners using this image](#list-of-runners-using-this-image) 20 | 21 | # Introduction 22 | 23 | `Dockerfile` to create a [Docker](https://www.docker.com/) container base image for [gitlab-ci-multi-runner](https://gitlab.com/gitlab-org/gitlab-ci-multi-runner). Use this image to build your CI runner images. 24 | 25 | ## Contributing 26 | 27 | If you find this image useful here's how you can help: 28 | 29 | - Send a pull request with your awesome features and bug fixes 30 | - Help users resolve their [issues](../../issues?q=is%3Aopen+is%3Aissue). 31 | - Support the development of this image with a [donation](http://www.damagehead.com/donate/) 32 | 33 | ## Issues 34 | 35 | Before reporting your issue please try updating Docker to the latest version and check if it resolves the issue. Refer to the Docker [installation guide](https://docs.docker.com/installation) for instructions. 36 | 37 | SELinux users should try disabling SELinux using the command `setenforce 0` to see if it resolves the issue. 38 | 39 | If the above recommendations do not help then [report your issue](../../issues/new) along with the following information: 40 | 41 | - Output of the `docker version` and `docker info` commands 42 | - The `docker run` command or `docker-compose.yml` used to start the image. Mask out the sensitive bits. 43 | - Please state if you are using [Boot2Docker](http://www.boot2docker.io), [VirtualBox](https://www.virtualbox.org), etc. 44 | 45 | # Getting started 46 | 47 | ## Installation 48 | 49 | Automated builds of the image are available on [Dockerhub](https://hub.docker.com/r/sameersbn/gitlab-ci-multi-runner) and is the recommended method of installation. 50 | 51 | > **Note**: Builds are also available on [Quay.io](https://quay.io/repository/sameersbn/gitlab-ci-multi-runner) 52 | 53 | ```bash 54 | docker pull sameersbn/gitlab-ci-multi-runner:1.1.4-7 55 | ``` 56 | 57 | Alternatively you can build the image yourself. 58 | 59 | ```bash 60 | docker build -t sameersbn/gitlab-ci-multi-runner github.com/sameersbn/docker-gitlab-ci-multi-runner 61 | ``` 62 | 63 | ## Quickstart 64 | 65 | 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. 66 | 67 | ```bash 68 | docker run --name gitlab-ci-multi-runner -d --restart=always \ 69 | --volume /srv/docker/gitlab-runner:/home/gitlab_ci_multi_runner/data \ 70 | --env='CI_SERVER_URL=http://git.example.com/ci' --env='RUNNER_TOKEN=xxxxxxxxx' \ 71 | --env='RUNNER_DESCRIPTION=myrunner' --env='RUNNER_EXECUTOR=shell' \ 72 | sameersbn/gitlab-ci-multi-runner:1.1.4-7 73 | ``` 74 | 75 | *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/)* 76 | 77 | 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. 78 | 79 | ## Command-line arguments 80 | 81 | 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: 82 | 83 | ```bash 84 | docker run --name gitlab-ci-multi-runner -it --rm \ 85 | --volume /srv/docker/gitlab-runner:/home/gitlab_ci_multi_runner/data \ 86 | sameersbn/gitlab-ci-multi-runner:1.1.4-7 --help 87 | ``` 88 | 89 | ## Persistence 90 | 91 | For the image to preserve its state across container shutdown and startup you should mount a volume at `/home/gitlab_ci_multi_runner/data`. 92 | 93 | > *The [Quickstart](#quickstart) command already mounts a volume for persistence.* 94 | 95 | SELinux users should update the security context of the host mountpoint so that it plays nicely with Docker: 96 | 97 | ```bash 98 | mkdir -p /srv/docker/gitlab-runner 99 | chcon -Rt svirt_sandbox_file_t /srv/docker/gitlab-runner 100 | ``` 101 | 102 | ## Deploy Keys 103 | 104 | At first run the image automatically generates SSH deploy keys which are installed at `/home/gitlab_ci_multi_runner/data/.ssh` of the persistent data store. You can replace these keys with your own if you wish to do so. 105 | 106 | You can use these keys to allow the runner to gain access to your private git repositories over the SSH protocol. 107 | 108 | > **NOTE** 109 | > 110 | > - The deploy keys are generated without a passphrase. 111 | > - If your CI jobs clone repositories over SSH, you will need to build the ssh known hosts file which can be done in the build steps using, for example, `ssh-keyscan github.com | sort -u - ~/.ssh/known_hosts -o ~/.ssh/known_hosts`. 112 | 113 | ## Trusting SSL Server Certificates 114 | 115 | If your GitLab server is using self-signed SSL certificates then you should make sure the GitLab server's SSL certificate is trusted on the runner for the git clone operations to work. 116 | 117 | The runner is configured to look for trusted SSL certificates at `/home/gitlab_ci_multi_runner/data/certs/ca.crt`. This path can be changed using the `CA_CERTIFICATES_PATH` enviroment variable. 118 | 119 | Create a file named `ca.crt` in a `certs` folder at the root of your persistent data volume. The `ca.crt` file should contain the root certificates of all the servers you want to trust. 120 | 121 | With respect to GitLab, append the contents of the `gitlab.crt` file to `ca.crt`. For more information on the `gitlab.crt` file please refer the [README](https://github.com/sameersbn/docker-gitlab/blob/master/README.md#ssl) of the [docker-gitlab](https://github.com/sameersbn/docker-gitlab) container. 122 | 123 | Similarly you should also trust the SSL certificate of the GitLab CI server by appending the contents of the `gitlab-ci.crt` file to `ca.crt`. 124 | 125 | # Maintenance 126 | 127 | ## Upgrading 128 | 129 | To upgrade to newer releases: 130 | 131 | 1. Download the updated Docker image: 132 | 133 | ```bash 134 | docker pull sameersbn/gitlab-ci-multi-runner:1.1.4-7 135 | ``` 136 | 137 | 2. Stop the currently running image: 138 | 139 | ```bash 140 | docker stop gitlab-ci-multi-runner 141 | ``` 142 | 143 | 3. Remove the stopped container 144 | 145 | ```bash 146 | docker rm -v gitlab-ci-multi-runner 147 | ``` 148 | 149 | 4. Start the updated image 150 | 151 | ```bash 152 | docker run -name gitlab-ci-multi-runner -d \ 153 | [OPTIONS] \ 154 | sameersbn/gitlab-ci-multi-runner:1.1.4-7 155 | ``` 156 | 157 | ## Shell Access 158 | 159 | For debugging and maintenance purposes you may want access the containers shell. If you are using Docker version `1.3.0` or higher you can access a running containers shell by starting `bash` using `docker exec`: 160 | 161 | ```bash 162 | docker exec -it gitlab-ci-multi-runner bash 163 | ``` 164 | 165 | # List of runners using this image 166 | 167 | * [docker-gitlab-ci-multi-runner-ruby](https://github.com/outcoldman/docker-gitlab-ci-multi-runner-ruby) to run ruby builds 168 | --------------------------------------------------------------------------------