Skip to content

Commit

Permalink
Added projects for one click apps
Browse files Browse the repository at this point in the history
  • Loading branch information
githubsaturn committed Oct 19, 2024
1 parent 03983dd commit dc3e384
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/api/ApiManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ export default class ApiManager {
)
}

registerProject(selectedProject: ProjectDefinition) {
registerProject(
selectedProject: ProjectDefinition
): Promise<ProjectDefinition> {
const http = this.http
return Promise.resolve() //
.then(
Expand Down
36 changes: 33 additions & 3 deletions src/containers/apps/oneclick/OneClickAppDeployManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)
}
Expand Down Expand Up @@ -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
Expand All @@ -221,7 +250,8 @@ export default class OneClickAppDeployManager {
stepPromise: function () {
return self.deploymentHelper.createRegisterPromise(
appName,
dockerComposeService
dockerComposeService,
projectMemoryCache
)
},
})
Expand Down
25 changes: 23 additions & 2 deletions src/containers/apps/oneclick/OneClickAppDeploymentHelper.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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,
Expand Down

0 comments on commit dc3e384

Please sign in to comment.