Skip to content

Instantly share code, notes, and snippets.

@lucassrg
Last active April 6, 2021 19:16
Show Gist options
  • Save lucassrg/5985997dc680a873aac8879750ef6cf2 to your computer and use it in GitHub Desktop.
Save lucassrg/5985997dc680a873aac8879750ef6cf2 to your computer and use it in GitHub Desktop.
Install GitLab Runner on Oracle Linux 7.9 with Docker executor
#!/bin/bash
while getopts s:t: flag
do
case "${flag}" in
s) GITLAB_SERVER_URL=${OPTARG};;
t) GITLAB_SERVER_REGISTRATION_TOKEN=${OPTARG};;
esac
done
#GITLAB_SERVER_URL='https://gitlab.com/'
#GITLAB_SERVER_REGISTRATION_TOKEN='mytokenABCD'
yum -y update
yum install -y git docker-engine
systemctl start docker
systemctl enable docker
mkdir -p /srv/gitlab-runner/config
# register runner
docker run -d --rm --name gitlab-runner \
-v /srv/gitlab-runner/config:/etc/gitlab-runner:Z \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner:latest register \
--non-interactive \
--url "$GITLAB_SERVER_URL" \
--registration-token "$GITLAB_SERVER_REGISTRATION_TOKEN" \
--executor "docker" \
--docker-image alpine:latest \
--description "$HOSTNAME" \
--run-untagged="true" \
--locked="false" \
--access-level="not_protected"
status_code_register="$(docker container wait gitlab-runner)"
echo "status_code of gitlab-runner register: ${status_code_register}"
# run runner
docker run -d --name gitlab-runner --restart always \
-v /srv/gitlab-runner/config:/etc/gitlab-runner:Z \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner:latest run
echo "done"
@lucassrg
Copy link
Author

lucassrg commented Apr 6, 2021

Usage:

sudo ./install-register-runners.sh -s $GITLAB_SERVER_URL -t $GITLAB_SERVER_REGISTRATION_TOKEN

where
GITLAB_SERVER_URL is a ENV variable containing the URL of the GitLab Server, e.g. https://gitlab.com/
GITLAB_SERVER_REGISTRATION_TOKEN is an ENV variable containing the Runner Registration Token generated by the GitLab Server, e.g. ABCDEFGH

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment