Commit 0530bbc6 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Initial commit from wild script

parents
Loading
Loading
Loading
Loading

gitlab-runner@.service

0 → 100644
+16 −0
Original line number Diff line number Diff line
[Unit]
Description=GitLab-CI Runner
After=network-online.target
Wants=network-online.target

[Service]
Environment=IMAGE=gitlab/gitlab-runner:alpine
ExecStartPre=-docker pull ${IMAGE}
ExecStart=docker run --rm \
	--name gitlab-runner-%i \
	--volume /etc/gitlab-runner/%i.d:/etc/gitlab-runner \
	--volume /run/docker.sock:/run/docker.sock \
	${IMAGE}

[Install]
WantedBy=multi-user.target

register.sh

0 → 100755
+68 −0
Original line number Diff line number Diff line
#!/bin/bash

set -eu

usage() {
	cat <<-END
	Usage: $0 [-h] [-d DESCRIPTION] [-u COORDINATOR] NAME TOKEN

	Options:
	  -h --help         Print this message and exit
	  -u --url          The co-ordinator's URL
	  -d --description  A description for the GitLab UI (defaults to NAME)

	Arguments:
	  NAME   An instance name to identify this runner
	  TOKEN  A registration token provided by the co-ordinator (GitLab) instance
	END
}

offset=0
while [[ $# -gt 0 ]]; do
	case "$1" in
		-h|--help) usage; exit 0 ;;
		-d|--description) DESCRIPTION=${2:$offset}; shift ;;
		-u|--url|--coordinator-url) COORDINATOR_URL=${2:$offset}; shift ;;

		--*=*) set -- "${1%%=*}" "${1#=*}" "${@:2}"; continue ;;
		-??*) set -- "${1:0:2}" "-${1:2}" "${@:2}"; offset=1; continue ;;

		--) ARGS+=( "${@:2}" ); break ;;
		*) ARGS+=( "$1" ) ;;
	esac
	shift
	offset=0
done

trap '{ echo; usage; } >&2' EXIT
set -- "${ARGS[@]}"
: ${NAME:=${1? An instance name is required}} \
  ${TOKEN:=${2? A registration token is required}} \
  ${DESCRIPTION:=${NAME}} \
  ${COORDINATOR_URL:=https://code.kodo.org.uk/} \
shift 2
if [[ $# -eq 0 ]]; then
	echo >&2 "Unknown arguments: $*"
	exit 2
fi
trap - EXIT

UNIT=$(systemd-escape -m gitlab-runner@${NAME})
DIR=${UNIT%.service}
DIR=${DIR#gitlab-runner@}.d

docker run --rm -t -i -v /etc/gitlab-runner/${DIR}:/etc/gitlab-runner \
	gitlab/gitlab-runner register \
	--non-interactive \
	--url ${COORDINATOR_URL} \
	--registration-token ${TOKEN} \
	--description ${NAME} \
	--executor docker \
	--docker-image docker:stable \
	--docker-privileged=true \
	--docker-pull-policy always \
	--run-untagged=true \
	--locked=false

systemctl enable ${UNIT}
systemctl start ${UNIT}