From 3dc52b28affb77fb7b42da34135ce61a021d88e0 Mon Sep 17 00:00:00 2001 From: TingluoHuang Date: Sun, 30 Aug 2020 00:29:28 -0400 Subject: [PATCH] update dockerfile --- Dockerfile | 17 ++++++++----- src/Misc/download-runner.sh | 8 +++--- src/Misc/entrypoint.sh | 50 ++++++++++++++++++++++++------------- 3 files changed, 48 insertions(+), 27 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0a2a3faf7..e8735f34c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,14 @@ FROM mcr.microsoft.com/dotnet/core/runtime-deps:3.1-buster-slim +ENV RUNNER_CONFIG_URL="" ENV GITHUB_PAT="" -ENV GITHUB_RUNNER_SCOPE="" -ENV GITHUB_SERVER_URL="" -ENV GITHUB_API_URL="" -ENV K8S_HOST_IP="" +ENV RUNNER_NAME="" +ENV RUNNER_GROUP="" +ENV RUNNER_LABELS="" +# ENV GITHUB_RUNNER_SCOPE="" +# ENV GITHUB_SERVER_URL="" +# ENV GITHUB_API_URL="" +# ENV K8S_HOST_IP="" RUN apt-get update --fix-missing \ && apt-get install -y --no-install-recommends \ @@ -27,8 +31,6 @@ RUN curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add RUN curl -fsSL https://get.docker.com -o get-docker.sh RUN sh get-docker.sh -# Allow runner to run as root -ENV RUNNER_ALLOW_RUNASROOT=1 # Directory for runner to operate in RUN mkdir /actions-runner WORKDIR /actions-runner @@ -45,4 +47,7 @@ ENV _INTERNAL_JOBSTART_NOTIFICATION=/actions-runner/jobstart.sh ENV _INTERNAL_JOBRUNNING_NOTIFICATION=/actions-runner/jobrunning.sh ENV _INTERNAL_JOBCOMPLETE_NOTIFICATION=/actions-runner/jobcomplete.sh +# Allow runner to run as root +ENV RUNNER_ALLOW_RUNASROOT=1 + ENTRYPOINT ["./entrypoint.sh"] \ No newline at end of file diff --git a/src/Misc/download-runner.sh b/src/Misc/download-runner.sh index 4f5fff703..b7d4cb7c5 100755 --- a/src/Misc/download-runner.sh +++ b/src/Misc/download-runner.sh @@ -2,10 +2,10 @@ set -e # if the scope has a slash, it's a repo runner -orgs_or_repos="orgs" -if [[ "$GITHUB_RUNNER_SCOPE" == *\/* ]]; then - orgs_or_repos="repos" -fi +# orgs_or_repos="orgs" +# if [[ "$GITHUB_RUNNER_SCOPE" == *\/* ]]; then +# orgs_or_repos="repos" +# fi #RUNNER_DOWNLOAD_URL=$(curl -s -X GET ${GITHUB_API_URL}/${orgs_or_repos}/${GITHUB_RUNNER_SCOPE}/actions/runners/downloads -H "authorization: token $GITHUB_PAT" -H "accept: application/vnd.github.everest-preview+json" | jq -r '.[]|select(.os=="linux" and .architecture=="x64")|.download_url') diff --git a/src/Misc/entrypoint.sh b/src/Misc/entrypoint.sh index b1a2a2ccc..269bda23d 100755 --- a/src/Misc/entrypoint.sh +++ b/src/Misc/entrypoint.sh @@ -8,23 +8,25 @@ function fatal() { } [ -n "${GITHUB_PAT:-""}" ] || fatal "GITHUB_PAT variable must be set" -[ -n "${GITHUB_RUNNER_SCOPE:-""}" ] || fatal "GITHUB_RUNNER_SCOPE variable must be set" +[ -n "${RUNNER_CONFIG_URL:-""}" ] || fatal "RUNNER_CONFIG_URL variable must be set" -# Use container id to gen unique runner name -CONTAINER_ID=$(cat /proc/self/cgroup | head -n 1 | tr '/' '\n' | tail -1 | cut -c1-12) -RUNNER_NAME="actions-runner-k8s-${CONTAINER_ID}" - -# if the scope has a slash, it's a repo runner -orgs_or_repos="orgs" -if [[ "$GITHUB_RUNNER_SCOPE" == *\/* ]]; then - orgs_or_repos="repos" +if [ -n "${RUNNER_NAME}" ]; then + # Use container id to gen unique runner name if name not provide + CONTAINER_ID=$(cat /proc/self/cgroup | head -n 1 | tr '/' '\n' | tail -1 | cut -c1-12) + RUNNER_NAME="actions-runner-${CONTAINER_ID}" fi -RUNNER_REG_URL="${GITHUB_SERVER_URL:=https://github.com}/${GITHUB_RUNNER_SCOPE}" +# if the scope has a slash, it's a repo runner +# orgs_or_repos="orgs" +# if [[ "$GITHUB_RUNNER_SCOPE" == *\/* ]]; then +# orgs_or_repos="repos" +# fi + +# RUNNER_REG_URL="${GITHUB_SERVER_URL:=https://github.com}/${GITHUB_RUNNER_SCOPE}" echo "Runner Name : ${RUNNER_NAME}" -echo "Registration URL : ${RUNNER_REG_URL}" -echo "GitHub API URL : ${GITHUB_API_URL:=https://api.github.com}" +echo "Registration URL : ${RUNNER_CONFIG_URL}" +# echo "GitHub API URL : ${GITHUB_API_URL:=https://api.github.com}" echo "Runner Labels : ${RUNNER_LABELS:=""}" # TODO: if api url is not default, validate it ends in /api/v3 @@ -34,17 +36,22 @@ if [ -n "${RUNNER_LABELS}" ]; then RUNNER_LABELS_ARG="--labels ${RUNNER_LABELS}" fi -if [ -n "${K8S_HOST_IP}" ]; then - export http_proxy=http://$K8S_HOST_IP:9090 +RUNNER_GROUP_ARG="" +if [ -n "${RUNNER_GROUP}" ]; then + RUNNER_GROUP_ARG="--runnergroup ${RUNNER_GROUP}" fi -curl -v -s -X POST ${GITHUB_API_URL}/${orgs_or_repos}/${GITHUB_RUNNER_SCOPE}/actions/runners/registration-token -H "authorization: token $GITHUB_PAT" -H "accept: application/vnd.github.everest-preview+json" +# if [ -n "${K8S_HOST_IP}" ]; then +# export http_proxy=http://$K8S_HOST_IP:9090 +# fi + +# curl -v -s -X POST ${GITHUB_API_URL}/${orgs_or_repos}/${GITHUB_RUNNER_SCOPE}/actions/runners/registration-token -H "authorization: token $GITHUB_PAT" -H "accept: application/vnd.github.everest-preview+json" # Generate registration token -RUNNER_REG_TOKEN=$(curl -s -X POST ${GITHUB_API_URL}/${orgs_or_repos}/${GITHUB_RUNNER_SCOPE}/actions/runners/registration-token -H "authorization: token $GITHUB_PAT" -H "accept: application/vnd.github.everest-preview+json" | jq -r '.token') +# RUNNER_REG_TOKEN=$(curl -s -X POST ${GITHUB_API_URL}/${orgs_or_repos}/${GITHUB_RUNNER_SCOPE}/actions/runners/registration-token -H "authorization: token $GITHUB_PAT" -H "accept: application/vnd.github.everest-preview+json" | jq -r '.token') # Create the runner and configure it -./config.sh --unattended --name $RUNNER_NAME --url $RUNNER_REG_URL --token $RUNNER_REG_TOKEN $RUNNER_LABELS_ARG --replace --ephemeral +./config.sh --unattended --name $RUNNER_NAME --url $RUNNER_CONFIG_URL --pat $GITHUB_PAT $RUNNER_LABELS_ARG $RUNNER_GROUP_ARG --replace --ephemeral # while (! docker version ); do # # Docker takes a few seconds to initialize @@ -52,6 +59,15 @@ RUNNER_REG_TOKEN=$(curl -s -X POST ${GITHUB_API_URL}/${orgs_or_repos}/${GITHUB_R # sleep 1 # done +# unset env +unset RUNNER_CONFIG_URL +unset GITHUB_PAT +unset RUNNER_NAME +unset RUNNER_GROUP +unset RUNNER_LABELS +unset RUNNER_LABELS_ARG +unset RUNNER_GROUP_ARG + # Run it ./bin/runsvc.sh interactive