update dockerfile

This commit is contained in:
TingluoHuang
2020-08-30 00:29:28 -04:00
parent 993edc3172
commit 3dc52b28af
3 changed files with 48 additions and 27 deletions

View File

@@ -1,10 +1,14 @@
FROM mcr.microsoft.com/dotnet/core/runtime-deps:3.1-buster-slim FROM mcr.microsoft.com/dotnet/core/runtime-deps:3.1-buster-slim
ENV RUNNER_CONFIG_URL=""
ENV GITHUB_PAT="" ENV GITHUB_PAT=""
ENV GITHUB_RUNNER_SCOPE="" ENV RUNNER_NAME=""
ENV GITHUB_SERVER_URL="" ENV RUNNER_GROUP=""
ENV GITHUB_API_URL="" ENV RUNNER_LABELS=""
ENV K8S_HOST_IP="" # ENV GITHUB_RUNNER_SCOPE=""
# ENV GITHUB_SERVER_URL=""
# ENV GITHUB_API_URL=""
# ENV K8S_HOST_IP=""
RUN apt-get update --fix-missing \ RUN apt-get update --fix-missing \
&& apt-get install -y --no-install-recommends \ && 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 curl -fsSL https://get.docker.com -o get-docker.sh
RUN sh 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 # Directory for runner to operate in
RUN mkdir /actions-runner RUN mkdir /actions-runner
WORKDIR /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_JOBRUNNING_NOTIFICATION=/actions-runner/jobrunning.sh
ENV _INTERNAL_JOBCOMPLETE_NOTIFICATION=/actions-runner/jobcomplete.sh ENV _INTERNAL_JOBCOMPLETE_NOTIFICATION=/actions-runner/jobcomplete.sh
# Allow runner to run as root
ENV RUNNER_ALLOW_RUNASROOT=1
ENTRYPOINT ["./entrypoint.sh"] ENTRYPOINT ["./entrypoint.sh"]

View File

@@ -2,10 +2,10 @@
set -e set -e
# if the scope has a slash, it's a repo runner # if the scope has a slash, it's a repo runner
orgs_or_repos="orgs" # orgs_or_repos="orgs"
if [[ "$GITHUB_RUNNER_SCOPE" == *\/* ]]; then # if [[ "$GITHUB_RUNNER_SCOPE" == *\/* ]]; then
orgs_or_repos="repos" # orgs_or_repos="repos"
fi # 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') #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')

View File

@@ -8,23 +8,25 @@ function fatal() {
} }
[ -n "${GITHUB_PAT:-""}" ] || fatal "GITHUB_PAT variable must be set" [ -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 if [ -n "${RUNNER_NAME}" ]; then
CONTAINER_ID=$(cat /proc/self/cgroup | head -n 1 | tr '/' '\n' | tail -1 | cut -c1-12) # Use container id to gen unique runner name if name not provide
RUNNER_NAME="actions-runner-k8s-${CONTAINER_ID}" CONTAINER_ID=$(cat /proc/self/cgroup | head -n 1 | tr '/' '\n' | tail -1 | cut -c1-12)
RUNNER_NAME="actions-runner-${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"
fi 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 "Runner Name : ${RUNNER_NAME}"
echo "Registration URL : ${RUNNER_REG_URL}" echo "Registration URL : ${RUNNER_CONFIG_URL}"
echo "GitHub API URL : ${GITHUB_API_URL:=https://api.github.com}" # echo "GitHub API URL : ${GITHUB_API_URL:=https://api.github.com}"
echo "Runner Labels : ${RUNNER_LABELS:=""}" echo "Runner Labels : ${RUNNER_LABELS:=""}"
# TODO: if api url is not default, validate it ends in /api/v3 # 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}" RUNNER_LABELS_ARG="--labels ${RUNNER_LABELS}"
fi fi
if [ -n "${K8S_HOST_IP}" ]; then RUNNER_GROUP_ARG=""
export http_proxy=http://$K8S_HOST_IP:9090 if [ -n "${RUNNER_GROUP}" ]; then
RUNNER_GROUP_ARG="--runnergroup ${RUNNER_GROUP}"
fi 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 # 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 # 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 # while (! docker version ); do
# # Docker takes a few seconds to initialize # # 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 # sleep 1
# done # 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 # Run it
./bin/runsvc.sh interactive ./bin/runsvc.sh interactive