mirror of
https://github.com/actions/runner-container-hooks.git
synced 2025-12-14 08:36:45 +00:00
Fix workingDir permissions issue by creating it within init container (#283)
* Fix workingDir permissions issue by creating it within init container * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * rework init commands --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -96,20 +96,30 @@ export async function createJobPod(
|
|||||||
appPod.spec.securityContext = {
|
appPod.spec.securityContext = {
|
||||||
fsGroup: 1001
|
fsGroup: 1001
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Extract working directory from GITHUB_WORKSPACE
|
||||||
|
// GITHUB_WORKSPACE is like /__w/repo-name/repo-name
|
||||||
|
const githubWorkspace = process.env.GITHUB_WORKSPACE
|
||||||
|
const workingDirPath = githubWorkspace?.split('/').slice(-2).join('/') ?? ''
|
||||||
|
|
||||||
|
const initCommands = [
|
||||||
|
'mkdir -p /mnt/externals',
|
||||||
|
'mkdir -p /mnt/work',
|
||||||
|
'mkdir -p /mnt/github',
|
||||||
|
'mv /home/runner/externals/* /mnt/externals/'
|
||||||
|
]
|
||||||
|
|
||||||
|
if (workingDirPath) {
|
||||||
|
initCommands.push(`mkdir -p /mnt/work/${workingDirPath}`)
|
||||||
|
}
|
||||||
|
|
||||||
appPod.spec.initContainers = [
|
appPod.spec.initContainers = [
|
||||||
{
|
{
|
||||||
name: 'fs-init',
|
name: 'fs-init',
|
||||||
image:
|
image:
|
||||||
process.env.ACTIONS_RUNNER_IMAGE ||
|
process.env.ACTIONS_RUNNER_IMAGE ||
|
||||||
'ghcr.io/actions/actions-runner:latest',
|
'ghcr.io/actions/actions-runner:latest',
|
||||||
command: [
|
command: ['sh', '-c', initCommands.join(' && ')],
|
||||||
'sh',
|
|
||||||
'-c',
|
|
||||||
`mkdir -p /mnt/externals && \\
|
|
||||||
mkdir -p /mnt/work && \\
|
|
||||||
mkdir -p /mnt/github && \\
|
|
||||||
mv /home/runner/externals/* /mnt/externals/`
|
|
||||||
],
|
|
||||||
securityContext: {
|
securityContext: {
|
||||||
runAsGroup: 1001,
|
runAsGroup: 1001,
|
||||||
runAsUser: 1001
|
runAsUser: 1001
|
||||||
|
|||||||
Reference in New Issue
Block a user