mirror of
https://github.com/danbulant/docker-compose
synced 2026-05-19 12:28:43 +00:00
fix: fix mapping ipv6-based port mappings
This commit is contained in:
parent
e7013dfab1
commit
48c9f0841a
3 changed files with 41 additions and 43 deletions
|
|
@ -7,24 +7,22 @@ const mapPorts = (
|
|||
const result = !ports
|
||||
? []
|
||||
: (() => {
|
||||
return ports.split(',').map((untypedPort) => {
|
||||
const exposedFragments = untypedPort.trim().split('->')
|
||||
return ports.split(',').map((untypedPort) => {
|
||||
const exposedFragments = untypedPort.trim().split('->')
|
||||
|
||||
console.log(exposedFragments)
|
||||
|
||||
const [port, protocol] =
|
||||
exposedFragments.length === 1
|
||||
? exposedFragments[0].split('/')
|
||||
: exposedFragments[1].split('/')
|
||||
const [address, mappedPort] =
|
||||
exposedFragments.length === 2 ? exposedFragments[0].split(':') : []
|
||||
return {
|
||||
exposed: { port: Number(port), protocol },
|
||||
...(address &&
|
||||
mappedPort && { mapped: { port: Number(mappedPort), address } })
|
||||
}
|
||||
})
|
||||
})()
|
||||
const [port, protocol] =
|
||||
exposedFragments.length === 1
|
||||
? exposedFragments[0].split('/')
|
||||
: exposedFragments[1].split('/')
|
||||
const [address, mappedPort] =
|
||||
exposedFragments.length === 2 ? exposedFragments[0].split(':') : []
|
||||
return {
|
||||
exposed: { port: Number(port), protocol },
|
||||
...(address &&
|
||||
mappedPort && { mapped: { port: Number(mappedPort), address } })
|
||||
}
|
||||
})
|
||||
})()
|
||||
return result
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import Docker from 'dockerode'
|
|||
import * as compose from '../src/index'
|
||||
import * as path from 'path'
|
||||
import { readFile } from 'fs'
|
||||
import { mapPorts, mapPsOutput } from '../src/index'
|
||||
import { mapPsOutput } from '../src/index'
|
||||
const docker = new Docker()
|
||||
|
||||
// Docker commands, especially builds, can take some time. This makes sure that they can take the time they need.
|
||||
|
|
@ -94,25 +94,21 @@ test('ensure exit code is returned correctly', async (): Promise<void> => {
|
|||
})
|
||||
|
||||
describe('starts containers properly with --build and --timeout options', (): void => {
|
||||
beforeEach(
|
||||
async (): Promise<void> => {
|
||||
await compose.down({
|
||||
cwd: path.join(__dirname),
|
||||
log: logOutput,
|
||||
config: 'docker-compose-build.yml'
|
||||
})
|
||||
}
|
||||
)
|
||||
beforeEach(async (): Promise<void> => {
|
||||
await compose.down({
|
||||
cwd: path.join(__dirname),
|
||||
log: logOutput,
|
||||
config: 'docker-compose-build.yml'
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(
|
||||
async (): Promise<void> => {
|
||||
await compose.down({
|
||||
cwd: path.join(__dirname),
|
||||
log: logOutput,
|
||||
config: 'docker-compose-build.yml'
|
||||
})
|
||||
}
|
||||
)
|
||||
afterEach(async (): Promise<void> => {
|
||||
await compose.down({
|
||||
cwd: path.join(__dirname),
|
||||
log: logOutput,
|
||||
config: 'docker-compose-build.yml'
|
||||
})
|
||||
})
|
||||
|
||||
test('ensure container gets started with --build option', async (): Promise<void> => {
|
||||
await compose.upAll({
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import mapPorts from "../src/port-mapper";
|
||||
import mapPorts from '../src/port-mapper'
|
||||
|
||||
test('map ports for empty string', () => {
|
||||
expect(mapPorts('')).toEqual([])
|
||||
|
|
@ -33,22 +33,26 @@ test('map multiple tcp ports exposed on ivp4 interfaces', () => {
|
|||
})
|
||||
|
||||
test('map multiple tcp ports exposed on ipv4 and ipv6 interfaces', () => {
|
||||
expect(mapPorts('0.0.0.0:443->443/tcp,:::443->443/tcp, 0.0.0.0:80->80/tcp,:::80->80/tcp')).toEqual([
|
||||
expect(
|
||||
mapPorts(
|
||||
'0.0.0.0:443->443/tcp,:::443->443/tcp, 0.0.0.0:80->80/tcp,:::80->80/tcp'
|
||||
)
|
||||
).toEqual([
|
||||
{
|
||||
exposed: { port: 443, protocol: 'tcp' },
|
||||
mapped: { address: '0.0.0.0', port: 443 },
|
||||
mapped: { address: '0.0.0.0', port: 443 }
|
||||
},
|
||||
{
|
||||
exposed: { port: 443, protocol: 'tcp' },
|
||||
mapped: { address: ':::', port: 443 },
|
||||
mapped: { address: ':::', port: 443 }
|
||||
},
|
||||
{
|
||||
exposed: { port: 80, protocol: 'tcp' },
|
||||
mapped: { address: '0.0.0.0', port: 80 },
|
||||
mapped: { address: '0.0.0.0', port: 80 }
|
||||
},
|
||||
{
|
||||
exposed: { port: 80, protocol: 'tcp' },
|
||||
mapped: { address: ':::', port: 80 },
|
||||
},
|
||||
mapped: { address: ':::', port: 80 }
|
||||
}
|
||||
])
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue