forked from gr0vity-dev/lxd-github-runner
-
Notifications
You must be signed in to change notification settings - Fork 1
/
prepare-instance
executable file
·50 lines (37 loc) · 1.62 KB
/
prepare-instance
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
#!/bin/sh
LXD_CONTAINER=$1
(
cat << EOF
#!/bin/sh
set -eu
sudo apt-get update
#prepare most basic dependencies
sudo apt-get install ca-certificates curl gnupg lsb-release --yes
#prepare python 3.8 environment
sudo apt-get install python3.8-venv python3.8-dev gcc jq --yes
#prepare docker and docker-compose
sudo apt-get install apt-transport-https ca-certificates gnupg-agent software-properties-common --yes
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get install docker-ce=5:20.10.22~3-0~ubuntu-focal docker-ce-cli=5:20.10.22~3-0~ubuntu-focal docker-compose-plugin containerd.io --yes
#workaround to escape $@ to prevent script parameters to be used. We want to use legacy "docker-compose" beside the new "docker compose"
echo 'docker compose "$' > /bin/docker-compose
echo '@"' > /bin/docker-compose && sed -i 's/^/docker compose "$/' /bin/docker-compose
chmod +x /bin/docker-compose
ARCH=x64
[ "\$(uname -m)" = "aarch64" ] && ARCH=arm64
curl -o /tmp/runner.tar.gz -L https://github.com/actions/runner/releases/download/v2.299.1/actions-runner-linux-\${ARCH}-2.299.1.tar.gz
# Create directory for the runner
rm -rf /srv/github-actions/
mkdir /srv/github-actions/
cd /srv/github-actions/
chown ubuntu:ubuntu /srv/github-actions/
# Unpack the code
sudo -u ubuntu -i tar zxf /tmp/runner.tar.gz -C /srv/github-actions/
# Add ubuntu user to docker group
sudo -su ubuntu sudo usermod -aG docker ubuntu
echo "ALL SETUP"
# Cleanup
rm /tmp/runner.tar.gz
EOF
) | lxc exec $LXD_CONTAINER /bin/sh