Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
apocas committed Oct 11, 2023
2 parents 66ee1f1 + 2c34de6 commit 4082772
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ async function up(docker, projectName, recipe, output, options) {
};

if (service.networks !== undefined) {
servicesTools.buildNetworks(projectName, serviceName, service.networks, networksToAttach, opts);
servicesTools.buildNetworks(projectName, serviceName, service.networks, networksToAttach, opts, recipe.networks);
} else {
opts.HostConfig.NetworkMode = projectName + '_default';
opts.NetworkingConfig.EndpointsConfig[projectName + '_default'] = {
Expand Down
30 changes: 27 additions & 3 deletions lib/servicesTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,13 @@ module.exports = {
if (service.ports !== undefined) {
this.buildPorts(service.ports, output);
}

if (service.devices !== undefined) {
output.Devices = service.devices.map((device) => ({
CgroupPermissions: "mrw",
PathInContainer: device,
PathOnHost: device,
}));
}
if (service.cpu_count !== undefined) {
output.CpuCount = service.cpu_count;
}
Expand Down Expand Up @@ -486,10 +492,19 @@ module.exports = {
return output;
},

buildNetworks: function (projectName, serviceName, serviceNetworks, networksToAttach, opts) {
buildNetworks: function (projectName, serviceName, serviceNetworks, networksToAttach, opts, toplevelNetworks) {
if (Array.isArray(serviceNetworks)) {
for (let index = 0; index < serviceNetworks.length; index++) {
let networkName = projectName + '_' + serviceNetworks[index];
// check if network is external
if (toplevelNetworks !== undefined) {
if (Object.keys(toplevelNetworks).includes(serviceNetworks[index])) {
if (toplevelNetworks[serviceNetworks[index]].external === true) {
// it is external network
networkName = toplevelNetworks[serviceNetworks[index]].name
}
}
}
let networkTemplate = {
NetworkingConfig: {
EndpointsConfig: {},
Expand All @@ -509,7 +524,16 @@ module.exports = {
let networkNames = Object.keys(serviceNetworks);
for (let index = 0; index < networkNames.length; index++) {
let network = serviceNetworks[networkNames[index]] || {};
let networkName = projectName + '_' + networkNames[index];
let networkName = projectName + '_' + serviceNetworks[index];
// check if network is external
if (toplevelNetworks !== undefined) {
if (Object.keys(toplevelNetworks).includes(networkNames[index])) {
if (toplevelNetworks[networkNames[index]].external === true) {
// it is external network
networkName = toplevelNetworks[networkNames[index]].name
}
}
}
let networkTemplate = {
NetworkingConfig: {
EndpointsConfig: {},
Expand Down

0 comments on commit 4082772

Please sign in to comment.