Last active
June 16, 2016 21:16
-
-
Save eduardocardoso/988b31994d40c59cd5f434a46ea7c5ab to your computer and use it in GitHub Desktop.
Gitlab Runner service
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
[Unit] | |
Description=GitLab Runner | |
[Service] | |
ExecStartPre=-/usr/bin/docker rm gitlab-runner-%i | |
ExecStartPre=-/usr/bin/docker pull gitlab/gitlab-runner:latest | |
ExecStart=/usr/bin/docker run --name gitlab-runner-%i \ | |
-v /var/run/docker.sock:/var/run/docker.sock \ | |
gitlab/gitlab-runner:latest | |
ExecStartPost=/opt/bin/runner-register.sh %i | |
ExecStop=/opt/bin/runner-unregister.sh %i | |
Restart=always | |
RestartSec=5 | |
[Install] | |
WantedBy=multi-user.target |
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
#!/bin/bash | |
set -e | |
DOCKER_VERSION=$(docker -v | awk '{print $3}' | sed -e 's/,//g') | |
HOST="<GITLAB-HOST>" | |
IMAGE=docker:${DOCKER_VERSION} | |
TOKEN="<RUNNER-TOKEN>" | |
RUNNER_ID=$1 | |
DESCRIPTION="Docker - ${RUNNER_ID}" | |
echo "Sleeping for 5 seconds before registering runner" | |
sleep 5 | |
echo "Docker version = ${DOCKER_VERSION}" | |
/usr/bin/docker exec gitlab-runner-${RUNNER_ID} gitlab-runner register -n --url "${HOST}" --registration-token "${TOKEN}" --description "${DESCRIPTION}" --executor "docker" --docker-image "${IMAGE}" --docker-volumes /var/run/docker.sock:/var/run/docker.sock --docker-host unix:///var/run/docker.sock --env DOCKER_VERSION=${DOCKER_VERSION} |
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
#!/bin/bash | |
set -e | |
RUNNER_ID=$1 | |
DESCRIPTION="Docker - ${RUNNER_ID}" | |
/usr/bin/docker exec gitlab-runner-${RUNNER_ID} gitlab-runner unregister --name "${DESCRIPTION}" | |
/usr/bin/docker stop gitlab-runner-${RUNNER_ID} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment