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

@@ -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')

View File

@@ -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