|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
| 3 | +echo "#####################" |
| 4 | +echo "Running entrypoint.sh" |
| 5 | +echo "" |
| 6 | + |
3 | 7 | # connection details
|
4 |
| -last_char="${GH_URL: -1}" |
5 |
| -[[ $last_char == "/" ]] && GH_URL="${GH_URL::-1}" |
6 |
| -readonly _GH_URL="${GH_URL:-https://github.com}" |
| 8 | +if [ -n "$GH_URL" ]; then |
| 9 | + last_char="${GH_URL: -1}" |
| 10 | + [[ $last_char == "/" ]] && GH_URL="${GH_URL::-1}" |
| 11 | + readonly _GH_URL="$GH_URL" |
| 12 | + echo "Using custom GitHub enterprise instance: $_GH_URL" |
| 13 | +else |
| 14 | + readonly _GH_URL="https://github.com" |
| 15 | + echo "Using default GitHub instance: $_GH_URL" |
| 16 | +fi |
7 | 17 |
|
8 |
| -last_char="${GH_API_ENDPOINT: -1}" |
9 |
| -[[ $last_char == "/" ]] && GH_API_ENDPOINT="${GH_API_ENDPOINT::-1}" |
10 |
| -readonly _GH_API_ENDPOINT="${GH_API_ENDPOINT:-https://api.github.com}" |
| 18 | +if [ -n "$GH_API_ENDPOINT" ]; then |
| 19 | + last_char="${GH_API_ENDPOINT: -1}" |
| 20 | + [[ $last_char == "/" ]] && GH_API_ENDPOINT="${GH_API_ENDPOINT::-1}" |
| 21 | + readonly _GH_API_ENDPOINT="$GH_API_ENDPOINT" |
| 22 | + echo "Using custom api url: $_GH_API_ENDPOINT" |
| 23 | +else |
| 24 | + # if GH_API_ENDPOINT not specified but GH_URL |
| 25 | + if [ -n "$GH_URL" ]; then |
| 26 | + readonly _GH_API_ENDPOINT="$_GH_URL/api/v3" |
| 27 | + echo "Using custom GitHub instance with default api url: $_GH_API_ENDPOINT" |
| 28 | + else |
| 29 | + readonly _GH_API_ENDPOINT="https://api.github.com" |
| 30 | + echo "Using default GitHub instance: $_GH_API_ENDPOINT" |
| 31 | + fi |
| 32 | +fi |
11 | 33 |
|
12 | 34 | # Org/ Repo details
|
13 | 35 | if [ -n "$GH_ORG" ]; then
|
14 | 36 | readonly RUNNER_URL="${_GH_URL}/${GH_ORG}"
|
15 | 37 | readonly RUNNER_REG_TOKEN_URL="${_GH_API_ENDPOINT}/orgs/${GH_ORG}/actions/runners/registration-token"
|
16 |
| -elif [ -n "$GH_ORG" ] && [ -n "$GH_REPO" ]; then |
| 38 | + elif [ -n "$GH_ORG" ] && [ -n "$GH_REPO" ]; then |
17 | 39 | readonly RUNNER_URL="${_GH_URL}/${GH_ORG}/${GH_REPO}"
|
18 | 40 | readonly RUNNER_REG_TOKEN_URL="${_GH_API_ENDPOINT}/repos/${GH_ORG}/${GH_REPO}/actions/runners/registration-token"
|
19 |
| -elif [ -n "$GH_ENTERPRISE" ]; then |
| 41 | + elif [ -n "$GH_ENTERPRISE" ]; then |
20 | 42 | readonly RUNNER_URL="${_GH_URL}/${GH_ENTERPRISE}"
|
21 | 43 | readonly RUNNER_REG_TOKEN_URL="${_GH_API_ENDPOINT}/enterprises/${GH_ENTERPRISEs}/actions/runners/registration-token"
|
22 | 44 | else
|
|
30 | 52 | # access details
|
31 | 53 | if [ ! -z "$RUNNER_TOKEN" ]; then
|
32 | 54 | readonly REG_TOKEN=$RUNNER_TOKEN
|
33 |
| -elif [ ! -z $GH_ACCESS_TOKEN ]; then |
| 55 | + elif [ ! -z $GH_ACCESS_TOKEN ]; then |
34 | 56 | readonly REG_TOKEN=$(curl -s -X POST -H "Accept: application/vnd.github.v3+json" -H "Authorization: token $GH_ACCESS_TOKEN" $RUNNER_REG_TOKEN_URL | jq .token --raw-output)
|
35 | 57 | else
|
36 | 58 | echo "Please provide one of the Environment Variables:"
|
|
40 | 62 |
|
41 | 63 | if [ -z ${RUNNER_HOME} ]; then
|
42 | 64 | echo "Environment variable 'RUNNER_HOME' is not set"
|
43 |
| - exit 1 |
| 65 | + exit 255 |
44 | 66 | fi
|
45 | 67 |
|
46 | 68 | if [ "$KANIKO_ENABLED" == "true" ]; then
|
47 | 69 | readonly GH_WORKDIR=$GH_KANIKO_WORKDIR
|
48 |
| - echo "Build container via Kaniko: enabled" |
| 70 | + echo "Build container via Kaniko: enabled" |
49 | 71 | GH_RUNNER_LABELS="${GH_RUNNER_LABELS},kaniko"
|
50 | 72 | else
|
51 | 73 | readonly GH_WORKDIR=$GH_RUNNER_WORKDIR
|
52 |
| - echo "Build container via Kaniko: disabled" |
| 74 | + echo "Build container via Kaniko: disabled" |
53 | 75 | fi
|
54 | 76 |
|
55 |
| -echo "Connecting runner to: $RUNNER_URL" |
56 |
| -echo "Individual Runner Name: $HOSTNAME" |
57 |
| -echo "Runner Home: $RUNNER_HOME" |
| 77 | +echo "Connecting runner to: $RUNNER_URL" |
| 78 | +echo "Individual Runner Name: $HOSTNAME" |
| 79 | +echo "Runner Home: $RUNNER_HOME" |
| 80 | +echo "" |
| 81 | + |
| 82 | +# proxy support |
| 83 | +if [ -n "$PROXY_PAC" ]; then |
| 84 | + echo "Using configured Proxy PAC" |
| 85 | + if [ ! -n "$PROXY_NTLM_CREDENTIALS" ]; then |
| 86 | + echo "Please provide the Environment Variable 'PROXY_NTLM_CREDENTIALS'" |
| 87 | + exit 255 |
| 88 | + fi |
| 89 | + NTLM_CREDENTIALS="$PROXY_NTLM_CREDENTIALS" alpaca -C "$PROXY_PAC" >/dev/null 2>&1 & |
| 90 | + unset PROXY_NTLM_CREDENTIALS |
| 91 | + echo $! >/tmp/proxy_pid |
| 92 | +fi |
58 | 93 |
|
59 |
| -echo "Running setup fpr installed software..." |
| 94 | +echo "" |
| 95 | +echo "Running setup for installed software..." |
60 | 96 | /helper-scripts/detect-setup.sh
|
61 | 97 |
|
| 98 | +echo "configure GitHub runner" |
62 | 99 | ${RUNNER_HOME}/config.sh \
|
63 |
| - --name $HOSTNAME \ |
64 |
| - --token $REG_TOKEN \ |
65 |
| - --work $GH_WORKDIR \ |
66 |
| - --url "$RUNNER_URL" \ |
67 |
| - --labels $GH_RUNNER_LABELS \ |
68 |
| - --unattended \ |
69 |
| - --replace |
70 |
| -echo "Runner configured" |
| 100 | +--name $HOSTNAME \ |
| 101 | +--token $REG_TOKEN \ |
| 102 | +--work $GH_WORKDIR \ |
| 103 | +--url "$RUNNER_URL" \ |
| 104 | +--labels $GH_RUNNER_LABELS \ |
| 105 | +--runnergroup ${GH_RUNNER_GROUP:-'default'} \ |
| 106 | +--unattended \ |
| 107 | +--replace |
| 108 | +echo "GitHub runner configured" |
71 | 109 |
|
72 | 110 | cleanup() {
|
73 | 111 | echo "Removing runner..."
|
74 | 112 | if [ ! -z "$RUNNER_TOKEN" ]; then
|
75 |
| - readonly REG_TOKEN=$RUNNER_TOKEN |
76 |
| - elif [ ! -z $GH_ACCESS_TOKEN ]; then |
77 |
| - readonly REG_TOKEN=$(curl -s -X POST -H "Accept: application/vnd.github.v3+json" -H "Authorization: token $GH_ACCESS_TOKEN" $RUNNER_REG_TOKEN_URL | jq .token --raw-output) |
| 113 | + readonly REG_TOKEN_RM=$RUNNER_TOKEN |
| 114 | + elif [ ! -z $GH_ACCESS_TOKEN ]; then |
| 115 | + readonly REG_TOKEN_RM=$(curl -s -X POST -H "Accept: application/vnd.github.v3+json" -H "Authorization: token $GH_ACCESS_TOKEN" $RUNNER_REG_TOKEN_URL | jq .token --raw-output) |
78 | 116 | fi
|
79 |
| - ${RUNNER_HOME}/config.sh remove --token ${REG_TOKEN} |
| 117 | + ${RUNNER_HOME}/config.sh remove --token ${REG_TOKEN_RM} |
80 | 118 | exit 1
|
81 | 119 | }
|
82 | 120 |
|
|
0 commit comments