Update rollback flow to handle multiple custom domains

This commit is contained in:
IshaVenikar 2025-02-06 12:06:21 +05:30
parent 5c9437bf1a
commit 4476de6faf

View File

@ -320,7 +320,7 @@ export class Service {
const oldDeployments = projectDeployments.filter( const oldDeployments = projectDeployments.filter(
(projectDeployment) => (projectDeployment) =>
projectDeployment.deployer.deployerLrn === projectDeployment.deployer.deployerLrn ===
deployment.deployer.deployerLrn && deployment.deployer.deployerLrn &&
projectDeployment.id !== deployment.id && projectDeployment.id !== deployment.id &&
projectDeployment.isCanonical == deployment.isCanonical, projectDeployment.isCanonical == deployment.isCanonical,
); );
@ -756,24 +756,7 @@ export class Service {
true, true,
); );
let dns; const dns = await this.getDnsForDeployerByProjectId(data.project.id!, deployer!.version, canonicalDeployment.project.name)
// If a custom domain is present then use that as the DNS in the deployment request
// Only deployers with version > 1 support multiple custom domains
if (deployer!.version && Number(deployer!.version) >= 1) {
const customDomains = await this.db.getDomainsByProjectId(
data.project.id!,
);
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
@ -1349,13 +1332,9 @@ export class Service {
const applicationDeploymentRequestData = const applicationDeploymentRequestData =
newCurrentDeployment.applicationDeploymentRequestData; newCurrentDeployment.applicationDeploymentRequestData;
const customDomains = await this.db.getDomainsByProjectId(projectId); const dns = await this.getDnsForDeployerByProjectId(projectId, newCurrentDeployment.deployer!.version, newCurrentDeployment.project.name)
if (customDomains.length > 0 && applicationDeploymentRequestData) { applicationDeploymentRequestData!.dns = dns
applicationDeploymentRequestData.dns = customDomains
.map((d) => d.name)
.join(',');
}
// Create a canonical deployment for the new current deployment // Create a canonical deployment for the new current deployment
const canonicalDeployment = await this.createDeploymentFromData( const canonicalDeployment = await this.createDeploymentFromData(
@ -1764,4 +1743,27 @@ export class Service {
return amount === amountSent && sender === senderAddress && recipient === recipientAddress; return amount === amountSent && sender === senderAddress && recipient === recipientAddress;
} }
async getDnsForDeployerByProjectId(projectId: string, deployerVersion: string | undefined | null, projectName: string): Promise<string> {
let dns;
// If a custom domain is present then use that as the DNS in the deployment request
// Only deployers with version > 1 support multiple custom domains
if (deployerVersion && Number(deployerVersion) >= 1) {
const customDomains = await this.db.getDomainsByProjectId(
projectId,
);
dns =
customDomains.length > 0
? customDomains.map((d) => d.name).join(',')
: `${projectName}`;
} else {
const domain = await this.db.getOldestDomainByProjectId(
projectId
);
dns = domain?.name ?? `${projectName}`;
}
return dns;
}
} }