Skip to content

Commit

Permalink
breaking: Allow to use legacy configuration for container app (#34)
Browse files Browse the repository at this point in the history
* docs updated

* re-edit to allow legacy configuration of container app

* added versions print and updated to runner 2.315
  • Loading branch information
diegolagospagopa authored Apr 9, 2024
1 parent 707d714 commit 3878cb4
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 20 deletions.
14 changes: 13 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM ghcr.io/actions/actions-runner:2.314.1 AS base
FROM ghcr.io/actions/actions-runner:2.315.0 AS base

USER root

RUN apt-get update \
&& apt-get -y install curl git \
&& apt-get install -y curl jq \
Expand Down Expand Up @@ -50,6 +52,16 @@ RUN apt-get update \
FROM deps-node AS final
COPY ./github-runner-entrypoint.sh ./entrypoint.sh
RUN chmod +x ./entrypoint.sh

USER runner

RUN whoami \
&& echo "az cli: $(az version)" \
&& echo "kubectl client: $(kubectl version --client -o yaml)" \
&& echo "kubelogin client: $(kubelogin --version)" \
&& echo "helm: $(helm version)" \
&& echo "yq: $(yq --version)" \
&& echo "node: $(node --version)" \
&& echo "npm: $(npm --version)"

ENTRYPOINT ["./entrypoint.sh"]
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ Every time you want to update the runner you have to do the following:
* run a local build

* Push your code and be sure that the action `beta-docker-branch` runs correctly

## Github agent configuration

You can find all the configurations flags use by `config.sh` in this pages:

* <https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/autoscaling-with-self-hosted-runners>
* <https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners>
109 changes: 90 additions & 19 deletions github-runner-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,92 @@
#!/usr/bin/env bash

# Retrieve a short lived runner registration token using the PAT
REGISTRATION_TOKEN="$(curl -X POST -fsSL \
-H 'Accept: application/vnd.github.v3+json' \
-H "Authorization: Bearer $GITHUB_PAT" \
-H 'X-GitHub-Api-Version: 2022-11-28' \
"$REGISTRATION_TOKEN_API_URL" \
| jq -r '.token')"

./config.sh \
--url $REPO_URL \
--token $REGISTRATION_TOKEN \
--unattended \
--disableupdate \
--ephemeral \
--replace \
&& ./run.sh

export GITHUB_PAT=_REDACTED_
export REGISTRATION_TOKEN=_REDACTED_
INTERACTIVE="FALSE"

# Verify some Repo URL and token have been given, otherwise we must be interactive mode.
if [ -n "$GITHUB_REPOSITORY" ] && [ -n "$GITHUB_TOKEN" ]; then

#
# Legacy Container app configuration, with create and destroy agent
#
echo "🌊 start agent configuration"

if [ "$(echo "$INTERACTIVE_MODE" | tr '[:upper:]' '[:lower:]')" == "true" ]; then
INTERACTIVE="TRUE"
fi

# Calculate default configuration values.
GITHUB_REPOSITORY_BANNER="$GITHUB_REPOSITORY"
if [ -z "$GITHUB_REPOSITORY_BANNER" ]; then
export GITHUB_REPOSITORY_BANNER="<empty repository url>"
fi

if [ -z "$RUNNER_NAME" ]; then
RUNNER_NAME="$(hostname)"
export RUNNER_NAME
fi

if [ -z "$WORK_DIR" ]; then
export WORK_DIR=".workdir"
fi

# Calculate runner replacement policy.
REPLACEMENT_POLICY="\n\n\n"
REPLACEMENT_POLICY_LABEL="FALSE"
if [ "$(echo "$REPLACE_EXISTING_RUNNER" | tr '[:upper:]' '[:lower:]')" == "true" ]; then
REPLACEMENT_POLICY="Y\n\n"
REPLACEMENT_POLICY_LABEL="TRUE"
fi

# Configure runner interactively, or with the given replacement policy.
printf "ℹ️ Configuring GitHub Runner for %s\n\t" "$GITHUB_REPOSITORY_BANNER"
printf "ℹ️ Runner Name: %s\n\t" "$RUNNER_NAME"
printf "ℹ️ Working Directory: %s\n\t" "$WORK_DIR"
printf "ℹ️ Replace Existing Runners: %s\n" "$REPLACEMENT_POLICY_LABEL"

# actions-runner is a folder inside the github runner zip
if [ "$INTERACTIVE" == "FALSE" ]; then
echo -ne "$REPLACEMENT_POLICY" | ./config.sh --url "$GITHUB_REPOSITORY" --token "$GITHUB_TOKEN" --name "$RUNNER_NAME" --work "$WORK_DIR" --labels "$LABELS" --disableupdate
else
#<https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners>
./config.sh \
--url "$GITHUB_REPOSITORY" \
--token "$GITHUB_TOKEN" \
--name "$RUNNER_NAME" \
--work "$WORK_DIR" \
--labels "$LABELS" \
--disableupdate
echo "✅ config.sh launched"
fi

# Start the runner.
./run.sh
echo "🚀 Executing GitHub Runner for $GITHUB_REPOSITORY"

else

#
# JOB Container app configuration
#

# Retrieve a short lived runner registration token using the PAT
REGISTRATION_TOKEN="$(curl -X POST -fsSL \
-H 'Accept: application/vnd.github.v3+json' \
-H "Authorization: Bearer $GITHUB_PAT" \
-H 'X-GitHub-Api-Version: 2022-11-28' \
"$REGISTRATION_TOKEN_API_URL" \
| jq -r '.token')"

#<https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners>
./config.sh \
--url "${REPO_URL}" \
--token "${REGISTRATION_TOKEN}" \
--unattended \
--disableupdate \
--ephemeral \
--replace \
&& ./run.sh

export GITHUB_PAT=_REDACTED_
export REGISTRATION_TOKEN=_REDACTED_

fi

0 comments on commit 3878cb4

Please sign in to comment.