Add check for deployer version to support multiple custom domains
This commit is contained in:
parent
baaf0a2dd8
commit
5c9437bf1a
@ -619,6 +619,23 @@ export class Database {
|
||||
return domains;
|
||||
}
|
||||
|
||||
async getOldestDomainByProjectId(projectId: string): Promise<Domain | null> {
|
||||
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<DNSRecordAttributes | null> {
|
||||
|
@ -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[];
|
||||
}
|
||||
|
@ -272,8 +272,8 @@ type AppDeploymentRecordAttributes {
|
||||
}
|
||||
|
||||
input AuctionParams {
|
||||
maxPrice: String,
|
||||
numProviders: Int,
|
||||
maxPrice: String
|
||||
numProviders: Int
|
||||
}
|
||||
|
||||
type Query {
|
||||
|
@ -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
|
||||
// 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!,
|
||||
data.project.id!,
|
||||
);
|
||||
const dns =
|
||||
|
||||
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
|
||||
|
@ -120,5 +120,6 @@ export interface DeployerRecord {
|
||||
publicKey: string;
|
||||
type: string;
|
||||
version: string;
|
||||
deployerVersion: string;
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user