mirror of
https://github.com/caprover/caprover
synced 2025-12-14 15:25:41 +00:00
Added capability to delete multiple apps
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
## [Next Version - available as `edge`]
|
## [Next Version - available as `edge`]
|
||||||
|
|
||||||
|
- New: Ability to delete multiple apps at once
|
||||||
- Improved: Now the redirects include the path
|
- Improved: Now the redirects include the path
|
||||||
- Improved: SSH key handling to avoid human mistakes
|
- Improved: SSH key handling to avoid human mistakes
|
||||||
|
|
||||||
|
|||||||
@@ -249,14 +249,24 @@ router.post('/delete/', function (req, res, next) {
|
|||||||
const serviceManager =
|
const serviceManager =
|
||||||
InjectionExtractor.extractUserFromInjected(res).user.serviceManager
|
InjectionExtractor.extractUserFromInjected(res).user.serviceManager
|
||||||
|
|
||||||
const appName = req.body.appName
|
const appName: string = req.body.appName
|
||||||
const volumes = req.body.volumes || []
|
const volumes: string[] = req.body.volumes || []
|
||||||
|
const appNames: string[] = req.body.appNames || []
|
||||||
|
const appsToDelete: string[] = appNames.length ? appNames : [appName]
|
||||||
|
|
||||||
Logger.d(`Deleting app started: ${appName}`)
|
Logger.d(`Deleting app started: ${appName}`)
|
||||||
|
|
||||||
Promise.resolve()
|
Promise.resolve()
|
||||||
.then(function () {
|
.then(function () {
|
||||||
return serviceManager.removeApp(appName)
|
if (appNames.length > 0 && appName) {
|
||||||
|
throw ApiStatusCodes.createError(
|
||||||
|
ApiStatusCodes.ILLEGAL_OPERATION,
|
||||||
|
'Either appName or appNames should be provided'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(function () {
|
||||||
|
return serviceManager.removeApps(appsToDelete)
|
||||||
})
|
})
|
||||||
.then(function () {
|
.then(function () {
|
||||||
return Utils.getDelayedPromise(volumes.length ? 12000 : 0)
|
return Utils.getDelayedPromise(volumes.length ? 12000 : 0)
|
||||||
@@ -265,7 +275,7 @@ router.post('/delete/', function (req, res, next) {
|
|||||||
return serviceManager.removeVolsSafe(volumes)
|
return serviceManager.removeVolsSafe(volumes)
|
||||||
})
|
})
|
||||||
.then(function (failedVolsToRemoved) {
|
.then(function (failedVolsToRemoved) {
|
||||||
Logger.d(`AppName is deleted: ${appName}`)
|
Logger.d(`Successfully deleted: ${appsToDelete.join(', ')}`)
|
||||||
|
|
||||||
if (failedVolsToRemoved.length) {
|
if (failedVolsToRemoved.length) {
|
||||||
const returnVal = new BaseApi(
|
const returnVal = new BaseApi(
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ import Logger from '../utils/Logger'
|
|||||||
import Utils from '../utils/Utils'
|
import Utils from '../utils/Utils'
|
||||||
import Authenticator from './Authenticator'
|
import Authenticator from './Authenticator'
|
||||||
import DockerRegistryHelper from './DockerRegistryHelper'
|
import DockerRegistryHelper from './DockerRegistryHelper'
|
||||||
|
import ImageMaker, { BuildLogsManager } from './ImageMaker'
|
||||||
import { EventLogger } from './events/EventLogger'
|
import { EventLogger } from './events/EventLogger'
|
||||||
import {
|
import {
|
||||||
CapRoverEventFactory,
|
CapRoverEventFactory,
|
||||||
CapRoverEventType,
|
CapRoverEventType,
|
||||||
} from './events/ICapRoverEvent'
|
} from './events/ICapRoverEvent'
|
||||||
import ImageMaker, { BuildLogsManager } from './ImageMaker'
|
|
||||||
import DomainResolveChecker from './system/DomainResolveChecker'
|
import DomainResolveChecker from './system/DomainResolveChecker'
|
||||||
import LoadBalancerManager from './system/LoadBalancerManager'
|
import LoadBalancerManager from './system/LoadBalancerManager'
|
||||||
import requireFromString = require('require-from-string')
|
import requireFromString = require('require-from-string')
|
||||||
@@ -456,40 +456,51 @@ class ServiceManager {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
removeApp(appName: string) {
|
removeApps(appNames: string[]) {
|
||||||
Logger.d(`Removing service for: ${appName}`)
|
Logger.d(`Removing service for: ${appNames.join(', ')}`)
|
||||||
const self = this
|
const self = this
|
||||||
|
|
||||||
const serviceName = this.dataStore
|
const removeAppPromise = function (appName: string) {
|
||||||
.getAppsDataStore()
|
const serviceName = self.dataStore
|
||||||
.getServiceName(appName)
|
.getAppsDataStore()
|
||||||
const dockerApi = this.dockerApi
|
.getServiceName(appName)
|
||||||
const dataStore = this.dataStore
|
const dockerApi = self.dockerApi
|
||||||
|
const dataStore = self.dataStore
|
||||||
|
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(function () {
|
.then(function () {
|
||||||
return self.ensureNotBuilding(appName)
|
return self.ensureNotBuilding(appName)
|
||||||
})
|
})
|
||||||
.then(function () {
|
.then(function () {
|
||||||
Logger.d(`Check if service is running: ${serviceName}`)
|
Logger.d(`Check if service is running: ${serviceName}`)
|
||||||
return dockerApi.isServiceRunningByName(serviceName)
|
return dockerApi.isServiceRunningByName(serviceName)
|
||||||
})
|
})
|
||||||
.then(function (isRunning) {
|
.then(function (isRunning) {
|
||||||
if (isRunning) {
|
if (isRunning) {
|
||||||
return dockerApi.removeServiceByName(serviceName)
|
return dockerApi.removeServiceByName(serviceName)
|
||||||
} else {
|
} else {
|
||||||
Logger.w(
|
Logger.w(
|
||||||
`Cannot delete service... It is not running: ${serviceName}`
|
`Cannot delete service... It is not running: ${serviceName}`
|
||||||
)
|
)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(function () {
|
.then(function () {
|
||||||
return dataStore.getAppsDataStore().deleteAppDefinition(appName)
|
return dataStore
|
||||||
})
|
.getAppsDataStore()
|
||||||
.then(function () {
|
.deleteAppDefinition(appName)
|
||||||
return self.reloadLoadBalancer()
|
})
|
||||||
})
|
.then(function () {
|
||||||
|
return self.reloadLoadBalancer()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const promises = []
|
||||||
|
for (const appName of appNames) {
|
||||||
|
promises.push(removeAppPromise(appName))
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.all(promises)
|
||||||
}
|
}
|
||||||
|
|
||||||
removeVolsSafe(volumes: string[]) {
|
removeVolsSafe(volumes: string[]) {
|
||||||
|
|||||||
@@ -89,14 +89,14 @@ class LoadBalancerManager {
|
|||||||
consumeQueueIfAnyInNginxReloadQueue() {
|
consumeQueueIfAnyInNginxReloadQueue() {
|
||||||
const self = this
|
const self = this
|
||||||
|
|
||||||
const q = self.requestedReloadPromises.pop()
|
if (self.reloadInProcess) {
|
||||||
|
Logger.d('NGINX Reload already in process, Bouncing off...')
|
||||||
if (!q) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.reloadInProcess) {
|
const q = self.requestedReloadPromises.pop()
|
||||||
Logger.d('NGINX Reload already in process, Bouncing off...')
|
|
||||||
|
if (!q) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user