mirror of
				https://github.com/caprover/caprover
				synced 2025-10-30 01:57:03 +00:00 
			
		
		
		
	Added volume legacy logic
This commit is contained in:
		| @@ -277,10 +277,6 @@ class AppsDataStore { | ||||
|         return `${appName}` | ||||
|     } | ||||
|  | ||||
|     getVolumeName(volumeName: string) { | ||||
|         return `${this.namepace}--${volumeName}` | ||||
|     } | ||||
|  | ||||
|     getAppDefinitions() { | ||||
|         const self = this | ||||
|         return new Promise<IAllAppDefinitions>(function (resolve, reject) { | ||||
|   | ||||
| @@ -1438,8 +1438,9 @@ class DockerApi { | ||||
|                             // /var/lib/docker/volumes/YOUR_VOLUME_NAME/_data | ||||
|                             mts.push({ | ||||
|                                 Source: | ||||
|                                     (namespace ? namespace + '--' : '') + | ||||
|                                     v.volumeName, | ||||
|                                     (namespace && appObject?.isLegacyAppName | ||||
|                                         ? namespace + '--' | ||||
|                                         : '') + v.volumeName, | ||||
|                                 Target: v.containerPath, | ||||
|                                 Type: VolumesTypes.VOLUME, | ||||
|                                 ReadOnly: false, | ||||
|   | ||||
| @@ -3,6 +3,7 @@ import ApiStatusCodes from '../../../../api/ApiStatusCodes' | ||||
| import BaseApi from '../../../../api/BaseApi' | ||||
| import InjectionExtractor from '../../../../injection/InjectionExtractor' | ||||
| import { AppDeployTokenConfig, IAppDef } from '../../../../models/AppDefinition' | ||||
| import { IHashMapGeneric } from '../../../../models/ICacheGeneric' | ||||
| import { ICaptainDefinition } from '../../../../models/ICaptainDefinition' | ||||
| import { CaptainError } from '../../../../models/OtherTypes' | ||||
| import CaptainManager from '../../../../user/system/CaptainManager' | ||||
| @@ -260,6 +261,8 @@ router.post('/register/', function (req, res, next) { | ||||
| router.post('/delete/', function (req, res, next) { | ||||
|     const serviceManager = | ||||
|         InjectionExtractor.extractUserFromInjected(res).user.serviceManager | ||||
|     const dataStore = | ||||
|         InjectionExtractor.extractUserFromInjected(res).user.dataStore | ||||
|  | ||||
|     const appName: string = req.body.appName | ||||
|     const volumes: string[] = req.body.volumes || [] | ||||
| @@ -267,6 +270,7 @@ router.post('/delete/', function (req, res, next) { | ||||
|     const appsToDelete: string[] = appNames.length ? appNames : [appName] | ||||
|  | ||||
|     Logger.d(`Deleting app started: ${appName}`) | ||||
|     const legacyVolumes: IHashMapGeneric<boolean> = {} | ||||
|  | ||||
|     return Promise.resolve() | ||||
|         .then(function () { | ||||
| @@ -277,6 +281,24 @@ router.post('/delete/', function (req, res, next) { | ||||
|                 ) | ||||
|             } | ||||
|         }) | ||||
|         .then(function () { | ||||
|             return dataStore.getAppsDataStore().getAppDefinitions() | ||||
|         }) | ||||
|         .then(function (apps) { | ||||
|             Object.keys(apps).forEach((appName) => { | ||||
|                 const app = apps[appName] | ||||
|                 if (app.isLegacyAppName) { | ||||
|                     const volumesForApp = app.volumes.map( | ||||
|                         (vol) => vol.volumeName | ||||
|                     ) | ||||
|                     volumesForApp.forEach((volumeName) => { | ||||
|                         if (volumeName) { | ||||
|                             legacyVolumes[volumeName] = true | ||||
|                         } | ||||
|                     }) | ||||
|                 } | ||||
|             }) | ||||
|         }) | ||||
|         .then(function () { | ||||
|             return serviceManager.removeApps(appsToDelete) | ||||
|         }) | ||||
| @@ -284,7 +306,7 @@ router.post('/delete/', function (req, res, next) { | ||||
|             return Utils.getDelayedPromise(volumes.length ? 12000 : 0) | ||||
|         }) | ||||
|         .then(function () { | ||||
|             return serviceManager.removeVolsSafe(volumes) | ||||
|             return serviceManager.removeVolsSafe(volumes, legacyVolumes) | ||||
|         }) | ||||
|         .then(function (failedVolsToRemoved) { | ||||
|             Logger.d(`Successfully deleted: ${appsToDelete.join(', ')}`) | ||||
|   | ||||
| @@ -522,7 +522,7 @@ class ServiceManager { | ||||
|         return Promise.all(promises) | ||||
|     } | ||||
|  | ||||
|     removeVolsSafe(volumes: string[]) { | ||||
|     removeVolsSafe(volumes: string[], legacyVolumes: IHashMapGeneric<boolean>) { | ||||
|         const dockerApi = this.dockerApi | ||||
|         const dataStore = this.dataStore | ||||
|  | ||||
| @@ -552,7 +552,7 @@ class ServiceManager { | ||||
|                 volumes.forEach((v) => { | ||||
|                     if (!volsFailedToDelete[v]) { | ||||
|                         volumesTryToDelete.push( | ||||
|                             dataStore.getAppsDataStore().getVolumeName(v) | ||||
|                             legacyVolumes[v] ? `captain--${v}` : v | ||||
|                         ) | ||||
|                     } | ||||
|                 }) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Kasra Bigdeli
					Kasra Bigdeli