1
1
#! /usr/bin/env bash
2
2
3
+ # check if the script is being run inside a google cloud compute instance
4
+ # to perform this check we are looking for the metadata server
5
+ # if the metadata server is not found, we assume that the script is being run
6
+ # outside of a google cloud compute instance
7
+ if curl -s -f -m 5 -o /dev/null http://metadata.google.internal/computeMetadata/v1/instance/attributes/ -H " Metadata-Flavor: Google" ; then
8
+ # We are running inside a google cloud compute instance
9
+ # Retrieving the metadata keys
10
+ METADATA_KEYS=$( curl -s -f -m 5 http://metadata.google.internal/computeMetadata/v1/instance/attributes/ -H " Metadata-Flavor: Google" )
11
+ for key in ${METADATA_KEYS} ; do
12
+ # if the key starts with RUNNER_ then we export it as an environment variable
13
+ if [[ ${key} =~ ^RUNNER_ ]]; then
14
+ export " ${key} " =" $( curl -s -f -m 5 http://metadata.google.internal/computeMetadata/v1/instance/attributes/" ${key} " -H ' Metadata-Flavor: Google' ) "
15
+ fi
16
+ done
17
+ fi
18
+
3
19
RUNNER_NAME=${RUNNER_NAME:- $(hostname)}
4
20
RUNNER_ORG=${RUNNER_ORG:- " org" }
5
21
RUNNER_LABELS=${RUNNER_LABELS:- " runner" }
62
78
if [[ ! ${RUNNER_LABELS} =~ " no-docker" ]]; then
63
79
64
80
if [[ ${LINUX_OS} == " ubuntu" ]]; then
81
+ sudo install -m 0755 -d /etc/apt/keyrings
65
82
sudo apt-get -y update
66
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg - o /tmp /docker.gpg
67
- sudo cat /tmp/docker.gpg | sudo gpg --dearmor -o /usr/share /keyrings/docker-archive-keyring .gpg || true
83
+ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor - o /etc/apt/keyrings /docker.gpg
84
+ sudo chmod a+r /etc/apt /keyrings/docker.gpg
68
85
echo \
69
- " deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
70
- ${LSB_RELEASE_CS} stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
71
- sudo apt-get update --yes --force-yes
72
- sudo apt-get install --yes --force-yes docker-ce docker-ce-cli containerd.io
86
+ deb [arch= " $( dpkg --print-architecture) " signed-by= /etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
87
+ " $( . /etc/os-release && echo " ${VERSION_CODENAME} " ) " stable |
88
+ sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
89
+ sudo apt-get update --yes
90
+ sudo apt-get install --yes docker-ce docker-ce-cli containerd.io
73
91
elif [[ ${LINUX_OS} == " centos" ]] || [[ ${LINUX_OS} == " rocky" ]] || [[ ${LINUX_OS} == " almalinux" ]]; then
74
92
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
75
93
sudo yum install -y epel-release docker-ce docker-ce-cli containerd.io
@@ -101,7 +119,6 @@ if [[ ! ${RUNNER_LABELS} =~ "no-docker" ]]; then
101
119
fi
102
120
103
121
# Login as actions user so that all the following commands are executed as actions user
104
- sudo su - actions
105
122
mkdir -p /home/actions/actions-runner
106
123
cd /home/actions/actions-runner || exit
107
124
# Download the runner package
@@ -124,7 +141,8 @@ TimeoutStopSec=5min
124
141
[Install]
125
142
WantedBy=multi-user.target" > /home/actions/actions-runner/bin/actions.runner.service.template
126
143
127
- ./config.sh \
144
+ sudo chown -Rh actions:actions /home/actions/actions-runner
145
+ sudo -u actions /home/actions/actions-runner/config.sh \
128
146
--url " https://github.com/${RUNNER_ORG} " \
129
147
--token " ${RUNNER_TOKEN} " \
130
148
--name " ${RUNNER_NAME} " \
0 commit comments