Skip to content

Commit 6faefe5

Browse files
committed
Refactor start.sh script: improve variable checks, simplify runner configuration, and enhance permission handling.
1 parent f875a05 commit 6faefe5

File tree

1 file changed

+22
-31
lines changed

1 file changed

+22
-31
lines changed

scripts/start.sh

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,41 @@
11
#!/bin/bash
2-
32
set -e
43

5-
GH_OWNER=$GH_OWNER
6-
#GH_REPOSITORY=$GH_REPOSITORY
7-
GH_TOKEN=$GH_TOKEN
4+
# Vérifs variables
5+
if [ -z "$GH_OWNER" ] || [ -z "$GH_TOKEN" ]; then
6+
echo "GH_OWNER et GH_TOKEN doivent être définis"
7+
exit 1
8+
fi
89

910
RUNNER_NAME="runner-$(head /dev/urandom | tr -dc a-z0-9 | head -c 6)"
1011
export RUNNER_NAME
1112

12-
# Ensure /actions-runner is accessible and owned
13+
# Permissions / groupe docker
1314
chown -R docker:docker /actions-runner
14-
15-
# Get Docker socket GID and allow docker user to access it
1615
DOCKER_GID=$(stat -c '%g' /var/run/docker.sock)
1716
groupadd -g "$DOCKER_GID" docker-host || true
1817
usermod -aG docker-host docker
1918

20-
# Switch to docker user for config and execution
21-
su docker <<EOF
22-
cd /actions-runner
23-
24-
#if [ ! -f .runner ]; then
25-
# REG_TOKEN=\$(curl -sX POST \
26-
# -H "Accept: application/vnd.github.v3+json" \
27-
# -H "Authorization: token ${GH_TOKEN}" \
28-
# https://api.github.com/repos/${GH_OWNER}/${GH_REPOSITORY}/actions/runners/registration-token | jq -r .token)
29-
#
30-
# ./config.sh --unattended --url https://github.com/${GH_OWNER}/${GH_REPOSITORY} --token "\$REG_TOKEN" --name "\$RUNNER_NAME"
31-
#fi
32-
if [ ! -f .runner ]; then
33-
REG_TOKEN=\$(curl -sX POST \
34-
-H "Accept: application/vnd.github.v3+json" \
35-
-H "Authorization: token ${GH_TOKEN}" \
36-
https://api.github.com/orgs/${GH_OWNER}/actions/runners/registration-token | jq -r .token)
37-
38-
./config.sh --unattended --url https://github.com/${GH_OWNER} --token "\$REG_TOKEN" --name "\$RUNNER_NAME"
39-
fi
19+
# Création du token
20+
REG_TOKEN=$(curl -sX POST \
21+
-H "Accept: application/vnd.github.v3+json" \
22+
-H "Authorization: token ${GH_TOKEN}" \
23+
https://api.github.com/orgs/${GH_OWNER}/actions/runners/registration-token | jq -r .token)
4024

25+
# Configurer le runner
26+
sudo -u docker /actions-runner/config.sh \
27+
--unattended \
28+
--url "https://github.com/${GH_OWNER}" \
29+
--token "$REG_TOKEN" \
30+
--name "$RUNNER_NAME"
4131

32+
# Cleanup à l’arrêt
4233
cleanup() {
43-
echo "Removing runner..."
44-
./config.sh remove --unattended --token "\$REG_TOKEN"
34+
echo "Suppression du runner..."
35+
sudo -u docker /actions-runner/config.sh remove --unattended --token "$REG_TOKEN"
4536
}
4637
trap 'cleanup; exit 130' INT
4738
trap 'cleanup; exit 143' TERM
4839

49-
./run.sh
50-
EOF
40+
# Lancer en foreground (PID 1)
41+
exec sudo -u docker /actions-runner/run.sh

0 commit comments

Comments
 (0)