From ee8fb5a3886ef5a75df5c126bcd3c846e13c801e Mon Sep 17 00:00:00 2001 From: Reinier Timmer Date: Wed, 25 Nov 2020 00:55:26 +0100 Subject: [PATCH] parametrized working directory (#185) * parametrized working directory * manifests v3.0 --- README.md | 4 ++++ api/v1alpha1/runner_types.go | 2 ++ .../actions.summerwind.dev_runnerdeployments.yaml | 2 ++ .../actions.summerwind.dev_runnerreplicasets.yaml | 2 ++ .../crds/actions.summerwind.dev_runners.yaml | 2 ++ .../actions.summerwind.dev_runnerdeployments.yaml | 2 ++ .../actions.summerwind.dev_runnerreplicasets.yaml | 2 ++ .../crd/bases/actions.summerwind.dev_runners.yaml | 2 ++ controllers/runner_controller.go | 13 +++++++++++-- runner/entrypoint.sh | 6 +++++- 10 files changed, 34 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4d2d86b3..058ff3be 100644 --- a/README.md +++ b/README.md @@ -342,6 +342,10 @@ spec: value: abcd1234 securityContext: runAsUser: 0 + # if workDir is not specified, the default working directory is /runner/_work + # this setting allows you to customize the working directory location + # for example, the below setting is the same as on the ubuntu-18.04 image + workDir: /home/runner/work ``` ## Runner labels diff --git a/api/v1alpha1/runner_types.go b/api/v1alpha1/runner_types.go index 8d77fa6d..8e29f990 100644 --- a/api/v1alpha1/runner_types.go +++ b/api/v1alpha1/runner_types.go @@ -59,6 +59,8 @@ type RunnerSpec struct { // +optional Volumes []corev1.Volume `json:"volumes,omitempty"` + // +optional + WorkDir string `json:"workDir,omitempty"` // +optional InitContainers []corev1.Container `json:"initContainers,omitempty"` diff --git a/charts/actions-runner-controller/crds/actions.summerwind.dev_runnerdeployments.yaml b/charts/actions-runner-controller/crds/actions.summerwind.dev_runnerdeployments.yaml index 2e6e03e7..b867989f 100644 --- a/charts/actions-runner-controller/crds/actions.summerwind.dev_runnerdeployments.yaml +++ b/charts/actions-runner-controller/crds/actions.summerwind.dev_runnerdeployments.yaml @@ -1533,6 +1533,8 @@ spec: - name type: object type: array + workDir: + type: string type: object type: object required: diff --git a/charts/actions-runner-controller/crds/actions.summerwind.dev_runnerreplicasets.yaml b/charts/actions-runner-controller/crds/actions.summerwind.dev_runnerreplicasets.yaml index 0cc21cdb..261685e5 100644 --- a/charts/actions-runner-controller/crds/actions.summerwind.dev_runnerreplicasets.yaml +++ b/charts/actions-runner-controller/crds/actions.summerwind.dev_runnerreplicasets.yaml @@ -1533,6 +1533,8 @@ spec: - name type: object type: array + workDir: + type: string type: object type: object required: diff --git a/charts/actions-runner-controller/crds/actions.summerwind.dev_runners.yaml b/charts/actions-runner-controller/crds/actions.summerwind.dev_runners.yaml index 5f8da46e..ee2aa441 100644 --- a/charts/actions-runner-controller/crds/actions.summerwind.dev_runners.yaml +++ b/charts/actions-runner-controller/crds/actions.summerwind.dev_runners.yaml @@ -1526,6 +1526,8 @@ spec: - name type: object type: array + workDir: + type: string type: object status: description: RunnerStatus defines the observed state of Runner diff --git a/config/crd/bases/actions.summerwind.dev_runnerdeployments.yaml b/config/crd/bases/actions.summerwind.dev_runnerdeployments.yaml index 2e6e03e7..b867989f 100644 --- a/config/crd/bases/actions.summerwind.dev_runnerdeployments.yaml +++ b/config/crd/bases/actions.summerwind.dev_runnerdeployments.yaml @@ -1533,6 +1533,8 @@ spec: - name type: object type: array + workDir: + type: string type: object type: object required: diff --git a/config/crd/bases/actions.summerwind.dev_runnerreplicasets.yaml b/config/crd/bases/actions.summerwind.dev_runnerreplicasets.yaml index 0cc21cdb..261685e5 100644 --- a/config/crd/bases/actions.summerwind.dev_runnerreplicasets.yaml +++ b/config/crd/bases/actions.summerwind.dev_runnerreplicasets.yaml @@ -1533,6 +1533,8 @@ spec: - name type: object type: array + workDir: + type: string type: object type: object required: diff --git a/config/crd/bases/actions.summerwind.dev_runners.yaml b/config/crd/bases/actions.summerwind.dev_runners.yaml index 5f8da46e..ee2aa441 100644 --- a/config/crd/bases/actions.summerwind.dev_runners.yaml +++ b/config/crd/bases/actions.summerwind.dev_runners.yaml @@ -1526,6 +1526,8 @@ spec: - name type: object type: array + workDir: + type: string type: object status: description: RunnerStatus defines the observed state of Runner diff --git a/controllers/runner_controller.go b/controllers/runner_controller.go index 586bb682..f73cc101 100644 --- a/controllers/runner_controller.go +++ b/controllers/runner_controller.go @@ -307,6 +307,11 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) { runnerImage = r.RunnerImage } + workDir := runner.Spec.WorkDir + if workDir == "" { + workDir = "/runner/_work" + } + runnerImagePullPolicy := runner.Spec.ImagePullPolicy if runnerImagePullPolicy == "" { runnerImagePullPolicy = corev1.PullAlways @@ -345,6 +350,10 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) { Name: "GITHUB_URL", Value: r.GitHubClient.GithubBaseURL, }, + { + Name: "RUNNER_WORKDIR", + Value: workDir, + }, } env = append(env, runner.Spec.Env...) @@ -392,7 +401,7 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) { pod.Spec.Containers[0].VolumeMounts = []corev1.VolumeMount{ { Name: "work", - MountPath: "/runner/_work", + MountPath: workDir, }, { Name: "externals", @@ -409,7 +418,7 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) { VolumeMounts: []corev1.VolumeMount{ { Name: "work", - MountPath: "/runner/_work", + MountPath: workDir, }, { Name: "externals", diff --git a/runner/entrypoint.sh b/runner/entrypoint.sh index 740849f0..5a877448 100755 --- a/runner/entrypoint.sh +++ b/runner/entrypoint.sh @@ -27,6 +27,10 @@ else exit 1 fi +if [ -n "${RUNNER_WORKDIR}" ]; then + WORKDIR_ARG="--work ${RUNNER_WORKDIR}" +fi + if [ -n "${RUNNER_LABELS}" ]; then LABEL_ARG="--labels ${RUNNER_LABELS}" fi @@ -41,7 +45,7 @@ if [ -z "${RUNNER_REPO}" ] && [ -n "${RUNNER_ORG}" ] && [ -n "${RUNNER_GROUP}" ] fi cd /runner -./config.sh --unattended --replace --name "${RUNNER_NAME}" --url "${GITHUB_URL}${ATTACH}" --token "${RUNNER_TOKEN}" ${RUNNER_GROUP_ARG} ${LABEL_ARG} +./config.sh --unattended --replace --name "${RUNNER_NAME}" --url "${GITHUB_URL}${ATTACH}" --token "${RUNNER_TOKEN}" ${RUNNER_GROUP_ARG} ${LABEL_ARG} ${WORKDIR_ARG} # Hack due to the DinD volumes mv ./externalstmp/* ./externals/