|
1 | 1 | #!/bin/bash |
2 | | - |
3 | 2 | set -e |
4 | 3 |
|
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 |
8 | 9 |
|
9 | 10 | RUNNER_NAME="runner-$(head /dev/urandom | tr -dc a-z0-9 | head -c 6)" |
10 | 11 | export RUNNER_NAME |
11 | 12 |
|
12 | | -# Ensure /actions-runner is accessible and owned |
| 13 | +# Permissions / groupe docker |
13 | 14 | chown -R docker:docker /actions-runner |
14 | | - |
15 | | -# Get Docker socket GID and allow docker user to access it |
16 | 15 | DOCKER_GID=$(stat -c '%g' /var/run/docker.sock) |
17 | 16 | groupadd -g "$DOCKER_GID" docker-host || true |
18 | 17 | usermod -aG docker-host docker |
19 | 18 |
|
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) |
40 | 24 |
|
| 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" |
41 | 31 |
|
| 32 | +# Cleanup à l’arrêt |
42 | 33 | 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" |
45 | 36 | } |
46 | 37 | trap 'cleanup; exit 130' INT |
47 | 38 | trap 'cleanup; exit 143' TERM |
48 | 39 |
|
49 | | -./run.sh |
50 | | -EOF |
| 40 | +# Lancer en foreground (PID 1) |
| 41 | +exec sudo -u docker /actions-runner/run.sh |
0 commit comments