Skip to content

Instantly share code, notes, and snippets.

@slavahatnuke
Last active December 5, 2018 18:10
Show Gist options
  • Save slavahatnuke/8b8245945fce0b1de0643b42123a4d73 to your computer and use it in GitHub Desktop.
Save slavahatnuke/8b8245945fce0b1de0643b42123a4d73 to your computer and use it in GitHub Desktop.
GitLab runner - docker - single command register & start
#!/bin/bash
### ./glr.sh [APP] [TOKEN]
NAME=$1
TOKEN=$2
DIR="gitlab-runner-$NAME"
PWD=$(pwd)
mkdir $DIR || echo "DIR $DIR exists"
if [ ! -z "$TOKEN" ]; then
echo "register $TOKEN"
docker run --rm \
-v "$PWD/$DIR":/etc/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock --privileged \
gitlab/gitlab-runner:latest register \
--non-interactive \
--url "https://gitlab.com/" \
--registration-token "$TOKEN" \
--executor "docker" \
--docker-image alpine:latest \
--description "docker-runner" \
--tag-list "docker,aws,glr,$NAME" \
--run-untagged \
--locked="false" \
--docker-privileged
fi
## -d --restart always
RUNNER="gitlab-runner-$NAME"
docker stop $RUNNER
docker run --restart always \
-v "$PWD/$DIR":/etc/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock --privileged \
-d --name $RUNNER \
gitlab/gitlab-runner:latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment