From 510e0de654f6af1dbe6a63a2a6101fc9fc892611 Mon Sep 17 00:00:00 2001 From: Adw8 Date: Thu, 17 Oct 2024 11:28:22 +0530 Subject: [PATCH] Create Deployer entity --- packages/backend/src/entity/Deployer.ts | 14 +++++++++ packages/backend/src/entity/Deployment.ts | 6 ++-- packages/backend/src/schema.gql | 11 ++++++- packages/backend/src/service.ts | 29 ++++++++++--------- .../components/projects/create/Configure.tsx | 2 +- 5 files changed, 45 insertions(+), 17 deletions(-) create mode 100644 packages/backend/src/entity/Deployer.ts diff --git a/packages/backend/src/entity/Deployer.ts b/packages/backend/src/entity/Deployer.ts new file mode 100644 index 00000000..056ed64c --- /dev/null +++ b/packages/backend/src/entity/Deployer.ts @@ -0,0 +1,14 @@ +import { Entity, PrimaryColumn, Column, OneToMany } from 'typeorm'; +import { Deployment } from './Deployment'; + +@Entity() +export class Deployer { + @PrimaryColumn() + deployerId!: string; + + @Column() + deployerLrn!: string; + + @Column() + deployerApiUrl!: string; +} diff --git a/packages/backend/src/entity/Deployment.ts b/packages/backend/src/entity/Deployment.ts index 0036aed9..68c731d7 100644 --- a/packages/backend/src/entity/Deployment.ts +++ b/packages/backend/src/entity/Deployment.ts @@ -13,6 +13,7 @@ import { import { Project } from './Project'; import { Domain } from './Domain'; import { User } from './User'; +import { Deployer } from './Deployer'; import { AppDeploymentRecordAttributes, AppDeploymentRemovalRecordAttributes } from '../types'; export enum Environment { @@ -127,8 +128,9 @@ export class Deployment { @Column('simple-json', { nullable: true }) applicationDeploymentRemovalRecordData!: AppDeploymentRemovalRecordAttributes | null; - @Column('varchar') - deployerLrn!: string; + @ManyToOne(() => Deployer) + @JoinColumn({ name: 'deployerId' }) + deployer!: Deployer; @Column({ enum: Environment diff --git a/packages/backend/src/schema.gql b/packages/backend/src/schema.gql index 8c222fb2..897de44c 100644 --- a/packages/backend/src/schema.gql +++ b/packages/backend/src/schema.gql @@ -104,7 +104,7 @@ type Deployment { commitMessage: String! url: String environment: Environment! - deployerLrn: String + deployerId: String isCurrent: Boolean! baseDomain: String status: DeploymentStatus! @@ -132,6 +132,15 @@ type EnvironmentVariable { updatedAt: String! } +type Deployer { + deployerId: String! + deployerLrn: String! + deployerApiUrl: String! + createdAt: String! + updatedAt: String! +} + + type AuthResult { token: String! } diff --git a/packages/backend/src/service.ts b/packages/backend/src/service.ts index 3f7e7f98..baa86b87 100644 --- a/packages/backend/src/service.ts +++ b/packages/backend/src/service.ts @@ -14,6 +14,7 @@ import { Project } from './entity/Project'; import { Permission, ProjectMember } from './entity/ProjectMember'; import { User } from './entity/User'; import { Registry } from './registry'; +import { Deployer } from './entity/Deployer'; import { GitHubConfig, RegistryConfig } from './config'; import { AddProjectFromTemplateInput, @@ -235,7 +236,7 @@ export class Service { for (const deployment of prodDeployments) { const projectDeployments = await this.db.getDeploymentsByProjectId(deployment.projectId); const oldDeployments = projectDeployments - .filter(projectDeployment => projectDeployment.deployerLrn === deployment.deployerLrn && projectDeployment.id !== deployment.id); + .filter(projectDeployment => projectDeployment.deployer.deployerLrn === deployment.deployer.deployerLrn && projectDeployment.id !== deployment.id); for (const oldDeployment of oldDeployments) { await this.db.updateDeployment( { id: oldDeployment.id }, @@ -587,7 +588,7 @@ export class Service { domain: prodBranchDomains[0], commitHash: oldDeployment.commitHash, commitMessage: oldDeployment.commitMessage, - deployerLrn: oldDeployment.deployerLrn + deployer: oldDeployment.deployer }); return newDeployment; @@ -625,7 +626,7 @@ export class Service { ); } - const newDeployment = await this.createDeploymentFromData(userId, data, data.deployerLrn!, applicationRecordId, applicationRecordData); + const newDeployment = await this.createDeploymentFromData(userId, data, data.deployer!.deployerId!, applicationRecordId, applicationRecordData); const { repo, repoUrl } = await getRepoDetails(octokit, data.project.repository, data.commitHash); const environmentVariablesObj = await this.getEnvVariables(data.project!.id!); @@ -639,7 +640,7 @@ export class Service { repository: repoUrl, environmentVariables: environmentVariablesObj, dns: `${newDeployment.project.name}`, - lrn: data.deployerLrn! + lrn: data.deployer!.deployerLrn! }); } @@ -648,7 +649,7 @@ export class Service { deployment: newDeployment, appName: repo, repository: repoUrl, - lrn: data.deployerLrn!, + lrn: data.deployer!.deployerLrn!, environmentVariables: environmentVariablesObj, dns: `${newDeployment.project.name}-${newDeployment.id}`, }); @@ -740,7 +741,7 @@ export class Service { async createDeploymentFromData( userId: string, data: DeepPartial, - deployerLrn: string, + deployerId: string, applicationRecordId: string, applicationRecordData: ApplicationRecord, ): Promise { @@ -757,7 +758,9 @@ export class Service { createdBy: Object.assign(new User(), { id: userId, }), - deployerLrn, + deployer: Object.assign(new Deployer(), { + deployerId, + }), }); log(`Created deployment ${newDeployment.id}`); @@ -936,6 +939,7 @@ export class Service { branch, }); + // TODO: Store deployer in project const deployers = project.deployerLrns; if (!deployers) { log(`No deployer present for project ${project.id}`) @@ -955,7 +959,7 @@ export class Service { domain, commitHash: headCommit.id, commitMessage: headCommit.message, - deployerLrn: deployer + // deployer: deployer }, ); } @@ -1011,8 +1015,7 @@ export class Service { let newDeployment: Deployment; if (oldDeployment.project.auctionId) { - // TODO: Discuss creating applicationRecord for redeployments - newDeployment = await this.createDeploymentFromAuction(oldDeployment.project, oldDeployment.deployerLrn); + newDeployment = await this.createDeploymentFromAuction(oldDeployment.project, oldDeployment.deployer.deployerLrn); } else { newDeployment = await this.createDeployment(user.id, octokit, { @@ -1023,7 +1026,7 @@ export class Service { domain: oldDeployment.domain, commitHash: oldDeployment.commitHash, commitMessage: oldDeployment.commitMessage, - deployerLrn: oldDeployment.deployerLrn + deployer: oldDeployment.deployer } ); } @@ -1101,14 +1104,14 @@ export class Service { await this.laconicRegistry.createApplicationDeploymentRemovalRequest({ deploymentId: latestRecord.id, - deployerLrn: deployment.deployerLrn + deployerLrn: deployment.deployer.deployerLrn }); } const result = await this.laconicRegistry.createApplicationDeploymentRemovalRequest({ deploymentId: deployment.applicationDeploymentRecordId, - deployerLrn: deployment.deployerLrn + deployerLrn: deployment.deployer.deployerLrn }); await this.db.updateDeploymentById(deployment.id, { diff --git a/packages/frontend/src/components/projects/create/Configure.tsx b/packages/frontend/src/components/projects/create/Configure.tsx index 7d81ee77..ac08ae2b 100644 --- a/packages/frontend/src/components/projects/create/Configure.tsx +++ b/packages/frontend/src/components/projects/create/Configure.tsx @@ -308,4 +308,4 @@ const Configure = () => { ); }; -export default Configure; +export default Configure; \ No newline at end of file