Add check for deployer version to support multiple custom domains

This commit is contained in:
IshaVenikar 2025-02-06 11:49:48 +05:30
parent baaf0a2dd8
commit 5c9437bf1a
5 changed files with 63 additions and 16 deletions

View File

@ -619,6 +619,23 @@ export class Database {
return domains; return domains;
} }
async getOldestDomainByProjectId(projectId: string): Promise<Domain | null> {
const domainRepository = this.dataSource.getRepository(Domain);
const domain = await domainRepository.findOne({
where: {
project: {
id: projectId,
},
},
order: {
createdAt: 'ASC',
},
});
return domain;
}
async getLatestDNSRecordByProjectId( async getLatestDNSRecordByProjectId(
projectId: string, projectId: string,
): Promise<DNSRecordAttributes | null> { ): Promise<DNSRecordAttributes | null> {

View File

@ -24,6 +24,9 @@ export class Deployer {
@Column('varchar', { nullable: true }) @Column('varchar', { nullable: true })
paymentAddress!: string | null; paymentAddress!: string | null;
@Column('varchar', { nullable: true })
version!: string | null;
@ManyToMany(() => Project, (project) => project.deployers) @ManyToMany(() => Project, (project) => project.deployers)
projects!: Project[]; projects!: Project[];
} }

View File

@ -272,8 +272,8 @@ type AppDeploymentRecordAttributes {
} }
input AuctionParams { input AuctionParams {
maxPrice: String, maxPrice: String
numProviders: Int, numProviders: Int
} }
type Query { type Query {

View File

@ -253,13 +253,20 @@ export class Service {
if (previousCanonicalDeployment) { if (previousCanonicalDeployment) {
// If all the DNS in the previous canonical deployment request are different from the new deployment request // If all the DNS in the previous canonical deployment request are different from the new deployment request
// Send removal request for the previous canonical deployment and delete DB entry // Send removal request for the previous canonical deployment and delete DB entry
const previousDnsList = previousCanonicalDeployment.applicationDeploymentRequestData?.dns || ""; const previousDnsList =
const newDnsList = deployment.applicationDeploymentRequestData?.dns || ""; previousCanonicalDeployment.applicationDeploymentRequestData?.dns ||
'';
const newDnsList =
deployment.applicationDeploymentRequestData?.dns || '';
const previousDnsSet = new Set(previousDnsList.split(",").map(item => item.trim())); const previousDnsSet = new Set(
const newDnsSet = new Set(newDnsList.split(",").map(item => item.trim())); previousDnsList.split(',').map((item) => item.trim()),
);
const newDnsSet = new Set(
newDnsList.split(',').map((item) => item.trim()),
);
const isMatch = previousDnsSet.size === newDnsSet.size && [...previousDnsSet].every(item => newDnsSet.has(item)); const isMatch = [...previousDnsSet].some((item) => newDnsSet.has(item));
if (!isMatch) { if (!isMatch) {
await this.laconicRegistry.createApplicationDeploymentRemovalRequest( await this.laconicRegistry.createApplicationDeploymentRemovalRequest(
@ -674,7 +681,10 @@ export class Service {
let newDeployment: Deployment; let newDeployment: Deployment;
if (oldDeployment.project.auctionId) { if (oldDeployment.project.auctionId) {
newDeployment = await this.createDeploymentFromAuction(oldDeployment.project, oldDeployment.deployer); newDeployment = await this.createDeploymentFromAuction(
oldDeployment.project,
oldDeployment.deployer,
);
} else { } else {
newDeployment = await this.createDeployment(user.id, octokit, { newDeployment = await this.createDeployment(user.id, octokit, {
project: oldDeployment.project, project: oldDeployment.project,
@ -745,14 +755,25 @@ export class Service {
applicationRecordData, applicationRecordData,
true, true,
); );
let dns;
// If a custom domain is present then use that as the DNS in the deployment request // If a custom domain is present then use that as the DNS in the deployment request
const customDomains = await this.db.getDomainsByProjectId( // Only deployers with version > 1 support multiple custom domains
data.project!.id!, if (deployer!.version && Number(deployer!.version) >= 1) {
); const customDomains = await this.db.getDomainsByProjectId(
const dns = data.project.id!,
customDomains.length > 0 );
? customDomains.map((d) => d.name).join(',')
: `${canonicalDeployment.project.name}`; dns =
customDomains.length > 0
? customDomains.map((d) => d.name).join(',')
: `${canonicalDeployment.project.name}`;
} else {
const domain = await this.db.getOldestDomainByProjectId(
canonicalDeployment.project.id,
);
dns = domain?.name ?? `${canonicalDeployment.project.name}`;
}
// On deleting deployment later, project canonical deployment is also deleted // On deleting deployment later, project canonical deployment is also deleted
// So publish project canonical deployment first so that ApplicationDeploymentRecord for the same is available when deleting deployment later // So publish project canonical deployment first so that ApplicationDeploymentRecord for the same is available when deleting deployment later
@ -1072,7 +1093,9 @@ export class Service {
commitHash: latestCommit.sha, commitHash: latestCommit.sha,
commitMessage: latestCommit.commit.message, commitMessage: latestCommit.commit.message,
}; };
const { applicationDeploymentAuctionId } = await this.laconicRegistry.createApplicationDeploymentAuction(repo, octokit, auctionParams!, deploymentData); const { applicationDeploymentAuctionId } = await this.laconicRegistry.createApplicationDeploymentAuction(repo, octokit, auctionParams!, deploymentData);
await this.updateProject(project.id, { auctionId: applicationDeploymentAuctionId }); await this.updateProject(project.id, { auctionId: applicationDeploymentAuctionId });
} else { } else {
const deployer = await this.db.getDeployerByLRN(lrn!); const deployer = await this.db.getDeployerByLRN(lrn!);
@ -1690,6 +1713,8 @@ export class Service {
const minimumPayment = record.attributes.minimumPayment; const minimumPayment = record.attributes.minimumPayment;
const paymentAddress = record.attributes.paymentAddress; const paymentAddress = record.attributes.paymentAddress;
const publicKey = record.attributes.publicKey; const publicKey = record.attributes.publicKey;
const version = record.attributes.deployerVersion;
const baseDomain = deployerApiUrl.substring(deployerApiUrl.indexOf('.') + 1); const baseDomain = deployerApiUrl.substring(deployerApiUrl.indexOf('.') + 1);
const deployerData = { const deployerData = {
@ -1699,7 +1724,8 @@ export class Service {
baseDomain, baseDomain,
minimumPayment, minimumPayment,
paymentAddress, paymentAddress,
publicKey publicKey,
version,
}; };
// TODO: Update deployers table in a separate job // TODO: Update deployers table in a separate job

View File

@ -120,5 +120,6 @@ export interface DeployerRecord {
publicKey: string; publicKey: string;
type: string; type: string;
version: string; version: string;
deployerVersion: string;
}; };
} }