60-gitlab-install 1.34 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
#!/bin/sh -efu

gl_url="https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-"

add_user() {
	useradd -c 'Gitlab Runner' -m "$1"
	[ -z "$GLOBAL_GL_SSH_KEY" ] || echo "$GLOBAL_GL_SSH_KEY" >> /home/"$1"/.ssh/authorized_keys
	usermod -L "$1" ||
	echo "*** failed to add user '$1'"
}


case "$GLOBAL_ARCH" in
	x86_64)
		gl_url="${gl_url}amd64"
	;;
	i586)
		gl_url="${gl_url}386"
	;;
	armh)
		gl_url="${gl_url}arm"
	;;
	aarch64)
		gl_url="${gl_url}arm64"
	;;
	ppc64le)
		gl_url="${gl_url}ppc64le"
	;;
	*)
		echo "arch $GLOBAL_ARCH not supported!"
		exit 1
	;;
esac

if [ -n "$GLOBAL_GL_USER" ]; then
	add_user "$GLOBAL_GL_USER"
	echo 'nameserver 8.8.8.8' >> /etc/resolv.conf
	curl -L --output /usr/local/bin/gitlab-runner "$gl_url"
	chmod +x /usr/local/bin/gitlab-runner
	cat > /lib/systemd/system/gitlab-runner.service << EOF
[Unit]
Description=GitLab Runner
ConditionFileIsExecutable=/usr/local/bin/gitlab-runner

After=syslog.target network.target

[Service]
StartLimitInterval=5
StartLimitBurst=10
ExecStart=/usr/bin/gitlab-runner "run" "--working-directory" "/home/$GLOBAL_GL_USER" "--config" "/etc/gitlab-runner/config.toml" "--service" "gitlab-runner" "--user" "$GLOBAL_GL_USER"

Restart=always

RestartSec=120
EnvironmentFile=-/etc/sysconfig/gitlab-runner

[Install]
WantedBy=multi-user.target
EOF
    systemctl enable gitlab-runner
fi