Skip to content

Commit

Permalink
feat: support docker compose v2 plugin version
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexZeitler committed Feb 4, 2023
1 parent ce3ff7d commit 81e72e9
Show file tree
Hide file tree
Showing 19 changed files with 1,540 additions and 4 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,4 @@ module.exports = {

// Whether to use watchman for file crawling
// watchman: true,
};
}
38 changes: 38 additions & 0 deletions src/v2-map-ports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const mapPorts = (
ports: string
): Array<{
mapped?: { address: string; port: number }
exposed: { port: number; protocol: string }
}> => {
if (!ports) {
return []
}

return ports.split(',').map((untypedPort) => {
const exposedFragments = untypedPort.trim().split('->')

const [port, protocol] =
exposedFragments.length === 1
? exposedFragments[0].split('/')
: exposedFragments[1].split('/')

const mapped = exposedFragments[0]
const lastDoubleColon = mapped.lastIndexOf(':')

if (lastDoubleColon === -1) {
return {
exposed: { port: Number(port), protocol }
}
}

const address = mapped.substr(0, lastDoubleColon)
const mappedPort = mapped.substr(lastDoubleColon + 1)

return {
exposed: { port: Number(port), protocol },
mapped: { port: Number(mappedPort), address }
}
})
}

export default mapPorts
Loading

0 comments on commit 81e72e9

Please sign in to comment.