docker-local-proxy
Advanced tools
Comparing version
@@ -186,3 +186,3 @@ #!/usr/bin/env node | ||
server { | ||
listen {{this}}; | ||
listen {{add this @../index}}; | ||
proxy_pass {{../this.fullName}}:{{this}}; | ||
@@ -195,2 +195,5 @@ } | ||
const tcpCompiledTemplate = handlebars_1.default.compile(tcpTemplate); | ||
handlebars_1.default.registerHelper('add', function (a, b) { | ||
return a + b; | ||
}); | ||
return { | ||
@@ -214,3 +217,9 @@ httpConfig: httpCompiledTemplate({ containers, httpPort: argv.httpPort }), | ||
} | ||
function updateDockerComposePorts(httpPorts, tcpPorts) { | ||
// Create Docker network if it doesn't exist | ||
async function createDockerNetwork() { | ||
const networkName = 'docker-local-proxy'; | ||
const networks = await docker.listNetworks(); | ||
const networkExists = networks.some(network => network.Name === networkName); | ||
} | ||
function updateDockerCompose(containers, httpPorts, tcpPorts) { | ||
const composePath = PROJECT_ROOT + '/docker-compose.yml'; | ||
@@ -223,7 +232,5 @@ try { | ||
const newHttpPorts = httpPorts.map(port => `${port}:${port}`); | ||
const newTcpPorts = tcpPorts.map(port => `${port}:${port}`); | ||
// Filter out old HTTP and TCP ports to avoid duplicates | ||
const filteredPorts = existingPorts.filter((p) => !p.startsWith('80:') && !p.startsWith('443:') && !p.startsWith('5432:')); | ||
const newTcpPorts = containers.flatMap((_, index) => tcpPorts.map(port => `${port + index}:${port + index}`)); | ||
// Combine existing with new ports | ||
doc.services['nginx-proxy'].ports = [...filteredPorts, ...newHttpPorts, ...newTcpPorts]; | ||
doc.services['nginx-proxy'].ports = [...newHttpPorts, ...newTcpPorts]; | ||
} | ||
@@ -240,18 +247,2 @@ // Write back the updated configuration | ||
} | ||
// Create Docker network if it doesn't exist | ||
async function createDockerNetwork() { | ||
const networkName = 'docker-local-proxy'; | ||
const networks = await docker.listNetworks(); | ||
const networkExists = networks.some(network => network.Name === networkName); | ||
if (!networkExists) { | ||
await docker.createNetwork({ | ||
Name: networkName, | ||
Driver: 'bridge' | ||
}); | ||
console.log(`Network ${networkName} created.`); | ||
} | ||
else { | ||
console.log(`Network ${networkName} already exists.`); | ||
} | ||
} | ||
function runDockerComposeUp() { | ||
@@ -307,8 +298,11 @@ return new Promise((resolve, reject) => { | ||
} | ||
updateDockerComposePorts(argv.httpPort, argv.tcpPort); | ||
updateDockerCompose(containers, argv.httpPort, argv.tcpPort); | ||
await runDockerComposeUp(); | ||
console.log('Containers Found:'); | ||
containers.forEach(({ hostname, fullName }) => console.log(' - Container', fullName, 'Hostname:', hostname, 'HTTP:', argv.httpPort.join(', '), 'TCP:', argv.tcpPort.join(', '))); | ||
containers.forEach((container, index) => { | ||
const httpBindings = argv.httpPort.join(', '); | ||
const tcpBindings = argv.tcpPort.map(port => `${port + index}:${port}`).join(', '); | ||
console.log(` - Container: ${container.fullName}, Hostname: ${container.hostname}, HTTP: ${httpBindings}, TCP: ${tcpBindings}`); | ||
}); | ||
} | ||
main(); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "docker-local-proxy", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"description": "A tool for automatically configuring Nginx and updating /etc/hosts based on Docker containers for local development environments.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -181,3 +181,3 @@ #!/usr/bin/env node | ||
server { | ||
listen {{this}}; | ||
listen {{add this @../index}}; | ||
proxy_pass {{../this.fullName}}:{{this}}; | ||
@@ -192,2 +192,6 @@ } | ||
Handlebars.registerHelper('add', function (a, b) { | ||
return a + b; | ||
}); | ||
return { | ||
@@ -214,4 +218,10 @@ httpConfig: httpCompiledTemplate({containers, httpPort: argv.httpPort}), | ||
// Create Docker network if it doesn't exist | ||
async function createDockerNetwork() { | ||
const networkName = 'docker-local-proxy'; | ||
const networks = await docker.listNetworks(); | ||
const networkExists = networks.some(network => network.Name === networkName); | ||
} | ||
function updateDockerComposePorts(httpPorts: number[], tcpPorts: number[]) { | ||
function updateDockerCompose(containers: ContainerInfo[],httpPorts: number[], tcpPorts: number[]) { | ||
const composePath = PROJECT_ROOT + '/docker-compose.yml'; | ||
@@ -227,9 +237,7 @@ | ||
const newHttpPorts = httpPorts.map(port => `${port}:${port}`); | ||
const newTcpPorts = tcpPorts.map(port => `${port}:${port}`); | ||
// Filter out old HTTP and TCP ports to avoid duplicates | ||
const filteredPorts = existingPorts.filter((p: string) => !p.startsWith('80:') && !p.startsWith('443:') && !p.startsWith('5432:')); | ||
const newTcpPorts = containers.flatMap((_, index) => | ||
tcpPorts.map(port => `${port + index}:${port + index}`) | ||
); | ||
// Combine existing with new ports | ||
doc.services['nginx-proxy'].ports = [...filteredPorts, ...newHttpPorts, ...newTcpPorts]; | ||
doc.services['nginx-proxy'].ports = [ ...newHttpPorts, ...newTcpPorts]; | ||
} | ||
@@ -247,19 +255,2 @@ | ||
// Create Docker network if it doesn't exist | ||
async function createDockerNetwork() { | ||
const networkName = 'docker-local-proxy'; | ||
const networks = await docker.listNetworks(); | ||
const networkExists = networks.some(network => network.Name === networkName); | ||
if (!networkExists) { | ||
await docker.createNetwork({ | ||
Name: networkName, | ||
Driver: 'bridge' | ||
}); | ||
console.log(`Network ${networkName} created.`); | ||
} else { | ||
console.log(`Network ${networkName} already exists.`); | ||
} | ||
} | ||
function runDockerComposeUp() { | ||
@@ -320,9 +311,12 @@ return new Promise((resolve, reject) => { | ||
updateDockerComposePorts(argv.httpPort, argv.tcpPort); | ||
updateDockerCompose(containers, argv.httpPort, argv.tcpPort); | ||
await runDockerComposeUp(); | ||
console.log('Containers Found:') | ||
containers.forEach(({hostname,fullName}) => console.log(' - Container',fullName, 'Hostname:', hostname, 'HTTP:', argv.httpPort.join(', '), 'TCP:', argv.tcpPort.join(', '))) | ||
containers.forEach((container, index) => { | ||
const httpBindings = argv.httpPort.join(', '); | ||
const tcpBindings = argv.tcpPort.map(port => `${port + index}:${port}`).join(', '); | ||
console.log(` - Container: ${container.fullName}, Hostname: ${container.hostname}, HTTP: ${httpBindings}, TCP: ${tcpBindings}`); | ||
}); | ||
} | ||
main(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
53239
-1.03%833
-1.07%