Skip to content

Commit 3878cb4

Browse files
breaking: Allow to use legacy configuration for container app (#34)
* docs updated * re-edit to allow legacy configuration of container app * added versions print and updated to runner 2.315
1 parent 707d714 commit 3878cb4

File tree

3 files changed

+110
-20
lines changed

3 files changed

+110
-20
lines changed

Dockerfile

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
FROM ghcr.io/actions/actions-runner:2.314.1 AS base
1+
FROM ghcr.io/actions/actions-runner:2.315.0 AS base
2+
23
USER root
4+
35
RUN apt-get update \
46
&& apt-get -y install curl git \
57
&& apt-get install -y curl jq \
@@ -50,6 +52,16 @@ RUN apt-get update \
5052
FROM deps-node AS final
5153
COPY ./github-runner-entrypoint.sh ./entrypoint.sh
5254
RUN chmod +x ./entrypoint.sh
55+
5356
USER runner
5457

58+
RUN whoami \
59+
&& echo "az cli: $(az version)" \
60+
&& echo "kubectl client: $(kubectl version --client -o yaml)" \
61+
&& echo "kubelogin client: $(kubelogin --version)" \
62+
&& echo "helm: $(helm version)" \
63+
&& echo "yq: $(yq --version)" \
64+
&& echo "node: $(node --version)" \
65+
&& echo "npm: $(npm --version)"
66+
5567
ENTRYPOINT ["./entrypoint.sh"]

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@ Every time you want to update the runner you have to do the following:
1414
* run a local build
1515

1616
* Push your code and be sure that the action `beta-docker-branch` runs correctly
17+
18+
## Github agent configuration
19+
20+
You can find all the configurations flags use by `config.sh` in this pages:
21+
22+
* <https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/autoscaling-with-self-hosted-runners>
23+
* <https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners>

github-runner-entrypoint.sh

+90-19
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,92 @@
11
#!/usr/bin/env bash
22

3-
# Retrieve a short lived runner registration token using the PAT
4-
REGISTRATION_TOKEN="$(curl -X POST -fsSL \
5-
-H 'Accept: application/vnd.github.v3+json' \
6-
-H "Authorization: Bearer $GITHUB_PAT" \
7-
-H 'X-GitHub-Api-Version: 2022-11-28' \
8-
"$REGISTRATION_TOKEN_API_URL" \
9-
| jq -r '.token')"
10-
11-
./config.sh \
12-
--url $REPO_URL \
13-
--token $REGISTRATION_TOKEN \
14-
--unattended \
15-
--disableupdate \
16-
--ephemeral \
17-
--replace \
18-
&& ./run.sh
19-
20-
export GITHUB_PAT=_REDACTED_
21-
export REGISTRATION_TOKEN=_REDACTED_
3+
INTERACTIVE="FALSE"
4+
5+
# Verify some Repo URL and token have been given, otherwise we must be interactive mode.
6+
if [ -n "$GITHUB_REPOSITORY" ] && [ -n "$GITHUB_TOKEN" ]; then
7+
8+
#
9+
# Legacy Container app configuration, with create and destroy agent
10+
#
11+
echo "🌊 start agent configuration"
12+
13+
if [ "$(echo "$INTERACTIVE_MODE" | tr '[:upper:]' '[:lower:]')" == "true" ]; then
14+
INTERACTIVE="TRUE"
15+
fi
16+
17+
# Calculate default configuration values.
18+
GITHUB_REPOSITORY_BANNER="$GITHUB_REPOSITORY"
19+
if [ -z "$GITHUB_REPOSITORY_BANNER" ]; then
20+
export GITHUB_REPOSITORY_BANNER="<empty repository url>"
21+
fi
22+
23+
if [ -z "$RUNNER_NAME" ]; then
24+
RUNNER_NAME="$(hostname)"
25+
export RUNNER_NAME
26+
fi
27+
28+
if [ -z "$WORK_DIR" ]; then
29+
export WORK_DIR=".workdir"
30+
fi
31+
32+
# Calculate runner replacement policy.
33+
REPLACEMENT_POLICY="\n\n\n"
34+
REPLACEMENT_POLICY_LABEL="FALSE"
35+
if [ "$(echo "$REPLACE_EXISTING_RUNNER" | tr '[:upper:]' '[:lower:]')" == "true" ]; then
36+
REPLACEMENT_POLICY="Y\n\n"
37+
REPLACEMENT_POLICY_LABEL="TRUE"
38+
fi
39+
40+
# Configure runner interactively, or with the given replacement policy.
41+
printf "ℹ️ Configuring GitHub Runner for %s\n\t" "$GITHUB_REPOSITORY_BANNER"
42+
printf "ℹ️ Runner Name: %s\n\t" "$RUNNER_NAME"
43+
printf "ℹ️ Working Directory: %s\n\t" "$WORK_DIR"
44+
printf "ℹ️ Replace Existing Runners: %s\n" "$REPLACEMENT_POLICY_LABEL"
45+
46+
# actions-runner is a folder inside the github runner zip
47+
if [ "$INTERACTIVE" == "FALSE" ]; then
48+
echo -ne "$REPLACEMENT_POLICY" | ./config.sh --url "$GITHUB_REPOSITORY" --token "$GITHUB_TOKEN" --name "$RUNNER_NAME" --work "$WORK_DIR" --labels "$LABELS" --disableupdate
49+
else
50+
#<https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners>
51+
./config.sh \
52+
--url "$GITHUB_REPOSITORY" \
53+
--token "$GITHUB_TOKEN" \
54+
--name "$RUNNER_NAME" \
55+
--work "$WORK_DIR" \
56+
--labels "$LABELS" \
57+
--disableupdate
58+
echo "✅ config.sh launched"
59+
fi
60+
61+
# Start the runner.
62+
./run.sh
63+
echo "🚀 Executing GitHub Runner for $GITHUB_REPOSITORY"
64+
65+
else
66+
67+
#
68+
# JOB Container app configuration
69+
#
70+
71+
# Retrieve a short lived runner registration token using the PAT
72+
REGISTRATION_TOKEN="$(curl -X POST -fsSL \
73+
-H 'Accept: application/vnd.github.v3+json' \
74+
-H "Authorization: Bearer $GITHUB_PAT" \
75+
-H 'X-GitHub-Api-Version: 2022-11-28' \
76+
"$REGISTRATION_TOKEN_API_URL" \
77+
| jq -r '.token')"
78+
79+
#<https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners>
80+
./config.sh \
81+
--url "${REPO_URL}" \
82+
--token "${REGISTRATION_TOKEN}" \
83+
--unattended \
84+
--disableupdate \
85+
--ephemeral \
86+
--replace \
87+
&& ./run.sh
88+
89+
export GITHUB_PAT=_REDACTED_
90+
export REGISTRATION_TOKEN=_REDACTED_
91+
92+
fi

0 commit comments

Comments
 (0)