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 * Fetch record by Id
*/ */
async getRecordById(id: string): Promise<RegistryRecord | null> { async getRecordById(id: string): Promise<RegistryRecord | null> {
const record = await this.registry.getRecordsByIds([id]); const [record] = await this.registry.getRecordsByIds([id]);
if (record.length === 0) { return record ?? null;
return null;
}
return record[0];
} }
async createApplicationDeploymentRemovalRequest(data: { async createApplicationDeploymentRemovalRequest(data: {

View File

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