Use oldest custom domain in deployment requests

This commit is contained in:
IshaVenikar 2025-01-30 16:13:28 +05:30
parent 5d9c965f54
commit 82c4b71694
2 changed files with 28 additions and 1 deletions

View File

@ -603,6 +603,25 @@ export class Database {
return domains; return domains;
} }
async getOldestDomainByProjectId(
projectId: string,
): Promise<Domain[]> {
const domainRepository = this.dataSource.getRepository(Domain);
const domains = await domainRepository.find({
where: {
project: {
id: projectId
},
},
order: {
createdAt: 'ASC'
}
});
return domains;
}
async getLatestDNSDataByProjectId( async getLatestDNSDataByProjectId(
projectId: string, projectId: string,
): Promise<DNSRecordAttributes | null> { ): Promise<DNSRecordAttributes | null> {

View File

@ -663,6 +663,14 @@ export class Service {
const address = await this.getAddress(); const address = await this.getAddress();
const { repo, repoUrl } = await getRepoDetails(octokit, data.project.repository, data.commitHash); const { repo, repoUrl } = await getRepoDetails(octokit, data.project.repository, data.commitHash);
const environmentVariablesObj = await this.getEnvVariables(data.project!.id!); const environmentVariablesObj = await this.getEnvVariables(data.project!.id!);
// If a custom domain is present then use that as the DNS in the deployment request
const domain = await this.db.getOldestDomainByProjectId(data.projectId!);
let dns: string | undefined = undefined;
if (domain) {
dns = domain[0].name;
}
// To set project DNS // To set project DNS
if (data.environment === Environment.Production) { if (data.environment === Environment.Production) {
// On deleting deployment later, project DNS deployment is also deleted // On deleting deployment later, project DNS deployment is also deleted
@ -690,7 +698,7 @@ export class Service {
lrn: deployer!.deployerLrn!, lrn: deployer!.deployerLrn!,
apiUrl: deployer!.deployerApiUrl!, apiUrl: deployer!.deployerApiUrl!,
environmentVariables: environmentVariablesObj, environmentVariables: environmentVariablesObj,
dns: `${newDeployment.project.name}-${newDeployment.id}`, dns: dns || `${newDeployment.project.name}-${newDeployment.id}`,
payment: data.project.txHash, payment: data.project.txHash,
auctionId: data.project.auctionId, auctionId: data.project.auctionId,
requesterAddress: address, requesterAddress: address,