Skip to content

Commit

Permalink
Merge pull request #1914 from Automattic/fix/port-mappings
Browse files Browse the repository at this point in the history
fix(dev-env): display all port mappings
  • Loading branch information
sjinks authored Jul 1, 2024
2 parents 2bb77f6 + a6b4d11 commit a0db042
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/lib/dev-environment/dev-environment-lando.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,20 +470,21 @@ async function getExtraServicesConnections(
// eslint-disable-next-line no-await-in-loop
const containerScan = service.id ? await lando.engine.docker.scan( service.id ) : null;
if ( containerScan?.NetworkSettings.Ports ) {
type ExternalMapping = ( typeof containerScan.NetworkSettings.Ports )[ number ];

const mappings = Object.keys( containerScan.NetworkSettings.Ports )
.map( internalPort => containerScan.NetworkSettings.Ports[ internalPort ] )
.filter( ( externalMapping: ExternalMapping | undefined ) => externalMapping?.length );
const mappings = Object.values( containerScan.NetworkSettings.Ports ).filter(
externalMapping => externalMapping?.length
);

if ( mappings.length ) {
const { HostIp: host, HostPort: port } = mappings[ 0 ][ 0 ];
mappings[ 0 ]?.forEach( ( { HostIp: host, HostPort: port } ) => {
const label = displayConfiguration.label ?? service.service;
const value =
( displayConfiguration.protocol ? `${ displayConfiguration.protocol }://` : '' ) +
`${ host }:${ port }`;
extraServices[ label ] = value;
}
if ( extraServices[ label ] ) {
extraServices[ label ] += `, ${ value }`;
} else {
extraServices[ label ] = value;
}
} );
}
}

Expand Down

0 comments on commit a0db042

Please sign in to comment.