Create Deployer entity

This commit is contained in:
Adw8 2024-10-17 11:28:22 +05:30 committed by IshaVenikar
parent ef26f9b39e
commit 510e0de654
5 changed files with 45 additions and 17 deletions

View File

@ -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;
}

View File

@ -13,6 +13,7 @@ import {
import { Project } from './Project'; import { Project } from './Project';
import { Domain } from './Domain'; import { Domain } from './Domain';
import { User } from './User'; import { User } from './User';
import { Deployer } from './Deployer';
import { AppDeploymentRecordAttributes, AppDeploymentRemovalRecordAttributes } from '../types'; import { AppDeploymentRecordAttributes, AppDeploymentRemovalRecordAttributes } from '../types';
export enum Environment { export enum Environment {
@ -127,8 +128,9 @@ export class Deployment {
@Column('simple-json', { nullable: true }) @Column('simple-json', { nullable: true })
applicationDeploymentRemovalRecordData!: AppDeploymentRemovalRecordAttributes | null; applicationDeploymentRemovalRecordData!: AppDeploymentRemovalRecordAttributes | null;
@Column('varchar') @ManyToOne(() => Deployer)
deployerLrn!: string; @JoinColumn({ name: 'deployerId' })
deployer!: Deployer;
@Column({ @Column({
enum: Environment enum: Environment

View File

@ -104,7 +104,7 @@ type Deployment {
commitMessage: String! commitMessage: String!
url: String url: String
environment: Environment! environment: Environment!
deployerLrn: String deployerId: String
isCurrent: Boolean! isCurrent: Boolean!
baseDomain: String baseDomain: String
status: DeploymentStatus! status: DeploymentStatus!
@ -132,6 +132,15 @@ type EnvironmentVariable {
updatedAt: String! updatedAt: String!
} }
type Deployer {
deployerId: String!
deployerLrn: String!
deployerApiUrl: String!
createdAt: String!
updatedAt: String!
}
type AuthResult { type AuthResult {
token: String! token: String!
} }

View File

@ -14,6 +14,7 @@ import { Project } from './entity/Project';
import { Permission, ProjectMember } from './entity/ProjectMember'; import { Permission, ProjectMember } from './entity/ProjectMember';
import { User } from './entity/User'; import { User } from './entity/User';
import { Registry } from './registry'; import { Registry } from './registry';
import { Deployer } from './entity/Deployer';
import { GitHubConfig, RegistryConfig } from './config'; import { GitHubConfig, RegistryConfig } from './config';
import { import {
AddProjectFromTemplateInput, AddProjectFromTemplateInput,
@ -235,7 +236,7 @@ export class Service {
for (const deployment of prodDeployments) { for (const deployment of prodDeployments) {
const projectDeployments = await this.db.getDeploymentsByProjectId(deployment.projectId); const projectDeployments = await this.db.getDeploymentsByProjectId(deployment.projectId);
const oldDeployments = projectDeployments 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) { for (const oldDeployment of oldDeployments) {
await this.db.updateDeployment( await this.db.updateDeployment(
{ id: oldDeployment.id }, { id: oldDeployment.id },
@ -587,7 +588,7 @@ export class Service {
domain: prodBranchDomains[0], domain: prodBranchDomains[0],
commitHash: oldDeployment.commitHash, commitHash: oldDeployment.commitHash,
commitMessage: oldDeployment.commitMessage, commitMessage: oldDeployment.commitMessage,
deployerLrn: oldDeployment.deployerLrn deployer: oldDeployment.deployer
}); });
return newDeployment; 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 { repo, repoUrl } = await getRepoDetails(octokit, data.project.repository, data.commitHash);
const environmentVariablesObj = await this.getEnvVariables(data.project!.id!); const environmentVariablesObj = await this.getEnvVariables(data.project!.id!);
@ -639,7 +640,7 @@ export class Service {
repository: repoUrl, repository: repoUrl,
environmentVariables: environmentVariablesObj, environmentVariables: environmentVariablesObj,
dns: `${newDeployment.project.name}`, dns: `${newDeployment.project.name}`,
lrn: data.deployerLrn! lrn: data.deployer!.deployerLrn!
}); });
} }
@ -648,7 +649,7 @@ export class Service {
deployment: newDeployment, deployment: newDeployment,
appName: repo, appName: repo,
repository: repoUrl, repository: repoUrl,
lrn: data.deployerLrn!, lrn: data.deployer!.deployerLrn!,
environmentVariables: environmentVariablesObj, environmentVariables: environmentVariablesObj,
dns: `${newDeployment.project.name}-${newDeployment.id}`, dns: `${newDeployment.project.name}-${newDeployment.id}`,
}); });
@ -740,7 +741,7 @@ export class Service {
async createDeploymentFromData( async createDeploymentFromData(
userId: string, userId: string,
data: DeepPartial<Deployment>, data: DeepPartial<Deployment>,
deployerLrn: string, deployerId: string,
applicationRecordId: string, applicationRecordId: string,
applicationRecordData: ApplicationRecord, applicationRecordData: ApplicationRecord,
): Promise<Deployment> { ): Promise<Deployment> {
@ -757,7 +758,9 @@ export class Service {
createdBy: Object.assign(new User(), { createdBy: Object.assign(new User(), {
id: userId, id: userId,
}), }),
deployerLrn, deployer: Object.assign(new Deployer(), {
deployerId,
}),
}); });
log(`Created deployment ${newDeployment.id}`); log(`Created deployment ${newDeployment.id}`);
@ -936,6 +939,7 @@ export class Service {
branch, branch,
}); });
// TODO: Store deployer in project
const deployers = project.deployerLrns; const deployers = project.deployerLrns;
if (!deployers) { if (!deployers) {
log(`No deployer present for project ${project.id}`) log(`No deployer present for project ${project.id}`)
@ -955,7 +959,7 @@ export class Service {
domain, domain,
commitHash: headCommit.id, commitHash: headCommit.id,
commitMessage: headCommit.message, commitMessage: headCommit.message,
deployerLrn: deployer // deployer: deployer
}, },
); );
} }
@ -1011,8 +1015,7 @@ export class Service {
let newDeployment: Deployment; let newDeployment: Deployment;
if (oldDeployment.project.auctionId) { if (oldDeployment.project.auctionId) {
// TODO: Discuss creating applicationRecord for redeployments newDeployment = await this.createDeploymentFromAuction(oldDeployment.project, oldDeployment.deployer.deployerLrn);
newDeployment = await this.createDeploymentFromAuction(oldDeployment.project, oldDeployment.deployerLrn);
} else { } else {
newDeployment = await this.createDeployment(user.id, octokit, newDeployment = await this.createDeployment(user.id, octokit,
{ {
@ -1023,7 +1026,7 @@ export class Service {
domain: oldDeployment.domain, domain: oldDeployment.domain,
commitHash: oldDeployment.commitHash, commitHash: oldDeployment.commitHash,
commitMessage: oldDeployment.commitMessage, commitMessage: oldDeployment.commitMessage,
deployerLrn: oldDeployment.deployerLrn deployer: oldDeployment.deployer
} }
); );
} }
@ -1101,14 +1104,14 @@ export class Service {
await this.laconicRegistry.createApplicationDeploymentRemovalRequest({ await this.laconicRegistry.createApplicationDeploymentRemovalRequest({
deploymentId: latestRecord.id, deploymentId: latestRecord.id,
deployerLrn: deployment.deployerLrn deployerLrn: deployment.deployer.deployerLrn
}); });
} }
const result = const result =
await this.laconicRegistry.createApplicationDeploymentRemovalRequest({ await this.laconicRegistry.createApplicationDeploymentRemovalRequest({
deploymentId: deployment.applicationDeploymentRecordId, deploymentId: deployment.applicationDeploymentRecordId,
deployerLrn: deployment.deployerLrn deployerLrn: deployment.deployer.deployerLrn
}); });
await this.db.updateDeploymentById(deployment.id, { await this.db.updateDeploymentById(deployment.id, {

View File

@ -308,4 +308,4 @@ const Configure = () => {
); );
}; };
export default Configure; export default Configure;