filter out empty ports

This commit is contained in:
Nikola Jokic
2022-06-08 16:49:44 +02:00
parent 51bd8b62a4
commit ee2554e2c0
2 changed files with 4 additions and 4 deletions

View File

@@ -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> {

View File

@@ -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]