mirror of
https://github.com/actions/runner-container-hooks.git
synced 2025-12-13 08:06:44 +00:00
Use ACTIONS_RUNNER_CONTAINER_HOOK_TEMPLATE to extend service containers (#134)
https://github.com/actions/runner-container-hooks/issues/132 Co-authored-by: Katarzyna Radkowska <katarzyna.radkowska@sabre.com>
This commit is contained in:
@@ -9,7 +9,7 @@ spec:
|
|||||||
runAsGroup: 3000
|
runAsGroup: 3000
|
||||||
restartPolicy: Never
|
restartPolicy: Never
|
||||||
containers:
|
containers:
|
||||||
- name: $job # overwirtes job container
|
- name: $job # overwrites job container
|
||||||
env:
|
env:
|
||||||
- name: ENV1
|
- name: ENV1
|
||||||
value: "value1"
|
value: "value1"
|
||||||
@@ -20,11 +20,22 @@ spec:
|
|||||||
args:
|
args:
|
||||||
- -c
|
- -c
|
||||||
- sleep 50
|
- sleep 50
|
||||||
|
- name: $redis # overwrites redis service
|
||||||
|
env:
|
||||||
|
- name: ENV2
|
||||||
|
value: "value2"
|
||||||
|
image: "busybox:1.28" # Ignored
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
memory: "1Mi"
|
||||||
|
cpu: "1"
|
||||||
|
limits:
|
||||||
|
memory: "1Gi"
|
||||||
|
cpu: "2"
|
||||||
- name: side-car
|
- name: side-car
|
||||||
image: "ubuntu:latest" # required
|
image: "ubuntu:latest" # required
|
||||||
command:
|
command:
|
||||||
- sh
|
- sh
|
||||||
args:
|
args:
|
||||||
- -c
|
- -c
|
||||||
- sleep 60
|
- sleep 60
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ export function getSecretName(): string {
|
|||||||
|
|
||||||
export const MAX_POD_NAME_LENGTH = 63
|
export const MAX_POD_NAME_LENGTH = 63
|
||||||
export const STEP_POD_NAME_SUFFIX_LENGTH = 8
|
export const STEP_POD_NAME_SUFFIX_LENGTH = 8
|
||||||
|
export const CONTAINER_EXTENSION_PREFIX = '$'
|
||||||
export const JOB_CONTAINER_NAME = 'job'
|
export const JOB_CONTAINER_NAME = 'job'
|
||||||
export const JOB_CONTAINER_EXTENSION_NAME = '$job'
|
export const JOB_CONTAINER_EXTENSION_NAME = '$job'
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import {
|
|||||||
PodPhase,
|
PodPhase,
|
||||||
fixArgs
|
fixArgs
|
||||||
} from '../k8s/utils'
|
} from '../k8s/utils'
|
||||||
import { JOB_CONTAINER_EXTENSION_NAME, JOB_CONTAINER_NAME } from './constants'
|
import { CONTAINER_EXTENSION_PREFIX, JOB_CONTAINER_NAME } from './constants'
|
||||||
|
|
||||||
export async function prepareJob(
|
export async function prepareJob(
|
||||||
args: PrepareJobArgs,
|
args: PrepareJobArgs,
|
||||||
@@ -60,7 +60,7 @@ export async function prepareJob(
|
|||||||
service,
|
service,
|
||||||
generateContainerName(service.image),
|
generateContainerName(service.image),
|
||||||
false,
|
false,
|
||||||
undefined
|
extension
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -235,7 +235,7 @@ export function createContainerSpec(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const from = extension.spec?.containers?.find(
|
const from = extension.spec?.containers?.find(
|
||||||
c => c.name === JOB_CONTAINER_EXTENSION_NAME
|
c => c.name === CONTAINER_EXTENSION_PREFIX + name
|
||||||
)
|
)
|
||||||
|
|
||||||
if (from) {
|
if (from) {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { Mount } from 'hooklib'
|
|||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import { v1 as uuidv4 } from 'uuid'
|
import { v1 as uuidv4 } from 'uuid'
|
||||||
import { POD_VOLUME_NAME } from './index'
|
import { POD_VOLUME_NAME } from './index'
|
||||||
import { JOB_CONTAINER_EXTENSION_NAME } from '../hooks/constants'
|
import { CONTAINER_EXTENSION_PREFIX } from '../hooks/constants'
|
||||||
import * as shlex from 'shlex'
|
import * as shlex from 'shlex'
|
||||||
|
|
||||||
export const DEFAULT_CONTAINER_ENTRY_POINT_ARGS = [`-f`, `/dev/null`]
|
export const DEFAULT_CONTAINER_ENTRY_POINT_ARGS = [`-f`, `/dev/null`]
|
||||||
@@ -180,7 +180,7 @@ export function mergeContainerWithOptions(
|
|||||||
): void {
|
): void {
|
||||||
for (const [key, value] of Object.entries(from)) {
|
for (const [key, value] of Object.entries(from)) {
|
||||||
if (key === 'name') {
|
if (key === 'name') {
|
||||||
if (value !== base.name && value !== JOB_CONTAINER_EXTENSION_NAME) {
|
if (value !== CONTAINER_EXTENSION_PREFIX + base.name) {
|
||||||
core.warning("Skipping name override: name can't be overwritten")
|
core.warning("Skipping name override: name can't be overwritten")
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
@@ -209,7 +209,9 @@ export function mergePodSpecWithOptions(
|
|||||||
for (const [key, value] of Object.entries(from)) {
|
for (const [key, value] of Object.entries(from)) {
|
||||||
if (key === 'containers') {
|
if (key === 'containers') {
|
||||||
base.containers.push(
|
base.containers.push(
|
||||||
...from.containers.filter(e => !e.name?.startsWith('$'))
|
...from.containers.filter(
|
||||||
|
e => !e.name?.startsWith(CONTAINER_EXTENSION_PREFIX)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
} else if (key === 'volumes' && value) {
|
} else if (key === 'volumes' && value) {
|
||||||
const volumes = value as k8s.V1Volume[]
|
const volumes = value as k8s.V1Volume[]
|
||||||
|
|||||||
@@ -133,6 +133,13 @@ describe('Prepare job', () => {
|
|||||||
expect(got.spec?.containers[1].image).toBe('redis')
|
expect(got.spec?.containers[1].image).toBe('redis')
|
||||||
expect(got.spec?.containers[1].command).toBeFalsy()
|
expect(got.spec?.containers[1].command).toBeFalsy()
|
||||||
expect(got.spec?.containers[1].args).toBeFalsy()
|
expect(got.spec?.containers[1].args).toBeFalsy()
|
||||||
|
expect(got.spec?.containers[1].env).toEqual([
|
||||||
|
{ name: 'ENV2', value: 'value2' }
|
||||||
|
])
|
||||||
|
expect(got.spec?.containers[1].resources).toEqual({
|
||||||
|
requests: { memory: '1Mi', cpu: '1' },
|
||||||
|
limits: { memory: '1Gi', cpu: '2' }
|
||||||
|
})
|
||||||
// side-car
|
// side-car
|
||||||
expect(got.spec?.containers[2].name).toBe('side-car')
|
expect(got.spec?.containers[2].name).toBe('side-car')
|
||||||
expect(got.spec?.containers[2].image).toBe('ubuntu:latest')
|
expect(got.spec?.containers[2].image).toBe('ubuntu:latest')
|
||||||
|
|||||||
Reference in New Issue
Block a user