diff --git a/src/apps.js b/src/apps.js index 280a4acc8..87cb8c6de 100644 --- a/src/apps.js +++ b/src/apps.js @@ -207,8 +207,9 @@ function validatePortBindings(portBindings, manifest) { // it is OK if there is no 1-1 mapping between values in manifest.tcpPorts and portBindings. missing values implies // that the user wants the service disabled const tcpPorts = manifest.tcpPorts || { }; + const udpPorts = manifest.udpPorts || { }; for (let portName in portBindings) { - if (!(portName in tcpPorts)) return new AppsError(AppsError.BAD_FIELD, `Invalid portBindings ${portName}`); + if (!(portName in tcpPorts) && !(portName in udpPorts)) return new AppsError(AppsError.BAD_FIELD, `Invalid portBindings ${portName}`); } return null; diff --git a/src/apptask.js b/src/apptask.js index 9f142fc77..45dfa5c5f 100644 --- a/src/apptask.js +++ b/src/apptask.js @@ -670,12 +670,12 @@ function update(app, callback) { // free unused ports function (next) { - // make sure we always have objects - var currentPorts = app.portBindings || {}; - var newPorts = app.updateConfig.manifest.tcpPorts || {}; + const currentPorts = app.portBindings || {}; + const newTcpPorts = app.updateConfig.manifest.tcpPorts || {}; + const newUdpPorts = app.updateConfig.manifest.udpPorts || {}; async.each(Object.keys(currentPorts), function (portName, callback) { - if (newPorts[portName]) return callback(); // port still in use + if (newTcpPorts[portName] || newUdpPorts[portName]) return callback(); // port still in use appdb.delPortBinding(currentPorts[portName], apps.PORT_TYPE_TCP, function (error) { if (error && error.reason === DatabaseError.NOT_FOUND) console.error('Portbinding does not exist in database.'); diff --git a/src/docker.js b/src/docker.js index c237d15a5..118ffe234 100644 --- a/src/docker.js +++ b/src/docker.js @@ -128,13 +128,16 @@ function createSubcontainer(app, name, cmd, options, callback) { var portEnv = []; for (let portName in app.portBindings) { - var hostPort = app.portBindings[portName]; - var containerPort = manifest.tcpPorts[portName].containerPort || hostPort; + const hostPort = app.portBindings[portName]; + const portType = portName in manifest.tcpPorts ? 'tcp' : 'udp'; + const ports = portType == 'tcp' ? manifest.tcpPorts : manifest.udpPorts; - exposedPorts[containerPort + '/tcp'] = {}; + var containerPort = ports[portName].containerPort || hostPort; + + exposedPorts[`${containerPort}/${portType}`] = {}; portEnv.push(`${portName}=${hostPort}`); - dockerPortBindings[containerPort + '/tcp'] = [ { HostIp: '0.0.0.0', HostPort: hostPort + '' } ]; + dockerPortBindings[`${containerPort}/${portType}`] = [ { HostIp: '0.0.0.0', HostPort: hostPort + '' } ]; } // first check db record, then manifest