diff --git a/Dockerfile b/Dockerfile index 22d5bbb..896111b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 \ @@ -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"] diff --git a/README.md b/README.md index 822070b..5b3bc7b 100644 --- a/README.md +++ b/README.md @@ -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: + +* +* diff --git a/github-runner-entrypoint.sh b/github-runner-entrypoint.sh index a6e757b..a4c3ebb 100644 --- a/github-runner-entrypoint.sh +++ b/github-runner-entrypoint.sh @@ -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="" + 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 + # + ./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')" + + # + ./config.sh \ + --url "${REPO_URL}" \ + --token "${REGISTRATION_TOKEN}" \ + --unattended \ + --disableupdate \ + --ephemeral \ + --replace \ + && ./run.sh + + export GITHUB_PAT=_REDACTED_ + export REGISTRATION_TOKEN=_REDACTED_ + +fi