Rename variables for canonical deployments

This commit is contained in:
IshaVenikar 2025-02-04 14:50:45 +05:30
parent 6a2a8bb3c4
commit 2c71b8c95f
2 changed files with 30 additions and 34 deletions

View File

@ -414,12 +414,8 @@ export class Registry {
* Fetch record by Id
*/
async getRecordById(id: string): Promise<RegistryRecord | null> {
const record = await this.registry.getRecordsByIds([id]);
if (record.length === 0) {
return null;
}
return record[0];
const [record] = await this.registry.getRecordsByIds([id]);
return record ?? null;
}
async createApplicationDeploymentRemovalRequest(data: {

View File

@ -229,7 +229,7 @@ export class Service {
deployment.dnsRecordData = dnsRecordData;
if (deployment.isCanonical) {
const oldDNSDeployment = await this.db.getDeployment({
const previousCanonicalDeployment = await this.db.getDeployment({
where: {
projectId: deployment.project.id,
deployer: deployment.deployer,
@ -242,18 +242,18 @@ export class Service {
}
});
if (oldDNSDeployment) {
// Send removal request for the previous DNS deployment and delete DB entry
if (oldDNSDeployment.url !== deployment.url) {
if (previousCanonicalDeployment) {
// Send removal request for the previous canonical deployment and delete DB entry
if (previousCanonicalDeployment.url !== deployment.url) {
await this.laconicRegistry.createApplicationDeploymentRemovalRequest({
deploymentId: oldDNSDeployment.applicationDeploymentRecordId!,
deployerLrn: oldDNSDeployment.deployer.deployerLrn,
auctionId: oldDNSDeployment.project.auctionId,
payment: oldDNSDeployment.project.txHash
deploymentId: previousCanonicalDeployment.applicationDeploymentRecordId!,
deployerLrn: previousCanonicalDeployment.deployer.deployerLrn,
auctionId: previousCanonicalDeployment.project.auctionId,
payment: previousCanonicalDeployment.project.txHash
});
}
await this.db.deleteDeploymentById(oldDNSDeployment.id);
await this.db.deleteDeploymentById(previousCanonicalDeployment.id);
}
}
@ -691,7 +691,7 @@ export class Service {
// To set project DNS
if (data.environment === Environment.Production) {
const dnsDeployment = await this.createDeploymentFromData(userId, data, deployer!.deployerLrn!, applicationRecordId, applicationRecordData, true);
const canonicalDeployment = await this.createDeploymentFromData(userId, data, deployer!.deployerLrn!, applicationRecordId, applicationRecordData, true);
// If a custom domain is present then use that as the DNS in the deployment request
const customDomain = await this.db.getOldestDomainByProjectId(data.project!.id!);
@ -699,11 +699,11 @@ export class Service {
// So publish project DNS deployment first so that ApplicationDeploymentRecord for the same is available when deleting deployment later
const { applicationDeploymentRequestData, applicationDeploymentRequestId } =
await this.laconicRegistry.createApplicationDeploymentRequest({
deployment: dnsDeployment,
deployment: canonicalDeployment,
appName: repo,
repository: repoUrl,
environmentVariables: environmentVariablesObj,
dns: customDomain?.name ?? `${dnsDeployment.project.name}`,
dns: customDomain?.name ?? `${canonicalDeployment.project.name}`,
lrn: deployer!.deployerLrn!,
apiUrl: deployer!.deployerApiUrl!,
payment: data.project.txHash,
@ -712,7 +712,7 @@ export class Service {
publicKey: deployer!.publicKey!
});
await this.db.updateDeploymentById(dnsDeployment.id, {
await this.db.updateDeploymentById(canonicalDeployment.id, {
applicationDeploymentRequestId,
applicationDeploymentRequestData,
});
@ -787,7 +787,7 @@ export class Service {
const environmentVariablesObj = await this.getEnvVariables(project!.id!);
// To set project DNS
if (deploymentData.environment === Environment.Production) {
const dnsDeployment = await this.createDeploymentFromData(project.ownerId!, deploymentData, deployerLrn, applicationRecordId, applicationRecordData, true);
const canonicalDeployment = await this.createDeploymentFromData(project.ownerId!, deploymentData, deployerLrn, applicationRecordId, applicationRecordData, true);
// If a custom domain is present then use that as the DNS in the deployment request
const customDomain = await this.db.getOldestDomainByProjectId(project!.id!);
@ -795,11 +795,11 @@ export class Service {
// So publish project DNS deployment first so that ApplicationDeploymentRecord for the same is available when deleting deployment later
const { applicationDeploymentRequestId, applicationDeploymentRequestData } =
await this.laconicRegistry.createApplicationDeploymentRequest({
deployment: dnsDeployment,
deployment: canonicalDeployment,
appName: repo,
repository: repoUrl,
environmentVariables: environmentVariablesObj,
dns: customDomain?.name ?? `${dnsDeployment.project.name}`,
dns: customDomain?.name ?? `${canonicalDeployment.project.name}`,
auctionId: project.auctionId!,
lrn: deployerLrn,
apiUrl: deployer!.deployerApiUrl!,
@ -807,7 +807,7 @@ export class Service {
publicKey: deployer!.publicKey!
});
await this.db.updateDeploymentById(dnsDeployment.id, {
await this.db.updateDeploymentById(canonicalDeployment.id, {
applicationDeploymentRequestId,
applicationDeploymentRequestData,
});
@ -1232,8 +1232,8 @@ export class Service {
applicationDeploymentRequestData.dns = customDomain.name
}
// Create a DNS deployment for the new current deployment
const dnsDeployment = await this.createDeploymentFromData(
// Create a canonical deployment for the new current deployment
const canonicalDeployment = await this.createDeploymentFromData(
newCurrentDeployment.project.ownerId,
newCurrentDeployment,
newCurrentDeployment.deployer!.deployerLrn!,
@ -1255,7 +1255,7 @@ export class Service {
log(`Application deployment request record published: ${result.id}`)
await this.db.updateDeploymentById(dnsDeployment.id, {
await this.db.updateDeploymentById(canonicalDeployment.id, {
applicationDeploymentRequestId: result.id,
applicationDeploymentRequestData,
});
@ -1277,7 +1277,7 @@ export class Service {
if (deployment && deployment.applicationDeploymentRecordId) {
// If deployment is current, remove deployment for project subdomain as well
if (deployment.isCurrent) {
const dnsDeployment = await this.db.getDeployment({
const canonicalDeployment = await this.db.getDeployment({
where: {
projectId: deployment.project.id,
deployer: deployment.deployer,
@ -1289,21 +1289,21 @@ export class Service {
},
})
if (!dnsDeployment) {
log(`DNS deployment for deployment with id ${deployment.id} not found`);
if (!canonicalDeployment) {
log(`Canonical deployment for deployment with id ${deployment.id} not found`);
return false;
}
const dnsResult =
await this.laconicRegistry.createApplicationDeploymentRemovalRequest({
deploymentId: dnsDeployment.applicationDeploymentRecordId!,
deployerLrn: dnsDeployment.deployer.deployerLrn,
auctionId: dnsDeployment.project.auctionId,
payment: dnsDeployment.project.txHash
deploymentId: canonicalDeployment.applicationDeploymentRecordId!,
deployerLrn: canonicalDeployment.deployer.deployerLrn,
auctionId: canonicalDeployment.project.auctionId,
payment: canonicalDeployment.project.txHash
});
await this.db.updateDeploymentById(dnsDeployment.id, {
await this.db.updateDeploymentById(canonicalDeployment.id, {
status: DeploymentStatus.Deleting,
applicationDeploymentRemovalRequestId:
dnsResult.applicationDeploymentRemovalRequestId,