List deployer LRNs in deployment configuration step #11

Merged
nabarun merged 9 commits from iv-deployer-dropdown into main 2024-10-23 15:36:20 +00:00
8 changed files with 60 additions and 89 deletions
Showing only changes of commit 3aee4ac6f8 - Show all commits

View File

@ -590,14 +590,6 @@ export class Database {
return newDomain;
}
async getDeployerById (deployerId: string): Promise<Deployer | null> {
const deployerRepository = this.dataSource.getRepository(Deployer);
const deployer = await deployerRepository.findOne({ where: { deployerId } });
return deployer;
}
async getDeployers(): Promise<Deployer[]> {
const deployerRepository = this.dataSource.getRepository(Deployer);
const deployers = await deployerRepository.find();

View File

@ -4,10 +4,10 @@ import { Project } from './Project';
@Entity()
export class Deployer {
@PrimaryColumn('varchar')
deployerId!: string;
deployerLrn!: string;
@Column('varchar')
deployerLrn!: string;
deployerId!: string;
@Column('varchar')
deployerApiUrl!: string;

View File

@ -129,7 +129,7 @@ export class Deployment {
applicationDeploymentRemovalRecordData!: AppDeploymentRemovalRecordAttributes | null;
@ManyToOne(() => Deployer)
@JoinColumn({ name: 'deployerId' })
@JoinColumn({ name: 'deployerLrn' })
deployer!: Deployer;
@Column({

View File

@ -134,8 +134,8 @@ type EnvironmentVariable {
}
type Deployer {
deployerId: String!
deployerLrn: String!
deployerId: String!
deployerApiUrl: String!
createdAt: String!
updatedAt: String!

View File

@ -21,6 +21,7 @@ import {
AppDeploymentRecord,
AppDeploymentRemovalRecord,
AuctionParams,
DeployerRecord,
EnvironmentVariables,
GitPushEventPayload,
} from './types';
@ -309,35 +310,13 @@ export class Service {
if (!deployerRecords) {
log(`No winning deployer for auction ${project!.auctionId}`);
} else {
const deployerIds = [];
for (const record of deployerRecords) {
const deployerId = record.id;
const deployerLrn = record.names[0];
deployerIds.push(deployerId);
const deployerApiUrl = record.attributes.apiUrl;
const baseDomain = deployerApiUrl.substring(deployerApiUrl.indexOf('.') + 1);
const deployerData = {
deployerId,
deployerLrn,
deployerApiUrl,
baseDomain
};
// Store the deployer in the DB
const deployer = await this.db.addDeployer(deployerData);
const deployers = await this.saveDeployersByDeployerRecords(deployerRecords);
for (const deployer of deployers) {
log(`Creating deployment for deployer ${deployer.deployerLrn}`);
await this.createDeploymentFromAuction(project, deployer);
// Update project with deployer
await this.updateProjectWithDeployer(project.id, deployer);
}
for (const deployerId of deployerIds) {
log(`Creating deployment for deployer ${deployerId}`);
await this.createDeploymentFromAuction(project, deployerId);
}
}
}
@ -649,7 +628,7 @@ export class Service {
deployer = data.deployer;
}
const newDeployment = await this.createDeploymentFromData(userId, data, deployer!.deployerId!, applicationRecordId, applicationRecordData);
const newDeployment = await this.createDeploymentFromData(userId, data, deployer!.deployerLrn!, applicationRecordId, applicationRecordData);
const { repo, repoUrl } = await getRepoDetails(octokit, data.project.repository, data.commitHash);
const environmentVariablesObj = await this.getEnvVariables(data.project!.id!);
@ -687,7 +666,7 @@ export class Service {
async createDeploymentFromAuction(
project: DeepPartial<Project>,
deployerId: string
deployer: Deployer
): Promise<Deployment> {
const octokit = await this.getOctokit(project.ownerId!);
const [owner, repo] = project.repository!.split('/');
@ -713,7 +692,6 @@ export class Service {
const applicationRecordId = record.id;
const applicationRecordData = record.attributes;
const deployer = await this.db.getDeployerById(deployerId);
const deployerLrn = deployer!.deployerLrn
// Create deployment with prod branch and latest commit
@ -726,7 +704,7 @@ export class Service {
commitMessage: latestCommit.commit.message,
};
const newDeployment = await this.createDeploymentFromData(project.ownerId!, deploymentData, deployerId, applicationRecordId, applicationRecordData);
const newDeployment = await this.createDeploymentFromData(project.ownerId!, deploymentData, deployerLrn, applicationRecordId, applicationRecordData);
const environmentVariablesObj = await this.getEnvVariables(project!.id!);
// To set project DNS
@ -767,7 +745,7 @@ export class Service {
async createDeploymentFromData(
userId: string,
data: DeepPartial<Deployment>,
deployerId: string,
deployerLrn: string,
applicationRecordId: string,
applicationRecordData: ApplicationRecord,
): Promise<Deployment> {
@ -785,7 +763,7 @@ export class Service {
id: userId,
}),
deployer: Object.assign(new Deployer(), {
deployerId,
deployerLrn,
}),
});
@ -802,20 +780,9 @@ export class Service {
return null;
}
const deployerId = records[0].id;
const deployerApiUrl = records[0].attributes.apiUrl;
const baseDomain = deployerApiUrl.substring(deployerApiUrl.indexOf('.') + 1);
const deployer = await this.saveDeployersByDeployerRecords(records);
const deployerData = {
deployerId,
deployerLrn,
deployerApiUrl,
baseDomain
};
const deployer = await this.db.addDeployer(deployerData);
return deployer;
return deployer[0];
}
async updateProjectWithDeployer(
@ -1089,7 +1056,7 @@ export class Service {
let newDeployment: Deployment;
if (oldDeployment.project.auctionId) {
newDeployment = await this.createDeploymentFromAuction(oldDeployment.project, oldDeployment.deployer.deployerId);
newDeployment = await this.createDeploymentFromAuction(oldDeployment.project, oldDeployment.deployer);
} else {
newDeployment = await this.createDeployment(user.id, octokit,
{
@ -1374,33 +1341,45 @@ export class Service {
const dbDeployers = await this.db.getDeployers();
if (dbDeployers.length > 0) {
// Call asynchronously to fetch the records from the registry and update the DB
this.updateDeployersFromRegistry();
return dbDeployers;
} else {
// Fetch from the registry and populate empty DB
return await this.updateDeployersFromRegistry();
}
}
async updateDeployersFromRegistry(): Promise<Deployer[]> {
const deployerRecords = await this.laconicRegistry.getDeployerRecordsByFilter({});
await this.saveDeployersByDeployerRecords(deployerRecords);
return await this.db.getDeployers();
}
async saveDeployersByDeployerRecords(deployerRecords: DeployerRecord[]): Promise<Deployer[]> {
const deployers: Deployer[] = [];
for (const record of deployerRecords) {
if (record.names.length > 0) {
const deployerId = record.id;
const deployerLrn = record.names[0];
const deployerApiUrl = record.attributes.apiUrl;
const baseDomain = deployerApiUrl.substring(deployerApiUrl.indexOf('.') + 1);
const deployerData = {
deployerId,
deployerLrn,
deployerId,
deployerApiUrl,
baseDomain
};
await this.db.addDeployer(deployerData);
// TODO: Update deployers table in a separate job
const deployer = await this.db.addDeployer(deployerData);
deployers.push(deployer);
}
}
return await this.db.getDeployers();
return deployers;
}
}

View File

@ -51,7 +51,7 @@ const Configure = () => {
const client = useGQLClient();
const methods = useForm<ConfigureFormValues>({
defaultValues: { option: 'LRN' },
defaultValues: { option: 'Auction' },
});
const selectedOption = methods.watch('option');
@ -244,7 +244,7 @@ const Configure = () => {
>
{deployers.map((deployer) => (
<MenuItem key={deployer.deployerId} value={deployer.deployerLrn}>
<MenuItem key={deployer.deployerLrn} value={deployer.deployerLrn}>
{deployer.deployerLrn}
</MenuItem>
))}

View File

@ -25,9 +25,9 @@ query ($projectId: String!) {
prodBranch
auctionId
deployers {
deployerApiUrl
deployerId
deployerLrn
deployerId
deployerApiUrl
}
fundsReleased
framework
@ -81,9 +81,9 @@ query ($organizationSlug: String!) {
framework
auctionId
deployers {
deployerApiUrl
deployerId
deployerLrn
deployerId
deployerApiUrl
}
fundsReleased
prodBranch
@ -145,9 +145,9 @@ query ($projectId: String!) {
commitMessage
url
deployer {
deployerLrn
deployerId
deployerLrn,
deployerApiUrl,
deployerApiUrl
}
environment
isCurrent
@ -208,9 +208,9 @@ query ($searchText: String!) {
framework
auctionId
deployers {
deployerApiUrl
deployerId
deployerLrn
deployerId
deployerApiUrl
}
fundsReleased
prodBranch
@ -311,9 +311,9 @@ query ($auctionId: String!) {
export const getDeployers = gql`
query {
deployers {
deployerApiUrl
deployerId
deployerLrn
deployerId
deployerApiUrl
}
}
`;

View File

@ -117,9 +117,9 @@ export type Deployment = {
};
export type Deployer = {
deployerApiUrl: string;
deployerId: string;
deployerLrn: string;
deployerId: string;
deployerApiUrl: string;
}
export type OrganizationMember = {