parametrized working directory (#185)
* parametrized working directory * manifests v3.0
This commit is contained in:
		
							parent
							
								
									4e93879b8f
								
							
						
					
					
						commit
						ee8fb5a388
					
				|  | @ -342,6 +342,10 @@ spec: | ||||||
|               value: abcd1234 |               value: abcd1234 | ||||||
|           securityContext: |           securityContext: | ||||||
|             runAsUser: 0 |             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 | ## Runner labels | ||||||
|  |  | ||||||
|  | @ -59,6 +59,8 @@ type RunnerSpec struct { | ||||||
| 
 | 
 | ||||||
| 	// +optional
 | 	// +optional
 | ||||||
| 	Volumes []corev1.Volume `json:"volumes,omitempty"` | 	Volumes []corev1.Volume `json:"volumes,omitempty"` | ||||||
|  | 	// +optional
 | ||||||
|  | 	WorkDir string `json:"workDir,omitempty"` | ||||||
| 
 | 
 | ||||||
| 	// +optional
 | 	// +optional
 | ||||||
| 	InitContainers []corev1.Container `json:"initContainers,omitempty"` | 	InitContainers []corev1.Container `json:"initContainers,omitempty"` | ||||||
|  |  | ||||||
|  | @ -1533,6 +1533,8 @@ spec: | ||||||
|                           - name |                           - name | ||||||
|                         type: object |                         type: object | ||||||
|                       type: array |                       type: array | ||||||
|  |                     workDir: | ||||||
|  |                       type: string | ||||||
|                   type: object |                   type: object | ||||||
|               type: object |               type: object | ||||||
|           required: |           required: | ||||||
|  |  | ||||||
|  | @ -1533,6 +1533,8 @@ spec: | ||||||
|                           - name |                           - name | ||||||
|                         type: object |                         type: object | ||||||
|                       type: array |                       type: array | ||||||
|  |                     workDir: | ||||||
|  |                       type: string | ||||||
|                   type: object |                   type: object | ||||||
|               type: object |               type: object | ||||||
|           required: |           required: | ||||||
|  |  | ||||||
|  | @ -1526,6 +1526,8 @@ spec: | ||||||
|                   - name |                   - name | ||||||
|                 type: object |                 type: object | ||||||
|               type: array |               type: array | ||||||
|  |             workDir: | ||||||
|  |               type: string | ||||||
|           type: object |           type: object | ||||||
|         status: |         status: | ||||||
|           description: RunnerStatus defines the observed state of Runner |           description: RunnerStatus defines the observed state of Runner | ||||||
|  |  | ||||||
|  | @ -1533,6 +1533,8 @@ spec: | ||||||
|                           - name |                           - name | ||||||
|                         type: object |                         type: object | ||||||
|                       type: array |                       type: array | ||||||
|  |                     workDir: | ||||||
|  |                       type: string | ||||||
|                   type: object |                   type: object | ||||||
|               type: object |               type: object | ||||||
|           required: |           required: | ||||||
|  |  | ||||||
|  | @ -1533,6 +1533,8 @@ spec: | ||||||
|                           - name |                           - name | ||||||
|                         type: object |                         type: object | ||||||
|                       type: array |                       type: array | ||||||
|  |                     workDir: | ||||||
|  |                       type: string | ||||||
|                   type: object |                   type: object | ||||||
|               type: object |               type: object | ||||||
|           required: |           required: | ||||||
|  |  | ||||||
|  | @ -1526,6 +1526,8 @@ spec: | ||||||
|                   - name |                   - name | ||||||
|                 type: object |                 type: object | ||||||
|               type: array |               type: array | ||||||
|  |             workDir: | ||||||
|  |               type: string | ||||||
|           type: object |           type: object | ||||||
|         status: |         status: | ||||||
|           description: RunnerStatus defines the observed state of Runner |           description: RunnerStatus defines the observed state of Runner | ||||||
|  |  | ||||||
|  | @ -307,6 +307,11 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) { | ||||||
| 		runnerImage = r.RunnerImage | 		runnerImage = r.RunnerImage | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	workDir := runner.Spec.WorkDir | ||||||
|  | 	if workDir == "" { | ||||||
|  | 		workDir = "/runner/_work" | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	runnerImagePullPolicy := runner.Spec.ImagePullPolicy | 	runnerImagePullPolicy := runner.Spec.ImagePullPolicy | ||||||
| 	if runnerImagePullPolicy == "" { | 	if runnerImagePullPolicy == "" { | ||||||
| 		runnerImagePullPolicy = corev1.PullAlways | 		runnerImagePullPolicy = corev1.PullAlways | ||||||
|  | @ -345,6 +350,10 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) { | ||||||
| 			Name:  "GITHUB_URL", | 			Name:  "GITHUB_URL", | ||||||
| 			Value: r.GitHubClient.GithubBaseURL, | 			Value: r.GitHubClient.GithubBaseURL, | ||||||
| 		}, | 		}, | ||||||
|  | 		{ | ||||||
|  | 			Name:  "RUNNER_WORKDIR", | ||||||
|  | 			Value: workDir, | ||||||
|  | 		}, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	env = append(env, runner.Spec.Env...) | 	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{ | 		pod.Spec.Containers[0].VolumeMounts = []corev1.VolumeMount{ | ||||||
| 			{ | 			{ | ||||||
| 				Name:      "work", | 				Name:      "work", | ||||||
| 				MountPath: "/runner/_work", | 				MountPath: workDir, | ||||||
| 			}, | 			}, | ||||||
| 			{ | 			{ | ||||||
| 				Name:      "externals", | 				Name:      "externals", | ||||||
|  | @ -409,7 +418,7 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) { | ||||||
| 			VolumeMounts: []corev1.VolumeMount{ | 			VolumeMounts: []corev1.VolumeMount{ | ||||||
| 				{ | 				{ | ||||||
| 					Name:      "work", | 					Name:      "work", | ||||||
| 					MountPath: "/runner/_work", | 					MountPath: workDir, | ||||||
| 				}, | 				}, | ||||||
| 				{ | 				{ | ||||||
| 					Name:      "externals", | 					Name:      "externals", | ||||||
|  |  | ||||||
|  | @ -27,6 +27,10 @@ else | ||||||
|   exit 1 |   exit 1 | ||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
|  | if [ -n "${RUNNER_WORKDIR}" ]; then | ||||||
|  |   WORKDIR_ARG="--work ${RUNNER_WORKDIR}" | ||||||
|  | fi | ||||||
|  | 
 | ||||||
| if [ -n "${RUNNER_LABELS}" ]; then | if [ -n "${RUNNER_LABELS}" ]; then | ||||||
|   LABEL_ARG="--labels ${RUNNER_LABELS}" |   LABEL_ARG="--labels ${RUNNER_LABELS}" | ||||||
| fi | fi | ||||||
|  | @ -41,7 +45,7 @@ if [ -z "${RUNNER_REPO}" ] && [ -n "${RUNNER_ORG}" ] && [ -n "${RUNNER_GROUP}" ] | ||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
| cd /runner | 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 | # Hack due to the DinD volumes | ||||||
| mv ./externalstmp/* ./externals/ | mv ./externalstmp/* ./externals/ | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue