Skip to content

Commit 52b7bf6

Browse files
authored
PTFE-774 gcloud not attaching (#372)
2 parents 05aa4e0 + 54ddc9c commit 52b7bf6

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

.trunk/configs/.shellcheckrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
enable=all
22
source-path=SCRIPTDIR
33
disable=SC2154
4+
disable=SC2312
45

56
# If you're having issues with shellcheck following source, disable the errors via:
67
# disable=SC1090

runner_manager/bin/startup.sh

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
#!/usr/bin/env bash
22

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+
319
RUNNER_NAME=${RUNNER_NAME:-$(hostname)}
420
RUNNER_ORG=${RUNNER_ORG:-"org"}
521
RUNNER_LABELS=${RUNNER_LABELS:-"runner"}
@@ -62,14 +78,16 @@ fi
6278
if [[ ! ${RUNNER_LABELS} =~ "no-docker" ]]; then
6379

6480
if [[ ${LINUX_OS} == "ubuntu" ]]; then
81+
sudo install -m 0755 -d /etc/apt/keyrings
6582
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
6885
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
7391
elif [[ ${LINUX_OS} == "centos" ]] || [[ ${LINUX_OS} == "rocky" ]] || [[ ${LINUX_OS} == "almalinux" ]]; then
7492
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
7593
sudo yum install -y epel-release docker-ce docker-ce-cli containerd.io
@@ -101,7 +119,6 @@ if [[ ! ${RUNNER_LABELS} =~ "no-docker" ]]; then
101119
fi
102120

103121
# Login as actions user so that all the following commands are executed as actions user
104-
sudo su - actions
105122
mkdir -p /home/actions/actions-runner
106123
cd /home/actions/actions-runner || exit
107124
# Download the runner package
@@ -124,7 +141,8 @@ TimeoutStopSec=5min
124141
[Install]
125142
WantedBy=multi-user.target" >/home/actions/actions-runner/bin/actions.runner.service.template
126143

127-
./config.sh \
144+
sudo chown -Rh actions:actions /home/actions/actions-runner
145+
sudo -u actions /home/actions/actions-runner/config.sh \
128146
--url "https://github.com/${RUNNER_ORG}" \
129147
--token "${RUNNER_TOKEN}" \
130148
--name "${RUNNER_NAME}" \

runner_manager/models/backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def runner_env(self, runner: Runner) -> RunnerEnv:
4545

4646
return RunnerEnv(
4747
RUNNER_NAME=runner.name,
48-
RUNNER_LABELS=", ".join([label.name for label in runner.labels]),
48+
RUNNER_LABELS=",".join([label.name for label in runner.labels]),
4949
RUNNER_TOKEN=runner.token,
5050
RUNNER_ORG=runner.organization,
5151
RUNNER_GROUP=runner.runner_group_name,

0 commit comments

Comments
 (0)