diff --git a/.gitignore b/.gitignore index bdabbc69..3785f0ef 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,6 @@ bin *.swp *.swo *~ + +.envrc +*.pem diff --git a/Makefile b/Makefile index 6db47917..5a5fcc18 100644 --- a/Makefile +++ b/Makefile @@ -118,6 +118,29 @@ release: manifests mkdir -p release kustomize build config/default > release/actions-runner-controller.yaml +.PHONY: acceptance +acceptance: release + ACCEPTANCE_TEST_SECRET_TYPE=token make acceptance/setup acceptance/tests acceptance/teardown + ACCEPTANCE_TEST_SECRET_TYPE=app make acceptance/setup acceptance/tests acceptance/teardown + +acceptance/setup: + kind create cluster --name acceptance + kubectl cluster-info --context kind-acceptance + kubectl apply --validate=false -f https://github.com/jetstack/cert-manager/releases/download/v1.0.4/cert-manager.yaml #kubectl create namespace actions-runner-system + kubectl -n cert-manager wait deploy/cert-manager-cainjector --for condition=available --timeout 60s + kubectl -n cert-manager wait deploy/cert-manager-webhook --for condition=available --timeout 60s + kubectl -n cert-manager wait deploy/cert-manager --for condition=available --timeout 60s + kubectl create namespace actions-runner-system + # Adhocly wait for some time until cert-manager's admission webhook gets ready + sleep 5 + +acceptance/teardown: + kind delete cluster --name acceptance + +acceptance/tests: + acceptance/deploy.sh + acceptance/checks.sh + # Upload release file to GitHub. github-release: release ghr ${VERSION} release/ diff --git a/README.md b/README.md index d9c30609..d72cf702 100644 --- a/README.md +++ b/README.md @@ -446,6 +446,28 @@ Your base64'ed PAT token has a new line at the end, it needs to be created witho * `echo -n $TOKEN | base64` * Create the secret as described in the docs using the shell and documeneted flags +# Developing + +If you'd like to modify the controller to fork or contribute, I'd suggest using the following snippet for running +the acceptance test: + +```shell +NAME=$DOCKER_USER/actions-runner-controller VERSION=dev \ + GITHUB_TOKEN=*** \ + APP_ID=*** \ + PRIVATE_KEY_FILE_PATH=path/to/pem/file \ + INSTALLATION_ID=*** \ + make docker-build docker-push acceptance +``` + +Please follow the instructions explained in [Using Personal Access Token](#using-personal-access-token) to obtain +`GITHUB_TOKEN`, and those in [Using GitHub App](#using-github-app) to obtain `APP_ID`, `INSTALLATION_ID`, and +`PRIAVTE_KEY_FILE_PATH`. + +The test creates a one-off `kind` cluster, deploys `cert-manager` and `actions-runner-controller`, +creates a `RunnerDeployment` custom resource for a public Git repository to confirm that the +controller is able to bring up a runner pod with the actions runner registration token installed. + # Alternatives The following is a list of alternative solutions that may better fit you depending on your use-case: diff --git a/acceptance/checks.sh b/acceptance/checks.sh new file mode 100755 index 00000000..b8bc704d --- /dev/null +++ b/acceptance/checks.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +set -e + +runner_name= + +while [ -z "${runner_name}" ]; do + echo Finding the runner... 1>&2 + sleep 1 + runner_name=$(kubectl get runner --output=jsonpath="{.items[*].metadata.name}") +done + +echo Found runner ${runner_name}. + +pod_name= + +while [ -z "${pod_name}" ]; do + echo Finding the runner pod... 1>&2 + sleep 1 + pod_name=$(kubectl get pod --output=jsonpath="{.items[*].metadata.name}" | grep ${runner_name}) +done + +echo Found pod ${pod_name}. + +echo Waiting for pod ${runner_name} to become ready... 1>&2 + +kubectl wait pod/${runner_name} --for condition=ready --timeout 120s + +echo All tests passed. 1>&2 diff --git a/acceptance/deploy.sh b/acceptance/deploy.sh new file mode 100755 index 00000000..200d656b --- /dev/null +++ b/acceptance/deploy.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +set -e + +tpe=${ACCEPTANCE_TEST_SECRET_TYPE} + +if [ "${tpe}" == "token" ]; then + kubectl create secret generic controller-manager \ + -n actions-runner-system \ + --from-literal=github_token=${GITHUB_TOKEN:?GITHUB_TOKEN must not be empty} +elif [ "${tpe}" == "app" ]; then + kubectl create secret generic controller-manager \ + -n actions-runner-system \ + --from-literal=github_app_id=${APP_ID:?must not be empty} \ + --from-literal=github_app_installation_id=${INSTALLATION_ID:?must not be empty} \ + --from-file=github_app_private_key=${PRIVATE_KEY_FILE_PATH:?must not be empty} +else + echo "ACCEPTANCE_TEST_SECRET_TYPE must be set to either \"token\" or \"app\"" 1>&2 + exit 1 +fi + +kubectl apply \ + -n actions-runner-system \ + -f release/actions-runner-controller.yaml + +kubectl -n actions-runner-system wait deploy/controller-manager --for condition=available + +# Adhocly wait for some time until actions-runner-controller's admission webhook gets ready +sleep 20 + +kubectl apply \ + -f acceptance/testdata/runnerdeploy.yaml diff --git a/acceptance/testdata/runnerdeploy.yaml b/acceptance/testdata/runnerdeploy.yaml new file mode 100644 index 00000000..684a2725 --- /dev/null +++ b/acceptance/testdata/runnerdeploy.yaml @@ -0,0 +1,9 @@ +apiVersion: actions.summerwind.dev/v1alpha1 +kind: RunnerDeployment +metadata: + name: example-runnerdeploy +spec: + replicas: 1 + template: + spec: + repository: mumoshu/actions-runner-controller-ci