mirror of
https://github.com/actions/runner-container-hooks.git
synced 2025-12-14 16:46:43 +00:00
exposing env variables from runner with DOCKER_ envs to respect docker options set on host (#40)
* exposing env variables from runner with DOCKER_ prefix to respect rootless docker * Prioritize DOCKER cli over workflow envs * formatted
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { sanitize } from '../src/utils'
|
||||
import { optionsWithDockerEnvs, sanitize } from '../src/utils'
|
||||
|
||||
describe('Utilities', () => {
|
||||
it('should return sanitized image name', () => {
|
||||
@@ -9,4 +9,41 @@ describe('Utilities', () => {
|
||||
const validStr = 'teststr8_one'
|
||||
expect(sanitize(validStr)).toBe(validStr)
|
||||
})
|
||||
|
||||
describe('with docker options', () => {
|
||||
it('should augment options with docker environment variables', () => {
|
||||
process.env.DOCKER_HOST = 'unix:///run/user/1001/docker.sock'
|
||||
process.env.DOCKER_NOTEXIST = 'notexist'
|
||||
|
||||
const optionDefinitions: any = [
|
||||
undefined,
|
||||
{},
|
||||
{ env: {} },
|
||||
{ env: { DOCKER_HOST: 'unix://var/run/docker.sock' } }
|
||||
]
|
||||
for (const opt of optionDefinitions) {
|
||||
let options = optionsWithDockerEnvs(opt)
|
||||
expect(options).toBeDefined()
|
||||
expect(options?.env).toBeDefined()
|
||||
expect(options?.env?.DOCKER_HOST).toBe(process.env.DOCKER_HOST)
|
||||
expect(options?.env?.DOCKER_NOTEXIST).toBeUndefined()
|
||||
}
|
||||
})
|
||||
|
||||
it('should not overwrite other options', () => {
|
||||
process.env.DOCKER_HOST = 'unix:///run/user/1001/docker.sock'
|
||||
const opt = {
|
||||
workingDir: 'test',
|
||||
input: Buffer.from('test')
|
||||
}
|
||||
|
||||
const options = optionsWithDockerEnvs(opt)
|
||||
expect(options).toBeDefined()
|
||||
expect(options?.workingDir).toBe(opt.workingDir)
|
||||
expect(options?.input).toBe(opt.input)
|
||||
expect(options?.env).toStrictEqual({
|
||||
DOCKER_HOST: process.env.DOCKER_HOST
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user