Docker and K8s: Fix shell arguments when split by the runner (#115)

* Docker: Fix shell arguments when split by the runner

* Add shlex to k8s hook as well
This commit is contained in:
Nikola Jokic
2023-11-20 15:09:36 +01:00
committed by GitHub
parent c47c74ad9e
commit c093f87779
13 changed files with 96 additions and 13 deletions

View File

@@ -14,7 +14,8 @@
"@actions/io": "^1.1.2",
"@kubernetes/client-node": "^0.18.1",
"hooklib": "file:../hooklib",
"js-yaml": "^4.1.0"
"js-yaml": "^4.1.0",
"shlex": "^2.1.2"
},
"devDependencies": {
"@types/jest": "^27.4.1",
@@ -4163,6 +4164,11 @@
"node": ">=8"
}
},
"node_modules/shlex": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/shlex/-/shlex-2.1.2.tgz",
"integrity": "sha512-Nz6gtibMVgYeMEhUjp2KuwAgqaJA1K155dU/HuDaEJUGgnmYfVtVZah+uerVWdH8UGnyahhDCgABbYTbs254+w=="
},
"node_modules/signal-exit": {
"version": "3.0.7",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz",
@@ -8117,6 +8123,11 @@
"integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==",
"dev": true
},
"shlex": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/shlex/-/shlex-2.1.2.tgz",
"integrity": "sha512-Nz6gtibMVgYeMEhUjp2KuwAgqaJA1K155dU/HuDaEJUGgnmYfVtVZah+uerVWdH8UGnyahhDCgABbYTbs254+w=="
},
"signal-exit": {
"version": "3.0.7",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz",

View File

@@ -18,7 +18,8 @@
"@actions/io": "^1.1.2",
"@kubernetes/client-node": "^0.18.1",
"hooklib": "file:../hooklib",
"js-yaml": "^4.1.0"
"js-yaml": "^4.1.0",
"shlex": "^2.1.2"
},
"devDependencies": {
"@types/jest": "^27.4.1",

View File

@@ -23,7 +23,8 @@ import {
generateContainerName,
mergeContainerWithOptions,
readExtensionFromFile,
PodPhase
PodPhase,
fixArgs
} from '../k8s/utils'
import { JOB_CONTAINER_EXTENSION_NAME, JOB_CONTAINER_NAME } from './constants'
@@ -206,7 +207,7 @@ export function createContainerSpec(
}
if (container.entryPointArgs?.length > 0) {
podContainer.args = container.entryPointArgs
podContainer.args = fixArgs(container.entryPointArgs)
}
podContainer.env = []

View File

@@ -14,7 +14,8 @@ import {
containerVolumes,
PodPhase,
mergeContainerWithOptions,
readExtensionFromFile
readExtensionFromFile,
fixArgs
} from '../k8s/utils'
import { JOB_CONTAINER_EXTENSION_NAME, JOB_CONTAINER_NAME } from './constants'
@@ -89,7 +90,7 @@ function createContainerSpec(
? [container.entryPoint]
: undefined
podContainer.args = container.entryPointArgs?.length
? container.entryPointArgs
? fixArgs(container.entryPointArgs)
: undefined
if (secretName) {

View File

@@ -511,7 +511,7 @@ export async function isPodContainerAlpine(
[
'sh',
'-c',
"[ $(cat /etc/*release* | grep -i -e '^ID=*alpine*' -c) != 0 ] || exit 1"
`'[ $(cat /etc/*release* | grep -i -e "^ID=*alpine*" -c) != 0 ] || exit 1'`
],
podName,
containerName

View File

@@ -7,6 +7,7 @@ import * as path from 'path'
import { v1 as uuidv4 } from 'uuid'
import { POD_VOLUME_NAME } from './index'
import { JOB_CONTAINER_EXTENSION_NAME } from '../hooks/constants'
import * as shlex from 'shlex'
export const DEFAULT_CONTAINER_ENTRY_POINT_ARGS = [`-f`, `/dev/null`]
export const DEFAULT_CONTAINER_ENTRY_POINT = 'tail'
@@ -282,3 +283,7 @@ function mergeLists<T>(base?: T[], from?: T[]): T[] {
b.push(...from)
return b
}
export function fixArgs(args: string[]): string[] {
return shlex.split(args.join(' '))
}

View File

@@ -72,7 +72,7 @@ describe('Run container step', () => {
runContainerStepData.args.entryPoint = 'bash'
runContainerStepData.args.entryPointArgs = [
'-c',
'if [[ -z $NODE_ENV ]]; then exit 1; fi'
"'if [[ -z $NODE_ENV ]]; then exit 1; fi'"
]
await expect(
runContainerStep(runContainerStepData.args)