-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate-runner.sh
executable file
·44 lines (39 loc) · 1.6 KB
/
create-runner.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
#!/usr/bin/env zsh
# usage: create-runner.sh <id> <base_vm> <base_snapshot> <configuration_name> <github_runner_label>
script_dir=${0:a:h}
. "$script_dir/common.sh"
id=$1; shift
base_vm=$1; shift
base_snapshot=$base_vm@$1; shift
configuration_name=$1; shift
github_runner_label=$1; shift
configure_runner=$script_dir/$configuration_name/configure-runner.sh
register_runner=$script_dir/$configuration_name/register-runner.sh
virt_clone=$script_dir/$configuration_name/virt-clone.sh
vm=$base_vm.$id
>&2 printf '[*] Creating runner: %s\n' $vm
runner_data=$SERVO_CI_MONITOR_DATA_PATH/runners/$id
mkdir $runner_data
touch $runner_data/created-time
zfs clone $SERVO_CI_ZFS_CLONE_PREFIX/$base_snapshot $SERVO_CI_ZFS_PREFIX/$vm
partition_block_device=/dev/zvol/$SERVO_CI_ZFS_PREFIX/$vm-part1
t=0; while ! test -e $partition_block_device; do
if [ $t -ge $SERVO_CI_ZVOL_BLOCK_DEVICE_TIMEOUT ]; then
>&2 printf '[!] Timed out waiting for block device: %s' $partition_block_device
exit 1
fi
sleep 1
t=$((t+1))
done
if ! [ -n "${SERVO_CI_DONT_REGISTER_RUNNERS+set}" ]; then
$register_runner "$github_runner_label" $vm > $runner_data/github-api-registration
>&2 echo "GitHub API runner id is $(jq .runner.id $runner_data/github-api-registration)"
runner_jitconfig=$(jq .encoded_jit_config $runner_data/github-api-registration)
else
>&2 echo 'Skipping GitHub API registration (SERVO_CI_DONT_REGISTER_RUNNERS)'
runner_jitconfig=
fi
"$script_dir/mount-runner.sh" $vm $configure_runner "$runner_jitconfig"
libvirt_vm=$SERVO_CI_LIBVIRT_PREFIX-$vm
$virt_clone $base_vm $vm
virsh start $libvirt_vm