Last active
November 15, 2017 23:08
-
-
Save joaocc/330fa0add1f61cebc95041b2d61b988a to your computer and use it in GitHub Desktop.
Gitlab-runner as dind
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
set -o pipefail | |
THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
T_STAMP=$(date -u +"%Y%m%d_%H%M%SZ") | |
set -x | |
# docker rm -f gitlab-runner-dind gitlab-dind-host | |
# docker volume rm cache.gitab-runner-dind var-lib-docker.gitlab-dind-host | |
[ "$1" == "" ] || docker network create ci-gitlab-net || true | |
if [ "$1" == "dind" ]; then | |
if [ "$2" == "use-dir" ]; then | |
DIND_HOST__VAR_LIB_DOCKER=/opt/mnt/c-data/gitlab.dind/host.var--lib--docker | |
DIND_RUNNER_CACHE_PRFX=/opt/cfg/gitlab-runner/config.dind | |
else | |
if [ "$2" == "use-dir" ]; then | |
DIND_HOST__VAR_LIB_DOCKER=var-lib-docker.gitlab-dind-host | |
DIND_RUNNER_CACHE_PRFX=cache.gitab-runner-dind | |
else | |
exit -5 | |
fi | |
fi | |
# https://medium.com/@tonywooster/docker-in-docker-in-gitlab-runners-220caeb708ca | |
docker run -d \ | |
--name gitlab-dind-host \ | |
--restart always \ | |
--network ci-gitlab-net \ | |
--privileged \ | |
-v ${DIND_HOST__VAR_LIB_DOCKER}:/var/lib/docker \ | |
docker:edge-dind | |
for rxid in 1 2 3; do | |
docker run -d \ | |
--name gitlab-runner-dind-${rxid} \ | |
--restart always \ | |
--network ci-gitlab-net \ | |
-e DOCKER_HOST=tcp://gitlab-dind-host:2375 \ | |
-v /opt/cfg/gitlab-runner/config.dind.${rxid}:/etc/gitlab-runner \ | |
-v ${DIND_RUNNER_CACHE_PRFX}.${rxid}:/cache \ | |
gitlab/gitlab-runner:latest | |
done | |
for rxid in 1 2 3; do | |
docker exec -it \ | |
gitlab-runner-dind-${rxid} \ | |
gitlab-runner register \ | |
--executor docker \ | |
--docker-image docker:edge \ | |
--docker-volumes /var/run/docker.sock:/var/run/docker.sock | |
done | |
fi | |
if [ "$1" == "noroot" ]; then | |
docker run -d \ | |
--name gitlab-runner-noroot \ | |
--restart always \ | |
--network ci-gitlab-net \ | |
-v /var/run/docker.sock:/var/run/docker.sock \ | |
-v /opt/cfg/gitlab-runner/config.noroot:/etc/gitlab-runner \ | |
-v cache.gitab-runner-noroot:/cache \ | |
gitlab/gitlab-runner:latest | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment