diff --git a/packages/backend/src/database.ts b/packages/backend/src/database.ts index 03455332..7b9a0b25 100644 --- a/packages/backend/src/database.ts +++ b/packages/backend/src/database.ts @@ -619,6 +619,23 @@ export class Database { return domains; } + async getOldestDomainByProjectId(projectId: string): Promise { + const domainRepository = this.dataSource.getRepository(Domain); + + const domain = await domainRepository.findOne({ + where: { + project: { + id: projectId, + }, + }, + order: { + createdAt: 'ASC', + }, + }); + + return domain; + } + async getLatestDNSRecordByProjectId( projectId: string, ): Promise { diff --git a/packages/backend/src/entity/Deployer.ts b/packages/backend/src/entity/Deployer.ts index 72f386ca..452337d1 100644 --- a/packages/backend/src/entity/Deployer.ts +++ b/packages/backend/src/entity/Deployer.ts @@ -24,6 +24,9 @@ export class Deployer { @Column('varchar', { nullable: true }) paymentAddress!: string | null; + @Column('varchar', { nullable: true }) + version!: string | null; + @ManyToMany(() => Project, (project) => project.deployers) projects!: Project[]; } diff --git a/packages/backend/src/schema.gql b/packages/backend/src/schema.gql index 1404adef..575b67d7 100644 --- a/packages/backend/src/schema.gql +++ b/packages/backend/src/schema.gql @@ -272,8 +272,8 @@ type AppDeploymentRecordAttributes { } input AuctionParams { - maxPrice: String, - numProviders: Int, + maxPrice: String + numProviders: Int } type Query { diff --git a/packages/backend/src/service.ts b/packages/backend/src/service.ts index 4d889077..638e1020 100644 --- a/packages/backend/src/service.ts +++ b/packages/backend/src/service.ts @@ -253,13 +253,20 @@ export class Service { if (previousCanonicalDeployment) { // 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 - const previousDnsList = previousCanonicalDeployment.applicationDeploymentRequestData?.dns || ""; - const newDnsList = deployment.applicationDeploymentRequestData?.dns || ""; + const previousDnsList = + previousCanonicalDeployment.applicationDeploymentRequestData?.dns || + ''; + const newDnsList = + deployment.applicationDeploymentRequestData?.dns || ''; - const previousDnsSet = new Set(previousDnsList.split(",").map(item => item.trim())); - const newDnsSet = new Set(newDnsList.split(",").map(item => item.trim())); + const previousDnsSet = new Set( + 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) { await this.laconicRegistry.createApplicationDeploymentRemovalRequest( @@ -674,7 +681,10 @@ export class Service { let newDeployment: Deployment; if (oldDeployment.project.auctionId) { - newDeployment = await this.createDeploymentFromAuction(oldDeployment.project, oldDeployment.deployer); + newDeployment = await this.createDeploymentFromAuction( + oldDeployment.project, + oldDeployment.deployer, + ); } else { newDeployment = await this.createDeployment(user.id, octokit, { project: oldDeployment.project, @@ -745,14 +755,25 @@ export class Service { applicationRecordData, true, ); + + let dns; // If a custom domain is present then use that as the DNS in the deployment request - const customDomains = await this.db.getDomainsByProjectId( - data.project!.id!, - ); - const dns = - customDomains.length > 0 - ? customDomains.map((d) => d.name).join(',') - : `${canonicalDeployment.project.name}`; + // 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 // 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, commitMessage: latestCommit.commit.message, }; + const { applicationDeploymentAuctionId } = await this.laconicRegistry.createApplicationDeploymentAuction(repo, octokit, auctionParams!, deploymentData); + await this.updateProject(project.id, { auctionId: applicationDeploymentAuctionId }); } else { const deployer = await this.db.getDeployerByLRN(lrn!); @@ -1690,6 +1713,8 @@ export class Service { const minimumPayment = record.attributes.minimumPayment; const paymentAddress = record.attributes.paymentAddress; const publicKey = record.attributes.publicKey; + const version = record.attributes.deployerVersion; + const baseDomain = deployerApiUrl.substring(deployerApiUrl.indexOf('.') + 1); const deployerData = { @@ -1699,7 +1724,8 @@ export class Service { baseDomain, minimumPayment, paymentAddress, - publicKey + publicKey, + version, }; // TODO: Update deployers table in a separate job diff --git a/packages/backend/src/types.ts b/packages/backend/src/types.ts index f02998ff..63ff4581 100644 --- a/packages/backend/src/types.ts +++ b/packages/backend/src/types.ts @@ -120,5 +120,6 @@ export interface DeployerRecord { publicKey: string; type: string; version: string; + deployerVersion: string; }; }