mirror of
https://github.com/caprover/caprover
synced 2026-05-06 03:30:29 +00:00
added support for mapping ports to the backend
This commit is contained in:
@@ -392,7 +392,7 @@ class DataStore {
|
||||
});
|
||||
}
|
||||
|
||||
updateAppDefinitionInDb(appName, instanceCount, envVars, volumes, nodeId, notExposeAsWebApp) {
|
||||
updateAppDefinitionInDb(appName, instanceCount, envVars, volumes, nodeId, notExposeAsWebApp, ports) {
|
||||
const self = this;
|
||||
|
||||
return this.getAppDefinition(appName)
|
||||
@@ -404,6 +404,32 @@ class DataStore {
|
||||
app.notExposeAsWebApp = !!notExposeAsWebApp;
|
||||
app.nodeId = nodeId;
|
||||
|
||||
if (ports) {
|
||||
|
||||
function isPortValid(portNumber) {
|
||||
return portNumber > 0 && portNumber < 65535;
|
||||
}
|
||||
|
||||
let tempPorts = [];
|
||||
for (let i = 0; i < ports.length; i++) {
|
||||
let obj = ports[i];
|
||||
if (obj.containerPort && obj.hostPort) {
|
||||
|
||||
let containerPort = Number(obj.containerPort);
|
||||
let hostPort = Number(obj.hostPort);
|
||||
|
||||
if (isPortValid(containerPort) && isPortValid(hostPort)) {
|
||||
tempPorts.push({
|
||||
hostPort: hostPort,
|
||||
containerPort: containerPort
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
app.ports = tempPorts;
|
||||
}
|
||||
|
||||
if (envVars) {
|
||||
app.envVars = [];
|
||||
for (let i = 0; i < envVars.length; i++) {
|
||||
@@ -660,6 +686,7 @@ class DataStore {
|
||||
networks: [CaptainConstants.captainNetworkName],
|
||||
envVars: [],
|
||||
volumes: [],
|
||||
ports: [],
|
||||
versions: []
|
||||
};
|
||||
|
||||
|
||||
@@ -897,7 +897,7 @@ class DockerApi {
|
||||
* @param namespace: String 'captain' or null
|
||||
* @returns {Promise.<>}
|
||||
*/
|
||||
updateService(serviceName, imageName, volumes, networks, arrayOfEnvKeyAndValue, secrets, authObject, instanceCount, nodeId, namespace) {
|
||||
updateService(serviceName, imageName, volumes, networks, arrayOfEnvKeyAndValue, secrets, authObject, instanceCount, nodeId, namespace, ports) {
|
||||
const self = this;
|
||||
return self.dockerode
|
||||
.getService(serviceName)
|
||||
@@ -938,6 +938,19 @@ class DockerApi {
|
||||
}
|
||||
}
|
||||
|
||||
if (ports) {
|
||||
updatedData.EndpointSpec = updatedData.EndpointSpec || {};
|
||||
updatedData.EndpointSpec.Ports = [];
|
||||
for (let i = 0; i < ports.length; i++) {
|
||||
let p = ports[i];
|
||||
updatedData.EndpointSpec.Ports.push({
|
||||
Protocol: 'tcp',
|
||||
TargetPort: p.containerPort,
|
||||
PublishedPort: p.hostPort
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (volumes) {
|
||||
let mts = [];
|
||||
for (let idx = 0; idx < volumes.length; idx++) {
|
||||
|
||||
@@ -301,11 +301,12 @@ router.post('/update/', function (req, res, next) {
|
||||
let notExposeAsWebApp = req.body.notExposeAsWebApp;
|
||||
let envVars = req.body.envVars || [];
|
||||
let volumes = req.body.volumes || [];
|
||||
let ports = req.body.ports || [];
|
||||
let instanceCount = req.body.instanceCount || '0';
|
||||
|
||||
Logger.d('Updating app started: ' + appName);
|
||||
|
||||
serviceManager.updateAppDefinition(appName, Number(instanceCount), envVars, volumes, nodeId, notExposeAsWebApp)
|
||||
serviceManager.updateAppDefinition(appName, Number(instanceCount), envVars, volumes, nodeId, notExposeAsWebApp, ports)
|
||||
.then(function () {
|
||||
|
||||
Logger.d('AppName is updated: ' + appName);
|
||||
|
||||
@@ -630,7 +630,7 @@ class ServiceManager {
|
||||
});
|
||||
}
|
||||
|
||||
updateAppDefinition(appName, instanceCount, envVars, volumes, nodeId, notExposeAsWebApp) {
|
||||
updateAppDefinition(appName, instanceCount, envVars, volumes, nodeId, notExposeAsWebApp, ports) {
|
||||
|
||||
const self = this;
|
||||
const dataStore = this.dataStore;
|
||||
@@ -712,7 +712,7 @@ class ServiceManager {
|
||||
})
|
||||
.then(function () {
|
||||
|
||||
return dataStore.updateAppDefinitionInDb(appName, instanceCount, envVars, volumes, nodeId, notExposeAsWebApp);
|
||||
return dataStore.updateAppDefinitionInDb(appName, instanceCount, envVars, volumes, nodeId, notExposeAsWebApp, ports);
|
||||
|
||||
})
|
||||
.then(function () {
|
||||
@@ -746,7 +746,9 @@ class ServiceManager {
|
||||
}
|
||||
|
||||
return dockerApi
|
||||
.updateService(serviceName, null, appFound.volumes, appFound.networks, appFound.envVars, null, dockerAuthObject, Number(appFound.instanceCount), appFound.nodeId, dataStore.getNameSpace());
|
||||
.updateService(serviceName, null, appFound.volumes, appFound.networks, appFound.envVars, null,
|
||||
dockerAuthObject, Number(appFound.instanceCount), appFound.nodeId, dataStore.getNameSpace(),
|
||||
appFound.ports);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ const questions = [
|
||||
type: 'input',
|
||||
default: SAMPLE_DOMAIN,
|
||||
name: 'captainAddress',
|
||||
message: 'Enter address of the Captain machine. \nIt can be in [IP]:[PORT] format or captain.[your-captain-root-domain] format:',
|
||||
message: 'Enter address of the Captain machine. \nIt is captain.[your-captain-root-domain] :',
|
||||
validate: function (value) {
|
||||
|
||||
if (value===SAMPLE_DOMAIN){
|
||||
|
||||
Reference in New Issue
Block a user