From dc3e384e500606aed5b1b6432638b7ef0cbc7fb4 Mon Sep 17 00:00:00 2001 From: Kasra Bigdeli Date: Fri, 18 Oct 2024 17:00:34 -0700 Subject: [PATCH] Added projects for one click apps --- src/api/ApiManager.ts | 4 ++- .../apps/oneclick/OneClickAppDeployManager.ts | 36 +++++++++++++++++-- .../oneclick/OneClickAppDeploymentHelper.ts | 25 +++++++++++-- 3 files changed, 59 insertions(+), 6 deletions(-) diff --git a/src/api/ApiManager.ts b/src/api/ApiManager.ts index 181e7145..f88ca324 100644 --- a/src/api/ApiManager.ts +++ b/src/api/ApiManager.ts @@ -278,7 +278,9 @@ export default class ApiManager { ) } - registerProject(selectedProject: ProjectDefinition) { + registerProject( + selectedProject: ProjectDefinition + ): Promise { const http = this.http return Promise.resolve() // .then( diff --git a/src/containers/apps/oneclick/OneClickAppDeployManager.ts b/src/containers/apps/oneclick/OneClickAppDeployManager.ts index d9fb919c..115b136d 100644 --- a/src/containers/apps/oneclick/OneClickAppDeployManager.ts +++ b/src/containers/apps/oneclick/OneClickAppDeployManager.ts @@ -92,13 +92,26 @@ export default class OneClickAppDeployManager { } else { const steps: IDeploymentStep[] = [] const capAppName = values[ONE_CLICK_APP_NAME_VAR_NAME] + + const projectMemoryCache = { projectId: '' } + + if (apps.length > 1) { + steps.push( + self.createDeploymentStepForProjectCreation( + capAppName, + projectMemoryCache + ) + ) + } + for (let index = 0; index < apps.length; index++) { const appToDeploy = apps[index] steps.push( ...self.createDeploymentStepPromises( appToDeploy.appName, appToDeploy.service, - capAppName + capAppName, + projectMemoryCache ) ) } @@ -207,11 +220,27 @@ export default class OneClickAppDeployManager { return apps } + private createDeploymentStepForProjectCreation( + capAppName: string, + projectMemoryCache: { projectId: string } + ): IDeploymentStep { + const self = this + return { + stepName: `Creating project ${capAppName}`, + stepPromise: function () { + return self.deploymentHelper.createRegisterPromiseProject( + capAppName, + projectMemoryCache + ) + }, + } + } private createDeploymentStepPromises( appName: string, dockerComposeService: IDockerComposeService, - capAppName: string + capAppName: string, + projectMemoryCache: { projectId: string } ): IDeploymentStep[] { const promises: IDeploymentStep[] = [] const self = this @@ -221,7 +250,8 @@ export default class OneClickAppDeployManager { stepPromise: function () { return self.deploymentHelper.createRegisterPromise( appName, - dockerComposeService + dockerComposeService, + projectMemoryCache ) }, }) diff --git a/src/containers/apps/oneclick/OneClickAppDeploymentHelper.ts b/src/containers/apps/oneclick/OneClickAppDeploymentHelper.ts index 21fe9523..dd2efaba 100644 --- a/src/containers/apps/oneclick/OneClickAppDeploymentHelper.ts +++ b/src/containers/apps/oneclick/OneClickAppDeploymentHelper.ts @@ -1,6 +1,7 @@ import ApiManager from '../../../api/ApiManager' import { ICaptainDefinition } from '../../../models/ICaptainDefinition' import { IDockerComposeService } from '../../../models/IOneClickAppModels' +import ProjectDefinition from '../../../models/ProjectDefinition' import DockerComposeToServiceOverride from '../../../utils/DockerComposeToServiceOverride' import Utils from '../../../utils/Utils' import { IAppDef } from '../AppDefinition' @@ -10,19 +11,39 @@ export default class OneClickAppDeploymentHelper { createRegisterPromise( appName: string, - dockerComposeService: IDockerComposeService + dockerComposeService: IDockerComposeService, + projectMemoryCache: { projectId: string } ) { const self = this return Promise.resolve().then(function () { return self.apiManager.registerNewApp( appName, - '', + projectMemoryCache.projectId, !!dockerComposeService.volumes && !!dockerComposeService.volumes.length, false ) }) } + createRegisterPromiseProject( + appName: string, + projectMemoryCache: { projectId: string } + ) { + const self = this + return Promise.resolve().then(function () { + const projectDef: ProjectDefinition = { + id: '', + name: appName, + description: ``, + } + // change backend to ensure this returns project ID + return self.apiManager + .registerProject(projectDef) + .then(function (data) { + projectMemoryCache.projectId = data.id + }) + }) + } createConfigurationPromise( appName: string,