mirror of
https://github.com/actions/runner-container-hooks.git
synced 2025-12-14 08:36:45 +00:00
Fix service port mappings when input is undefined, null, or empty (#60)
* fix: service without ports defined * fix port mappings when ports are undefined,null or empty * fix Co-authored-by: Ronald Claveau <ronald.claveau@pennylane.com>
This commit is contained in:
@@ -125,10 +125,9 @@ function generateResponseFile(
|
|||||||
)
|
)
|
||||||
if (serviceContainers?.length) {
|
if (serviceContainers?.length) {
|
||||||
response.context['services'] = serviceContainers.map(c => {
|
response.context['services'] = serviceContainers.map(c => {
|
||||||
if (!c.ports) {
|
if (!c.ports?.length) {
|
||||||
return
|
return { image: c.image }
|
||||||
}
|
}
|
||||||
|
|
||||||
const ctxPorts: ContextPorts = {}
|
const ctxPorts: ContextPorts = {}
|
||||||
for (const port of c.ports) {
|
for (const port of c.ports) {
|
||||||
ctxPorts[port.containerPort] = port.hostPort
|
ctxPorts[port.containerPort] = port.hostPort
|
||||||
|
|||||||
@@ -517,6 +517,9 @@ export function containerPorts(
|
|||||||
container: ContainerInfo
|
container: ContainerInfo
|
||||||
): k8s.V1ContainerPort[] {
|
): k8s.V1ContainerPort[] {
|
||||||
const ports: k8s.V1ContainerPort[] = []
|
const ports: k8s.V1ContainerPort[] = []
|
||||||
|
if (!container.portMappings?.length) {
|
||||||
|
return ports
|
||||||
|
}
|
||||||
for (const portDefinition of container.portMappings) {
|
for (const portDefinition of container.portMappings) {
|
||||||
const portProtoSplit = portDefinition.split('/')
|
const portProtoSplit = portDefinition.split('/')
|
||||||
if (portProtoSplit.length > 2) {
|
if (portProtoSplit.length > 2) {
|
||||||
|
|||||||
@@ -82,4 +82,18 @@ describe('Prepare job', () => {
|
|||||||
expect(services[0].command).toBe(undefined)
|
expect(services[0].command).toBe(undefined)
|
||||||
expect(services[0].args).toBe(undefined)
|
expect(services[0].args).toBe(undefined)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test.each([undefined, null, []])(
|
||||||
|
'should not throw exception when portMapping=%p',
|
||||||
|
async pm => {
|
||||||
|
prepareJobData.args.services.forEach(s => {
|
||||||
|
s.portMappings = pm
|
||||||
|
})
|
||||||
|
await prepareJob(prepareJobData.args, prepareJobOutputFilePath)
|
||||||
|
const content = JSON.parse(
|
||||||
|
fs.readFileSync(prepareJobOutputFilePath).toString()
|
||||||
|
)
|
||||||
|
expect(() => content.context.services[0].image).not.toThrow()
|
||||||
|
}
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user