Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dockerode-compose

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dockerode-compose - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

test/assets/wordpress_long.yml

25

lib/networks.js

@@ -6,2 +6,15 @@ module.exports = async function (docker, projectName, recipe, output) {

var network = recipe.networks[networkName];
if (network === null) {
try {
networks.push({ "name": projectName + '_' + networkName, "network": await docker.createNetwork({ 'Name': projectName + '_' + networkName, 'CheckDuplicate': true }) });
} catch (err) {
if (err.statusCode == 409 && err.json.message.includes("already exists")) {
let returnedNetwork = await docker.listNetworks({ "filters": { "name": [projectName + '_' + networkName] } })
networks.push({ "name": projectName + '_' + networkName, "network": await docker.getNetwork(returnedNetwork[0].Id) })
} else {
throw err;
}
}
continue
}
if (network.external === true) continue;

@@ -36,4 +49,5 @@ var opts = {

try {
networks.push(await docker.createNetwork(opts));
networks.push({ "name": projectName + '_' + networkName, "network": await docker.createNetwork(opts) });
} catch (err) {
//if exists we have to compare with the existing network
throw err;

@@ -45,5 +59,10 @@ }

try {
await docker.createNetwork({ 'Name': projectName + '_default', 'CheckDuplicate': true });
networks.push({ "name": projectName + '_' + networkName, "network": await docker.createNetwork({ 'Name': projectName + '_default', 'CheckDuplicate': true }) });
} catch (err) {
throw err;
if (err.statusCode == 409 && err.json.message.includes("already exists")) {
let returnedNetwork = await docker.listNetworks({ "filters": { "name": [projectName + '_default'] } })
networks.push({ "name": projectName + '_' + networkName, "network": await docker.getNetwork(returnedNetwork[0].Id) })
} else {
throw err;
}
}

@@ -50,0 +69,0 @@ }

@@ -7,2 +7,3 @@ const tools = require('./tools');

for (var serviceName of serviceNames) {
var networksToAttach = [];
var service = recipe.services[serviceName];

@@ -21,15 +22,75 @@

opts.NetworkingConfig.EndpointsConfig[projectName + '_default'] = {
'IPAMConfig': {},
'Links': [],
'Aliases': [
serviceName,
]
};
if (service.networks !== undefined) {
if (Array.isArray(service.networks)) {
for (let index = 0; index < service.networks.length; index++) {
let networkName = projectName + '_' + service.networks[index]
let networkTemplate = {
'NetworkingConfig': {
'EndpointsConfig': {
}
}
}
networkTemplate.NetworkingConfig.EndpointsConfig[networkName] = {};
networkTemplate.NetworkingConfig.EndpointsConfig[networkName]['Aliases'] = [serviceName]
if (index === 0)
opts.NetworkingConfig.EndpointsConfig = networkTemplate.NetworkingConfig.EndpointsConfig
networksToAttach.push(networkTemplate.NetworkingConfig.EndpointsConfig)
}
} else {
let networkNames = Object.keys(service.networks);
for (let index = 0; index < networkNames.length; index++) {
let network = service.networks[networkNames[index]] || {};
let networkName = projectName + '_' + networkNames[index]
let networkTemplate = {
'NetworkingConfig': {
'EndpointsConfig': {
}
}
}
networkTemplate.NetworkingConfig.EndpointsConfig[networkName] = {}
networkTemplate.NetworkingConfig.EndpointsConfig[networkName]['IPAMConfig'] = {}
if (network.aliases !== undefined) {
networkTemplate.NetworkingConfig.EndpointsConfig[networkName]['Aliases'] = network.aliases
}
if (network.ipv4_address !== undefined) {
networkTemplate.NetworkingConfig.EndpointsConfig[networkName].IPAMConfig['IPv4Address'] = network.ipv4_address
}
if (network.ipv6_address !== undefined) {
networkTemplate.NetworkingConfig.EndpointsConfig[networkName].IPAMConfig['IPv6Address'] = network.ipv6_address
}
if (network.link_local_ips !== undefined) {
networkTemplate.NetworkingConfig.EndpointsConfig[networkName].IPAMConfig['LinkLocalIPs'] = network.link_local_ips
}
if (network.priority !== undefined) {
networkTemplate.NetworkingConfig.EndpointsConfig[networkName].priority = network.priority
} else {
networkTemplate.NetworkingConfig.EndpointsConfig[networkName].priority = 0
}
if (index === 0)
opts.NetworkingConfig.EndpointsConfig = networkTemplate.NetworkingConfig.EndpointsConfig
networksToAttach.push(networkTemplate.NetworkingConfig.EndpointsConfig)
}
}
} else {
opts.NetworkingConfig.EndpointsConfig[projectName + '_default'] = {
'IPAMConfig': {},
'Links': [],
'Aliases': [
serviceName,
]
};
}
if (service.volumes) {
opts['Volumes'] = {};
for (var volume of service.volumes) {
var v = volume.split(':');
opts['Volumes'][v[1]] = {};
if (typeof volume === 'string' || volume instanceof String) {
var v = volume.split(':');
opts['Volumes'][v[1]] = {};
} else {
if (volume.target) {
opts['Volumes'][volume.target] = {};
}
}
}

@@ -43,2 +104,15 @@ }

var container = await docker.createContainer(opts);
if (networksToAttach.length > 1) {
let networkNames = Object.keys(networksToAttach[0]);
let network = findNetwork(output, networkNames[0])
await network.disconnect({ 'Container': container.id })
let networksToAttachSorted = tools.sortNetworksToAttach(networksToAttach)
for (var networkToAttach of networksToAttachSorted) {
let networkName = Object.keys(networkToAttach);
let network = findNetwork(output, networkName)
await network.connect({ 'Container': container.id, 'EndpointConfig': networkToAttach[networkName] })
}
}
await container.start();

@@ -60,3 +134,25 @@ services.push(container);

if (service.volumes) {
output['Binds'] = service.volumes;
output['Binds'] = [];
for (var volume of service.volumes) {
if (typeof volume === 'string' || volume instanceof String) {
output['Binds'].push(volume);
} else {
var volumestr = '';
if (volume.source && volume.target) {
volumestr += volume.source + ':' + volume.target + ':';
}
if (volume.read_only) {
volumestr += 'ro,';
}
if (volume.volume && volume.volume.nocopy) {
volumestr += 'nocopy,';
}
if (volume.bind && volume.bind.propagation) {
volumestr += volume.bind.propagation + ',';
}
volumestr = volumestr.slice(0, -1);
output['Binds'].push(volumestr);
}
}
}

@@ -84,2 +180,10 @@

return output;
}
var findNetwork = function (output, name) {
for (var network of output.networks) {
if (network.name == name)
return network.network
}
}

@@ -8,3 +8,3 @@ module.exports = {

for (var serviceName of serviceNames) {
if(order.indexOf(serviceName) === -1) {
if (order.indexOf(serviceName) === -1) {
insertService(serviceName, recipe.services[serviceName].depends_on || [], order)

@@ -15,2 +15,26 @@ }

return order;
},
'sortNetworksToAttach': function (networksToAttach) {
var networksToAttachSorted = [];
for (let i = 0; i < networksToAttach.length; i++) {
let networkName = Object.keys(networksToAttach[i]);
if (i === 0) {
networksToAttachSorted.push(networksToAttach[i])
} else {
let aux = 0;
for (let j = 0; j < networksToAttachSorted.length; j++) {
let networkNameSorted = Object.keys(networksToAttachSorted[j]);
if (networksToAttachSorted[j][networkNameSorted].priority > networksToAttach[i][networkName].priority) {
aux += j + 1;
} else if (networksToAttachSorted[j][networkNameSorted].priority < networksToAttach[i][networkName].priority) {
aux += j - 1;
} else {
aux += j + 1;
}
}
if (aux < 0) aux = 0;
networksToAttachSorted.splice(aux, 0, networksToAttach[i]);
}
}
return networksToAttachSorted
}

@@ -17,0 +41,0 @@ }

2

package.json
{
"name": "dockerode-compose",
"version": "1.0.2",
"version": "1.0.3",
"description": "docker-compose in nodejs using dockerode",

@@ -5,0 +5,0 @@ "main": "./compose.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc