mirror of
https://github.com/actions/runner-container-hooks.git
synced 2026-01-07 02:18:33 +08:00
Compare commits
2 Commits
0951cc73e4
...
3f829eef9e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3f829eef9e | ||
|
|
011ffb284e |
@@ -6,6 +6,7 @@ import { execCpFromPod, execCpToPod, execPodStep } from '../k8s'
|
|||||||
import { writeRunScript, sleep, listDirAllCommand } from '../k8s/utils'
|
import { writeRunScript, sleep, listDirAllCommand } from '../k8s/utils'
|
||||||
import { JOB_CONTAINER_NAME } from './constants'
|
import { JOB_CONTAINER_NAME } from './constants'
|
||||||
import { dirname } from 'path'
|
import { dirname } from 'path'
|
||||||
|
import * as shlex from 'shlex'
|
||||||
|
|
||||||
export async function runScriptStep(
|
export async function runScriptStep(
|
||||||
args: RunScriptStepArgs,
|
args: RunScriptStepArgs,
|
||||||
@@ -26,6 +27,23 @@ export async function runScriptStep(
|
|||||||
const runnerTemp = `${workdir}/_temp`
|
const runnerTemp = `${workdir}/_temp`
|
||||||
await execCpToPod(state.jobPod, runnerTemp, containerTemp)
|
await execCpToPod(state.jobPod, runnerTemp, containerTemp)
|
||||||
|
|
||||||
|
// Copy GitHub directories from temp to /github
|
||||||
|
const setupCommands = [
|
||||||
|
'mkdir -p /github',
|
||||||
|
'cp -r /__w/_temp/_github_home /github/home',
|
||||||
|
'cp -r /__w/_temp/_github_workflow /github/workflow'
|
||||||
|
]
|
||||||
|
|
||||||
|
try {
|
||||||
|
await execPodStep(
|
||||||
|
['sh', '-c', shlex.quote(setupCommands.join(' && '))],
|
||||||
|
state.jobPod,
|
||||||
|
JOB_CONTAINER_NAME
|
||||||
|
)
|
||||||
|
} catch (err) {
|
||||||
|
core.debug(`Failed to copy GitHub directories: ${JSON.stringify(err)}`)
|
||||||
|
}
|
||||||
|
|
||||||
// Execute the entrypoint script
|
// Execute the entrypoint script
|
||||||
args.entryPoint = 'sh'
|
args.entryPoint = 'sh'
|
||||||
args.entryPointArgs = ['-e', containerPath]
|
args.entryPointArgs = ['-e', containerPath]
|
||||||
|
|||||||
@@ -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