-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate-config.sh
executable file
·113 lines (93 loc) · 3.21 KB
/
generate-config.sh
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
111
112
#!/bin/bash
# Arguments are: <this_script> <original_config>
# Example: ./generate-config.sh ~/.gitlab-runner/config.toml
# Check usage
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <original_config>"
exit 1
fi
TOML_FILEPATH=$(readlink -f "$1")
# Check if the original config file exists
if [ ! -f "$1" ]; then
echo "Error: $1 does not exist"
exit 1
fi
# Check if the original config file is readable
if [ ! -r "$1" ]; then
echo "Error: $1 is not readable"
exit 1
fi
# The absolute path to this script
SCRIPT_FILEPATH=$(readlink -f "$0")
SCRIPT_DIRPATH=$(dirname "$SCRIPT_FILEPATH")
# Find the following values in the config file ( pattern is: "key = value" )
# check_interval
# shutdown_timeout
# name
# url
# id
# token
# token_obtained_at
# token_expires_at
# Value might or might not be quoted, key might or might not have spaces around it
# Example: concurrent = 10
# Example: concurrent=10
function get_value {
local key="$1"
local key_regex="$key = *" # The regex to match the key
while IFS= read -r line; do
if [[ "$line" =~ $key_regex ]]; then
local value="${line#*=}" # Remove everything before the '='
value="${value#"${value%%[![:space:]]*}"}" # Remove leading whitespace
value="${value%"${value##*[![:space:]]}"}" # Remove trailing whitespace
echo "$value"
return 0
fi
done < "$TOML_FILEPATH"
echo "Error: Could not find value for key '$key' in $TOML_FILEPATH"
return 1
}
value_check_interval=$(get_value check_interval "$1")
value_shutdown_timeout=$(get_value shutdown_timeout "$1")
value_name=$(get_value name "$1")
value_url=$(get_value url "$1")
value_id=$(get_value id "$1")
value_token=$(get_value token "$1")
value_token_obtained_at=$(get_value token_obtained_at "$1")
value_token_expires_at=$(get_value token_expires_at "$1")
new_content=$( cat <<EOF
check_interval = $value_check_interval
shutdown_timeout = $value_shutdown_timeout
# Amount of concurrent SLURM jobs that can be running at the same time
concurrent = 10
[[runners]]
executor = "custom"
# Values generated by "gitlab-runner register"
name = $value_name
url = $value_url
id = $value_id
token = $value_token
token_obtained_at = $value_token_obtained_at
token_expires_at = $value_token_expires_at
# Paths to the builds and cache directories
# - must be absolute
# - must be owned by the user running gitlab-runner
# - must have enough space to store potential large artifacts
builds_dir = "$SCRIPT_DIRPATH/wd/builds"
cache_dir = "$SCRIPT_DIRPATH/wd/cache"
# Un-comment me out during debugging
# log_level = "debug"
# Paths to the driver/main.py executable controlling the SLURM jobs
[runners.custom]
config_exec = "$SCRIPT_DIRPATH/driver/driver.py"
config_args = ["config", "$SCRIPT_DIRPATH/wd/builds", "$SCRIPT_DIRPATH/wd/cache"]
prepare_exec = "$SCRIPT_DIRPATH/driver/driver.py"
prepare_args = ["prepare"]
run_exec = "$SCRIPT_DIRPATH/driver/driver.py"
run_args = ["run"]
cleanup_exec = "$SCRIPT_DIRPATH/driver/driver.py"
cleanup_args = ["cleanup"]
EOF
)
# Echo the new content to stdout
echo "$new_content"