From ad48851dc93c956080a5b4e7d7c3f29a66b50909 Mon Sep 17 00:00:00 2001 From: Callum Tait <15716903+toast-gear@users.noreply.github.com> Date: Wed, 29 Dec 2021 01:23:35 +0000 Subject: [PATCH] feat: expose if docker is enabled and wait for docker to be ready (#962) Resolves #897 Resolves #915 --- CONTRIBUTING.md | 5 ++++- Makefile | 3 ++- README.md | 24 ++++++++++++++++++++++++ controllers/runner_controller.go | 6 ++++++ runner/Dockerfile | 2 +- runner/Dockerfile.dindrunner | 2 +- runner/Makefile | 17 +++++++++-------- runner/entrypoint.sh | 7 +++++++ 8 files changed, 54 insertions(+), 12 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ceabc038..c19d350c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -95,6 +95,7 @@ To make your development cycle faster, use the below command to update deploy an # you either need to bump VERSION and RUNNER_TAG on each run, # or manually run `kubectl delete pod $POD` on respective pods for changes to actually take effect. +# Makefile VERSION=controller1 \ RUNNER_TAG=runner1 \ make acceptance/pull acceptance/kind docker-build acceptance/load acceptance/deploy @@ -103,14 +104,16 @@ VERSION=controller1 \ If you've already deployed actions-runner-controller and only want to recreate pods to use the newer image, you can run: ```shell +# Makefile NAME=$DOCKER_USER/actions-runner-controller \ make docker-build acceptance/load && \ kubectl -n actions-runner-system delete po $(kubectl -n actions-runner-system get po -ojsonpath={.items[*].metadata.name}) ``` -Similarly, if you'd like to recreate runner pods with the newer runner image, +Similarly, if you'd like to recreate runner pods with the newer runner image you can use the runner specific [Makefile](runner/Makefile) to build and / or push new runner images ```shell +# runner/Makefile NAME=$DOCKER_USER/actions-runner make \ -C runner docker-{build,push}-ubuntu && \ (kubectl get po -ojsonpath={.items[*].metadata.name} | xargs -n1 kubectl delete po) diff --git a/Makefile b/Makefile index 624bd25e..6ab49fb4 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ else endif DOCKER_USER ?= $(shell echo ${NAME} | cut -d / -f1) VERSION ?= latest +TARGETPLATFORM ?= $(shell arch) RUNNER_NAME ?= ${DOCKER_USER}/actions-runner RUNNER_TAG ?= ${VERSION} TEST_REPO ?= ${DOCKER_USER}/actions-runner-controller @@ -111,7 +112,7 @@ generate: controller-gen # Build the docker image docker-build: docker build -t ${NAME}:${VERSION} . - docker build -t ${RUNNER_NAME}:${RUNNER_TAG} --build-arg TARGETPLATFORM=$(shell arch) runner + docker build -t ${RUNNER_NAME}:${RUNNER_TAG} --build-arg TARGETPLATFORM=${TARGETPLATFORM} runner docker-buildx: export DOCKER_CLI_EXPERIMENTAL=enabled diff --git a/README.md b/README.md index 5022e096..b8dfa9bf 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ ToC: - [Additional Tweaks](#additional-tweaks) - [Runner Labels](#runner-labels) - [Runner Groups](#runner-groups) + - [Runner Entrypoint Features](#runner-entrypoint-features) - [Using IRSA (IAM Roles for Service Accounts) in EKS](#using-irsa-iam-roles-for-service-accounts-in-eks) - [Stateful Runners](#stateful-runners) - [Ephemeral Runners](#ephemeral-runners) @@ -1044,6 +1045,29 @@ spec: group: NewGroup ``` +### Runner Entrypoint Features + +> Environment variable values must all be strings + +The entrypoint script is aware of a few environment variables for configuring features: + +```yaml +apiVersion: actions.summerwind.dev/v1alpha1 +kind: RunnerDeployment +metadata: + name: example-runnerdeployment +spec: + template: + spec: + env: + # Issues a sleep command at the start of the entrypoint + - name: STARTUP_DELAY_IN_SECONDS + value: "2" + # Disables the wait for the docker daemon to be available check + - name: DISABLE_WAIT_FOR_DOCKER + value: "true" +``` + ### Using IRSA (IAM Roles for Service Accounts) in EKS > This feature requires controller version => [v0.15.0](https://github.com/actions-runner-controller/actions-runner-controller/releases/tag/v0.15.0) diff --git a/controllers/runner_controller.go b/controllers/runner_controller.go index cd379432..d22e89ae 100644 --- a/controllers/runner_controller.go +++ b/controllers/runner_controller.go @@ -782,6 +782,8 @@ func newRunnerPod(template corev1.Pod, runnerSpec v1alpha1.RunnerConfig, default dockerRegistryMirror = *runnerSpec.DockerRegistryMirror } + // Be aware some of the environment variables are used + // in the runner entrypoint script env := []corev1.EnvVar{ { Name: EnvVarOrg, @@ -803,6 +805,10 @@ func newRunnerPod(template corev1.Pod, runnerSpec v1alpha1.RunnerConfig, default Name: "RUNNER_GROUP", Value: runnerSpec.Group, }, + { + Name: "DOCKER_ENABLED", + Value: fmt.Sprintf("%v", dockerEnabled || dockerdInRunner), + }, { Name: "DOCKERD_IN_RUNNER", Value: fmt.Sprintf("%v", dockerdInRunner), diff --git a/runner/Dockerfile b/runner/Dockerfile index 542f74d7..13daa5f0 100644 --- a/runner/Dockerfile +++ b/runner/Dockerfile @@ -1,7 +1,7 @@ FROM ubuntu:20.04 ARG TARGETPLATFORM -ARG RUNNER_VERSION=2.280.3 +ARG RUNNER_VERSION=2.286.0 ARG DOCKER_CHANNEL=stable ARG DOCKER_VERSION=20.10.8 ARG DUMB_INIT_VERSION=1.2.5 diff --git a/runner/Dockerfile.dindrunner b/runner/Dockerfile.dindrunner index 5dbd5efc..a893baf5 100644 --- a/runner/Dockerfile.dindrunner +++ b/runner/Dockerfile.dindrunner @@ -1,7 +1,7 @@ FROM ubuntu:20.04 ARG TARGETPLATFORM -ARG RUNNER_VERSION=2.280.3 +ARG RUNNER_VERSION=2.286.0 ARG DOCKER_CHANNEL=stable ARG DOCKER_VERSION=20.10.8 ARG DUMB_INIT_VERSION=1.2.5 diff --git a/runner/Makefile b/runner/Makefile index a0c90abb..c55e5630 100644 --- a/runner/Makefile +++ b/runner/Makefile @@ -1,9 +1,10 @@ -NAME ?= summerwind/actions-runner -DIND_RUNNER_NAME ?= ${NAME}-dind +DOCKER_USER ?= summerwind +NAME ?= ${DOCKER_USER}/actions-runner +DIND_RUNNER_NAME ?= ${DOCKER_USER}/actions-runner-dind TAG ?= latest -TARGET_PLATFORM ?= $(shell arch) +TARGETPLATFORM ?= $(shell arch) -RUNNER_VERSION ?= 2.280.3 +RUNNER_VERSION ?= 2.286.0 DOCKER_VERSION ?= 20.10.8 # default list of platforms for which multiarch image is built @@ -24,8 +25,8 @@ else endif docker-build-ubuntu: - docker build --build-arg TARGETPLATFORM=${TARGET_PLATFORM} --build-arg RUNNER_VERSION=${RUNNER_VERSION} --build-arg DOCKER_VERSION=${DOCKER_VERSION} -t ${NAME}:${TAG} . - docker build --build-arg TARGETPLATFORM=${TARGET_PLATFORM} --build-arg RUNNER_VERSION=${RUNNER_VERSION} --build-arg DOCKER_VERSION=${DOCKER_VERSION} -t ${DIND_RUNNER_NAME}:${TAG} -f Dockerfile.dindrunner . + docker build --build-arg TARGETPLATFORM=${TARGETPLATFORM} --build-arg RUNNER_VERSION=${RUNNER_VERSION} --build-arg DOCKER_VERSION=${DOCKER_VERSION} -t ${NAME}:${TAG} . + docker build --build-arg TARGETPLATFORM=${TARGETPLATFORM} --build-arg RUNNER_VERSION=${RUNNER_VERSION} --build-arg DOCKER_VERSION=${DOCKER_VERSION} -t ${DIND_RUNNER_NAME}:${TAG} -f Dockerfile.dindrunner . docker-push-ubuntu: docker push ${NAME}:${TAG} @@ -39,12 +40,12 @@ docker-buildx-ubuntu: docker buildx build --platform ${PLATFORMS} \ --build-arg RUNNER_VERSION=${RUNNER_VERSION} \ --build-arg DOCKER_VERSION=${DOCKER_VERSION} \ - -t "${NAME}:latest" \ + -t "${NAME}:${TAG}" \ -f Dockerfile \ . ${PUSH_ARG} docker buildx build --platform ${PLATFORMS} \ --build-arg RUNNER_VERSION=${RUNNER_VERSION} \ --build-arg DOCKER_VERSION=${DOCKER_VERSION} \ - -t "${DIND_RUNNER_NAME}:latest" \ + -t "${DIND_RUNNER_NAME}:${TAG}" \ -f Dockerfile.dindrunner \ . ${PUSH_ARG} diff --git a/runner/entrypoint.sh b/runner/entrypoint.sh index 9f94216b..3cdd987d 100755 --- a/runner/entrypoint.sh +++ b/runner/entrypoint.sh @@ -24,6 +24,13 @@ if [ ! -z "${STARTUP_DELAY_IN_SECONDS}" ]; then sleep ${STARTUP_DELAY_IN_SECONDS} fi +if [[ "${DISABLE_WAIT_FOR_DOCKER}" != "true" ]] && [[ "${DOCKER_ENABLED}" == "true" ]]; then + log "Docker enabled runner detected and Docker daemon wait is enabled" + log "Waiting until Docker is avaliable or the timeout is reached" + timeout 120s bash -c 'until docker ps ;do sleep 1; done' +else + log "Docker wait check skipped. Either Docker is disabled or the wait is disabled, continuing with entrypoint" +fi if [ -z "${GITHUB_URL}" ]; then log "Working with public GitHub"