Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge digitallumberjack/master modifications #33

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1fede7b
Upgrade gitlab-ci-multi-runner to v1.7.0
digitalLumberjack Oct 22, 2016
0337d65
added docker executor support
digitalLumberjack Oct 22, 2016
d3df8a7
Merge remote-tracking branch 'origin/release/v1.7.0'
digitalLumberjack Oct 23, 2016
21bdf60
added docker private registry support
digitalLumberjack Oct 23, 2016
c78eeff
fixed auth for docker
digitalLumberjack Nov 15, 2016
ee2edcf
update to xenial
saschanaz Nov 21, 2016
0de46ba
git-core -> git
saschanaz Nov 21, 2016
dc8b3bf
Merge pull request #1 from SaschaNaz/xenial
digitalLumberjack Nov 24, 2016
89a554b
gitlab-ci-multi-runner: upgrade to 1.8.0
Maescool Nov 25, 2016
225b987
Merge branch 'master' of https://github.com/Maescool/docker-gitlab-ci…
digitalLumberjack Nov 29, 2016
97d5e51
bumped to v1.9.0 of gitlab runner
digitalLumberjack Dec 29, 2016
30865ea
added support of RUNNER_CONCURRENT to set parallels jobs
digitalLumberjack Dec 29, 2016
9369254
added additonal volumes
digitalLumberjack Dec 29, 2016
688b056
fix reboot error where mkdir already existing directory
mproucelle Jan 6, 2017
974e3f2
bumped to 1.9.3 and added support of RUNNER_OUTPUT_LIMIT
digitalLumberjack Jan 14, 2017
a7cace0
bumped to runner v1.10.2
digitalLumberjack Jan 26, 2017
9947cf3
rollback to sameersbn/ubuntu:14.04.20170110 base image
digitalLumberjack Feb 5, 2017
3570012
bumped to gitlab runner v1.10.4
digitalLumberjack Feb 5, 2017
711f75d
Merge remote-tracking branch 'sam/master' into mergemaster
digitalLumberjack Feb 5, 2017
fd83ccf
restored origin image name
digitalLumberjack Feb 5, 2017
e3a7ab6
fixed package installation
digitalLumberjack Feb 5, 2017
71fbf3d
added RUNNER_AUTOUNREGISTER variable to unregister the runner on stop
digitalLumberjack Feb 5, 2017
6c55ae8
bumped to 1.11.0
digitalLumberjack Feb 26, 2017
80abfc5
bumped to runner v1.11.2
digitalLumberjack Apr 19, 2017
d050d92
fixed spelling on concurrent parameter
digitalLumberjack Jul 3, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
# Changelog

**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

Expand Down
17 changes: 16 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
FROM sameersbn/ubuntu:14.04.20170110
MAINTAINER [email protected]

ENV GITLAB_CI_MULTI_RUNNER_VERSION=1.1.4 \
ENV GITLAB_CI_MULTI_RUNNER_VERSION=1.11.0 \
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 \
Expand Down
70 changes: 64 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.0

- [Introduction](#introduction)
- [Contributing](#contributing)
Expand Down Expand Up @@ -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.0
```

Alternatively you can build the image yourself.
Expand All @@ -64,26 +64,84 @@ 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.0
```

*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.0
```

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.0
```

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:

```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.0 --help
```

## Persistence
Expand Down Expand Up @@ -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.0
```

2. Stop the currently running image:
Expand All @@ -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.0
```

## Shell Access
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.4-7
1.11.0
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GitlabCIMultiRunner:
image: sameersbn/gitlab-ci-multi-runner:1.1.4-7
image: sameersbn/gitlab-ci-multi-runner:1.11.0
volumes:
- /srv/docker/gitlab-runner:/home/gitlab_ci_multi_runner/data
environment:
Expand Down
31 changes: 30 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 = .*/concurent = ${RUNNER_CONCURRENT}/" ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/config.toml

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@digitalLumberjack spelling mistake here, should be concurrent

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks I fixed that.

digitallumberjack/docker-gitlab-ci-multi-runner:v9.3.0-1 include this fix.

fi
fi
}

Expand All @@ -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