mirror of
https://github.com/actions/runner-container-hooks.git
synced 2025-12-14 16:46:43 +00:00
filter out empty ports
This commit is contained in:
@@ -271,7 +271,7 @@ export async function healthCheck({
|
|||||||
export async function containerPorts(id: string): Promise<string[]> {
|
export async function containerPorts(id: string): Promise<string[]> {
|
||||||
const dockerArgs = ['port', id]
|
const dockerArgs = ['port', id]
|
||||||
const portMappings = (await runDockerCommand(dockerArgs)).trim()
|
const portMappings = (await runDockerCommand(dockerArgs)).trim()
|
||||||
return portMappings.split('\n')
|
return portMappings.split('\n').filter(p => !!p)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function registryLogin(registry?: Registry): Promise<string> {
|
export async function registryLogin(registry?: Registry): Promise<string> {
|
||||||
|
|||||||
@@ -186,15 +186,15 @@ function transformDockerPortsToContextPorts(
|
|||||||
meta: ContainerMetadata
|
meta: ContainerMetadata
|
||||||
): ContextPorts {
|
): ContextPorts {
|
||||||
// ex: '80/tcp -> 0.0.0.0:80'
|
// ex: '80/tcp -> 0.0.0.0:80'
|
||||||
const re = /^(\d+)\/(\w+)? -> (.*):(\d+)$/
|
const re = /^(\d+)(\/\w+)? -> (.*):(\d+)$/
|
||||||
const contextPorts: ContextPorts = {}
|
const contextPorts: ContextPorts = {}
|
||||||
|
|
||||||
if (meta.ports) {
|
if (meta.ports?.length) {
|
||||||
for (const port of meta.ports) {
|
for (const port of meta.ports) {
|
||||||
const matches = port.match(re)
|
const matches = port.match(re)
|
||||||
if (!matches) {
|
if (!matches) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'Container ports could not match the regex: "^(\\d+)\\/(\\w+)? -> (.*):(\\d+)$"'
|
'Container ports could not match the regex: "^(\\d+)(\\/\\w+)? -> (.*):(\\d+)$"'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
contextPorts[matches[1]] = matches[matches.length - 1]
|
contextPorts[matches[1]] = matches[matches.length - 1]
|
||||||
|
|||||||
Reference in New Issue
Block a user