Skip to content

Commit

Permalink
Merge pull request #38 from AndreasHeine/main
Browse files Browse the repository at this point in the history
fix: connecting to external networks
  • Loading branch information
apocas authored Sep 23, 2023
2 parents 3953a19 + 5faad45 commit 50518c6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 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
22 changes: 20 additions & 2 deletions lib/servicesTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,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 +518,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 50518c6

Please sign in to comment.