forked from stgraber/lxd-github-actions
-
Notifications
You must be signed in to change notification settings - Fork 2
/
renew_runner_token
executable file
·39 lines (32 loc) · 1016 Bytes
/
renew_runner_token
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
#!/bin/bash
LXD_CONTAINER=$1
RUNNER_URL=$2
GH_RUNNER_TOKEN=$3
LABELS=$4
# This is done outside the scope of the LXD container because exporting variables is not working as expected
_PROTO="$(echo "${RUNNER_URL}" | grep :// | sed -e's,^\(.*://\).*,\1,g')"
_URL="$(echo "${RUNNER_URL/${_PROTO}/}")"
_PATH="$(echo "${_URL}" | grep / | cut -d/ -f2-)"
#Create the github runner service
(
cat << EOF
# Setup the systemd unit
(
cat << EOG
[Unit]
Description=github - Actions runner
Requires=network-online.target
After=network-online.target
[Service]
Type=oneshot
WorkingDirectory=/srv/github-actions/
ExecStartPre=/usr/bin/sudo -u ubuntu -i /srv/github-actions/config.sh --url $RUNNER_URL --token $GH_RUNNER_TOKEN --unattended --ephemeral --labels "$LABELS"
ExecStart=-/usr/bin/sudo -u ubuntu -i /srv/github-actions/run.sh
ExecStartPost=/usr/sbin/poweroff
[Install]
WantedBy=multi-user.target
EOG
) > /etc/systemd/system/github-actions.service
systemctl enable github-actions
EOF
) | lxc exec $LXD_CONTAINER /bin/sh