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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/bash
############################################
# Description:
# Manage the gitlab runners
# Usage:
# $ ./setup-gitlab-runner new <TOKEN>
# $ ./setup-gitlab-runner start
#
# Register in crontab:
#
# */10 * * * * $HOME/setup-github-runner.sh start >& /tmp/$USER/github-runner/start.log
#
# Author: Tao Lin <lintao AT ihep.ac.cn>
############################################
#############################################
# Configuration
#############################################
export RUNNER_TOP_DIR=/tmp/$USER/gitlab-runner
export SINGULARITY_BINDPATH=/cvmfs
export RUNNER_URL=https://code.ihep.ac.cn
[ -d "$RUNNER_TOP_DIR" ] || mkdir $RUNNER_TOP_DIR
#############################################
# Create a new gitlab runner (glr)
#############################################
# ./gitlab-runner register --url https://code.ihep.ac.cn --token XXXXXX
function glr-preq() {
# if $HOME/gitlab-runner exists
if [ -f "$HOME/gitlab-runner" ]; then
cp $HOME/gitlab-runner .
else
curl -L --output gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64
fi
chmod +x gitlab-runner
}
function glr-new() {
local runner_url=$1; shift
local token=$1; shift
local executor=${1:-shell}; shift
local shell=${1:-bash}; shift
pushd $RUNNER_TOP_DIR
# check if gitlab-runner exists
if [ ! -f gitlab-runner ]; then
glr-preq
fi
./gitlab-runner register --url $runner_url --token $token --executor $executor --shell $shell
popd
}
function new() {
local token=$1; shift
if [ -z "$token" ]; then
echo "Please pass the token to this script" 1>&2
exit -1
fi
glr-new $RUNNER_URL $token
}
#############################################
# Create a new gitlab runner (glr)
#############################################
function glr-start() {
local glr=gitlab-runner
pushd $RUNNER_TOP_DIR
apptainer instance start ~/github-runner.sif ${glr}
apptainer run instance://${glr} bash -c "./gitlab-runner run -c ./config.toml &"
popd
}
function start() {
glr-start
}
#############################################
# Command line options
#############################################
cmd=$1; shift
if [ -z "$cmd" ]; then
echo "Please specify the command to be invoked" 1>&2
exit -1
fi
case $cmd in
new)
new $*
;;
start)
start $*
;;
*)
echo "Unknown command '$cmd'" 1>&2
;;
esac