Compare commits
9 Commits
main
...
iv-multi-c
Author | SHA1 | Date | |
---|---|---|---|
|
b5d84470ff | ||
|
4476de6faf | ||
|
5c9437bf1a | ||
|
baaf0a2dd8 | ||
|
d75be96d70 | ||
|
285d0e86bf | ||
|
13cc0f8b9b | ||
|
93b74074a3 | ||
|
b0d3c0593a |
@ -613,26 +613,27 @@ export class Database {
|
||||
id: projectId
|
||||
},
|
||||
...filter
|
||||
}
|
||||
},
|
||||
order: {
|
||||
createdAt: 'DESC',
|
||||
},
|
||||
});
|
||||
|
||||
return domains;
|
||||
}
|
||||
|
||||
async getOldestDomainByProjectId(
|
||||
projectId: string,
|
||||
): Promise<Domain | null> {
|
||||
async getOldestDomainByProjectId(projectId: string): Promise<Domain | null> {
|
||||
const domainRepository = this.dataSource.getRepository(Domain);
|
||||
|
||||
const domain = await domainRepository.findOne({
|
||||
where: {
|
||||
project: {
|
||||
id: projectId
|
||||
id: projectId,
|
||||
},
|
||||
},
|
||||
order: {
|
||||
createdAt: 'ASC'
|
||||
}
|
||||
createdAt: 'ASC',
|
||||
},
|
||||
});
|
||||
|
||||
return domain;
|
||||
|
@ -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[];
|
||||
}
|
||||
|
@ -345,10 +345,11 @@ export const createResolvers = async (service: Service): Promise<any> => {
|
||||
{
|
||||
projectId,
|
||||
deploymentId,
|
||||
}: { deploymentId: string; projectId: string },
|
||||
deployerId,
|
||||
}: { deploymentId: string; projectId: string, deployerId: string },
|
||||
) => {
|
||||
try {
|
||||
return await service.rollbackDeployment(projectId, deploymentId);
|
||||
return await service.rollbackDeployment(projectId, deploymentId, deployerId);
|
||||
} catch (err) {
|
||||
log(err);
|
||||
return false;
|
||||
|
@ -111,6 +111,7 @@ type Deployment {
|
||||
isCurrent: Boolean!
|
||||
baseDomain: String
|
||||
status: DeploymentStatus!
|
||||
dnsRecordData: DNSRecordAttributes
|
||||
createdAt: String!
|
||||
updatedAt: String!
|
||||
createdBy: User!
|
||||
@ -271,8 +272,8 @@ type AppDeploymentRecordAttributes {
|
||||
}
|
||||
|
||||
input AuctionParams {
|
||||
maxPrice: String,
|
||||
numProviders: Int,
|
||||
maxPrice: String
|
||||
numProviders: Int
|
||||
}
|
||||
|
||||
type Query {
|
||||
|
@ -7,7 +7,12 @@ import { DateTime } from 'luxon';
|
||||
import { OAuthApp } from '@octokit/oauth-app';
|
||||
|
||||
import { Database } from './database';
|
||||
import { ApplicationRecord, Deployment, DeploymentStatus, Environment } from './entity/Deployment';
|
||||
import {
|
||||
ApplicationRecord,
|
||||
Deployment,
|
||||
DeploymentStatus,
|
||||
Environment,
|
||||
} from './entity/Deployment';
|
||||
import { Domain } from './entity/Domain';
|
||||
import { EnvironmentVariable } from './entity/EnvironmentVariable';
|
||||
import { Organization } from './entity/Organization';
|
||||
@ -119,7 +124,8 @@ export class Service {
|
||||
}
|
||||
|
||||
// Fetch ApplicationDeploymentRecord for deployments
|
||||
const records = await this.laconicRegistry.getDeploymentRecords(deployments);
|
||||
const records =
|
||||
await this.laconicRegistry.getDeploymentRecords(deployments);
|
||||
log(`Found ${records.length} ApplicationDeploymentRecords`);
|
||||
|
||||
// Update deployments for which ApplicationDeploymentRecords were returned
|
||||
@ -204,7 +210,9 @@ export class Service {
|
||||
return;
|
||||
}
|
||||
|
||||
const registryRecord = await this.laconicRegistry.getRecordById(record.attributes.dns);
|
||||
const registryRecord = await this.laconicRegistry.getRecordById(
|
||||
record.attributes.dns,
|
||||
);
|
||||
|
||||
if (!registryRecord) {
|
||||
log(`DNS record not found for deployment ${deployment.id}`);
|
||||
@ -219,7 +227,7 @@ export class Service {
|
||||
resourceType: dnsRecord.attributes.resource_type,
|
||||
value: dnsRecord.attributes.value,
|
||||
version: dnsRecord.attributes.version,
|
||||
}
|
||||
};
|
||||
|
||||
deployment.applicationDeploymentRecordId = record.id;
|
||||
deployment.applicationDeploymentRecordData = record.attributes;
|
||||
@ -239,18 +247,38 @@ export class Service {
|
||||
relations: {
|
||||
project: true,
|
||||
deployer: true,
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
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
|
||||
if (previousCanonicalDeployment.url !== deployment.url) {
|
||||
await this.laconicRegistry.createApplicationDeploymentRemovalRequest({
|
||||
deploymentId: previousCanonicalDeployment.applicationDeploymentRecordId!,
|
||||
deployerLrn: previousCanonicalDeployment.deployer.deployerLrn,
|
||||
auctionId: previousCanonicalDeployment.project.auctionId,
|
||||
payment: previousCanonicalDeployment.project.txHash
|
||||
});
|
||||
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 isMatch = [...previousDnsSet].some((item) => newDnsSet.has(item));
|
||||
|
||||
if (!isMatch) {
|
||||
await this.laconicRegistry.createApplicationDeploymentRemovalRequest(
|
||||
{
|
||||
deploymentId:
|
||||
previousCanonicalDeployment.applicationDeploymentRecordId!,
|
||||
deployerLrn: previousCanonicalDeployment.deployer.deployerLrn,
|
||||
auctionId: previousCanonicalDeployment.project.auctionId,
|
||||
payment: previousCanonicalDeployment.project.txHash,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
await this.db.deleteDeploymentById(previousCanonicalDeployment.id);
|
||||
@ -261,7 +289,9 @@ export class Service {
|
||||
|
||||
// Release deployer funds on successful deployment
|
||||
if (!deployment.project.fundsReleased) {
|
||||
const fundsReleased = await this.releaseDeployerFundsByProjectId(deployment.projectId);
|
||||
const fundsReleased = await this.releaseDeployerFundsByProjectId(
|
||||
deployment.projectId,
|
||||
);
|
||||
|
||||
// Return remaining amount to owner
|
||||
await this.returnUserFundsByProjectId(deployment.projectId, true);
|
||||
@ -485,12 +515,17 @@ export class Service {
|
||||
return dbProjects;
|
||||
}
|
||||
|
||||
async getNonCanonicalDeploymentsByProjectId(projectId: string): Promise<Deployment[]> {
|
||||
const nonCanonicalDeployments = await this.db.getNonCanonicalDeploymentsByProjectId(projectId);
|
||||
async getNonCanonicalDeploymentsByProjectId(
|
||||
projectId: string,
|
||||
): Promise<Deployment[]> {
|
||||
const nonCanonicalDeployments =
|
||||
await this.db.getNonCanonicalDeploymentsByProjectId(projectId);
|
||||
return nonCanonicalDeployments;
|
||||
}
|
||||
|
||||
async getLatestDNSRecordByProjectId(projectId: string): Promise<DNSRecordAttributes | null> {
|
||||
async getLatestDNSRecordByProjectId(
|
||||
projectId: string,
|
||||
): Promise<DNSRecordAttributes | null> {
|
||||
const dnsRecord = await this.db.getLatestDNSRecordByProjectId(projectId);
|
||||
return dnsRecord;
|
||||
}
|
||||
@ -644,14 +679,23 @@ export class Service {
|
||||
|
||||
const octokit = await this.getOctokit(user.id);
|
||||
|
||||
const newDeployment = await this.createDeployment(user.id, octokit, {
|
||||
project: oldDeployment.project,
|
||||
branch: oldDeployment.branch,
|
||||
environment: Environment.Production,
|
||||
commitHash: oldDeployment.commitHash,
|
||||
commitMessage: oldDeployment.commitMessage,
|
||||
deployer: oldDeployment.deployer
|
||||
});
|
||||
let newDeployment: Deployment;
|
||||
|
||||
if (oldDeployment.project.auctionId) {
|
||||
newDeployment = await this.createDeploymentFromAuction(
|
||||
oldDeployment.project,
|
||||
oldDeployment.deployer,
|
||||
);
|
||||
} else {
|
||||
newDeployment = await this.createDeployment(user.id, octokit, {
|
||||
project: oldDeployment.project,
|
||||
branch: oldDeployment.branch,
|
||||
environment: Environment.Production,
|
||||
commitHash: oldDeployment.commitHash,
|
||||
commitMessage: oldDeployment.commitMessage,
|
||||
deployer: oldDeployment.deployer,
|
||||
});
|
||||
}
|
||||
|
||||
return newDeployment;
|
||||
}
|
||||
@ -660,7 +704,7 @@ export class Service {
|
||||
userId: string,
|
||||
octokit: Octokit,
|
||||
data: DeepPartial<Deployment>,
|
||||
deployerLrn?: string
|
||||
deployerLrn?: string,
|
||||
): Promise<Deployment> {
|
||||
assert(data.project?.repository, 'Project repository not found');
|
||||
log(
|
||||
@ -683,34 +727,56 @@ export class Service {
|
||||
deployer = data.deployer;
|
||||
}
|
||||
|
||||
const deployment = await this.createDeploymentFromData(userId, data, deployer!.deployerLrn!, applicationRecordId, applicationRecordData, false);
|
||||
const deployment = await this.createDeploymentFromData(
|
||||
userId,
|
||||
data,
|
||||
deployer!.deployerLrn!,
|
||||
applicationRecordId,
|
||||
applicationRecordData,
|
||||
false,
|
||||
);
|
||||
|
||||
const address = await this.getAddress();
|
||||
const { repo, repoUrl } = await getRepoDetails(octokit, data.project.repository, data.commitHash);
|
||||
const environmentVariablesObj = await this.getEnvVariables(data.project!.id!);
|
||||
const { repo, repoUrl } = await getRepoDetails(
|
||||
octokit,
|
||||
data.project.repository,
|
||||
data.commitHash,
|
||||
);
|
||||
const environmentVariablesObj = await this.getEnvVariables(
|
||||
data.project!.id!,
|
||||
);
|
||||
|
||||
// To set project DNS
|
||||
if (data.environment === Environment.Production) {
|
||||
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!);
|
||||
const canonicalDeployment = await this.createDeploymentFromData(
|
||||
userId,
|
||||
data,
|
||||
deployer!.deployerLrn!,
|
||||
applicationRecordId,
|
||||
applicationRecordData,
|
||||
true,
|
||||
);
|
||||
|
||||
const dns = await this.getDnsForDeployerByProjectId(data.project.id!, deployer!.version, 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
|
||||
const { applicationDeploymentRequestData, applicationDeploymentRequestId } =
|
||||
await this.laconicRegistry.createApplicationDeploymentRequest({
|
||||
deployment: canonicalDeployment,
|
||||
appName: repo,
|
||||
repository: repoUrl,
|
||||
environmentVariables: environmentVariablesObj,
|
||||
dns: customDomain?.name ?? `${canonicalDeployment.project.name}`,
|
||||
lrn: deployer!.deployerLrn!,
|
||||
apiUrl: deployer!.deployerApiUrl!,
|
||||
payment: data.project.txHash,
|
||||
auctionId: data.project.auctionId,
|
||||
requesterAddress: address,
|
||||
publicKey: deployer!.publicKey!
|
||||
});
|
||||
const {
|
||||
applicationDeploymentRequestData,
|
||||
applicationDeploymentRequestId,
|
||||
} = await this.laconicRegistry.createApplicationDeploymentRequest({
|
||||
deployment: canonicalDeployment,
|
||||
appName: repo,
|
||||
repository: repoUrl,
|
||||
environmentVariables: environmentVariablesObj,
|
||||
dns,
|
||||
lrn: deployer!.deployerLrn!,
|
||||
apiUrl: deployer!.deployerApiUrl!,
|
||||
payment: data.project.txHash,
|
||||
auctionId: data.project.auctionId,
|
||||
requesterAddress: address,
|
||||
publicKey: deployer!.publicKey!,
|
||||
});
|
||||
|
||||
await this.db.updateDeploymentById(canonicalDeployment.id, {
|
||||
applicationDeploymentRequestId,
|
||||
@ -730,7 +796,7 @@ export class Service {
|
||||
payment: data.project.txHash,
|
||||
auctionId: data.project.auctionId,
|
||||
requesterAddress: address,
|
||||
publicKey: deployer!.publicKey!
|
||||
publicKey: deployer!.publicKey!,
|
||||
});
|
||||
|
||||
await this.db.updateDeploymentById(deployment.id, {
|
||||
@ -743,7 +809,7 @@ export class Service {
|
||||
|
||||
async createDeploymentFromAuction(
|
||||
project: DeepPartial<Project>,
|
||||
deployer: Deployer
|
||||
deployer: Deployer,
|
||||
): Promise<Deployment> {
|
||||
const octokit = await this.getOctokit(project.ownerId!);
|
||||
const [owner, repo] = project.repository!.split('/');
|
||||
@ -769,7 +835,7 @@ export class Service {
|
||||
const applicationRecordId = record.id;
|
||||
const applicationRecordData = record.attributes;
|
||||
|
||||
const deployerLrn = deployer!.deployerLrn
|
||||
const deployerLrn = deployer!.deployerLrn;
|
||||
|
||||
// Create deployment with prod branch and latest commit
|
||||
const deploymentData = {
|
||||
@ -781,31 +847,49 @@ export class Service {
|
||||
commitMessage: latestCommit.commit.message,
|
||||
};
|
||||
|
||||
const deployment = await this.createDeploymentFromData(project.ownerId!, deploymentData, deployerLrn, applicationRecordId, applicationRecordData, false);
|
||||
const deployment = await this.createDeploymentFromData(
|
||||
project.ownerId!,
|
||||
deploymentData,
|
||||
deployerLrn,
|
||||
applicationRecordId,
|
||||
applicationRecordData,
|
||||
false,
|
||||
);
|
||||
|
||||
const address = await this.getAddress();
|
||||
|
||||
const environmentVariablesObj = await this.getEnvVariables(project!.id!);
|
||||
// To set project DNS
|
||||
if (deploymentData.environment === Environment.Production) {
|
||||
const canonicalDeployment = 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!);
|
||||
const dns = await this.getDnsForDeployerByProjectId(project.id!, deployer.version, 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
|
||||
const { applicationDeploymentRequestId, applicationDeploymentRequestData } =
|
||||
await this.laconicRegistry.createApplicationDeploymentRequest({
|
||||
deployment: canonicalDeployment,
|
||||
appName: repo,
|
||||
repository: repoUrl,
|
||||
environmentVariables: environmentVariablesObj,
|
||||
dns: customDomain?.name ?? `${canonicalDeployment.project.name}`,
|
||||
auctionId: project.auctionId!,
|
||||
lrn: deployerLrn,
|
||||
apiUrl: deployer!.deployerApiUrl!,
|
||||
requesterAddress: address,
|
||||
publicKey: deployer!.publicKey!
|
||||
});
|
||||
const {
|
||||
applicationDeploymentRequestId,
|
||||
applicationDeploymentRequestData,
|
||||
} = await this.laconicRegistry.createApplicationDeploymentRequest({
|
||||
deployment: canonicalDeployment,
|
||||
appName: repo,
|
||||
repository: repoUrl,
|
||||
environmentVariables: environmentVariablesObj,
|
||||
dns,
|
||||
auctionId: project.auctionId!,
|
||||
lrn: deployerLrn,
|
||||
apiUrl: deployer!.deployerApiUrl!,
|
||||
requesterAddress: address,
|
||||
publicKey: deployer!.publicKey!,
|
||||
});
|
||||
|
||||
await this.db.updateDeploymentById(canonicalDeployment.id, {
|
||||
applicationDeploymentRequestId,
|
||||
@ -825,7 +909,7 @@ export class Service {
|
||||
environmentVariables: environmentVariablesObj,
|
||||
dns: `${deployment.project.name}-${deployment.id}`,
|
||||
requesterAddress: address,
|
||||
publicKey: deployer!.publicKey!
|
||||
publicKey: deployer!.publicKey!,
|
||||
});
|
||||
|
||||
await this.db.updateDeploymentById(deployment.id, {
|
||||
@ -859,7 +943,7 @@ export class Service {
|
||||
deployer: Object.assign(new Deployer(), {
|
||||
deployerLrn,
|
||||
}),
|
||||
isCanonical
|
||||
isCanonical,
|
||||
});
|
||||
|
||||
log(`Created deployment ${newDeployment.id}`);
|
||||
@ -869,11 +953,11 @@ export class Service {
|
||||
|
||||
async updateProjectWithDeployer(
|
||||
projectId: string,
|
||||
deployer: Deployer
|
||||
deployer: Deployer,
|
||||
): Promise<Deployer> {
|
||||
const deploymentProject = await this.db.getProjects({
|
||||
where: { id: projectId },
|
||||
relations: ['deployers']
|
||||
relations: ['deployers'],
|
||||
});
|
||||
|
||||
if (!deploymentProject[0].deployers) {
|
||||
@ -918,15 +1002,22 @@ export class Service {
|
||||
|
||||
const prodBranch = createdTemplateRepo.data.default_branch ?? 'main';
|
||||
|
||||
const project = await this.addProject(user, organizationSlug, {
|
||||
name: `${gitRepo.data.owner!.login}-${gitRepo.data.name}`,
|
||||
prodBranch,
|
||||
repository: gitRepo.data.full_name,
|
||||
// TODO: Set selected template
|
||||
template: 'webapp',
|
||||
paymentAddress: data.paymentAddress,
|
||||
txHash: data.txHash
|
||||
}, lrn, auctionParams, environmentVariables);
|
||||
const project = await this.addProject(
|
||||
user,
|
||||
organizationSlug,
|
||||
{
|
||||
name: `${gitRepo.data.owner!.login}-${gitRepo.data.name}`,
|
||||
prodBranch,
|
||||
repository: gitRepo.data.full_name,
|
||||
// TODO: Set selected template
|
||||
template: 'webapp',
|
||||
paymentAddress: data.paymentAddress,
|
||||
txHash: data.txHash,
|
||||
},
|
||||
lrn,
|
||||
auctionParams,
|
||||
environmentVariables,
|
||||
);
|
||||
|
||||
if (!project || !project.id) {
|
||||
throw new Error('Failed to create project from template');
|
||||
@ -985,7 +1076,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!);
|
||||
@ -1167,19 +1260,20 @@ export class Service {
|
||||
let newDeployment: Deployment;
|
||||
|
||||
if (oldDeployment.project.auctionId) {
|
||||
newDeployment = await this.createDeploymentFromAuction(oldDeployment.project, oldDeployment.deployer);
|
||||
} else {
|
||||
newDeployment = await this.createDeployment(user.id, octokit,
|
||||
{
|
||||
project: oldDeployment.project,
|
||||
// TODO: Put isCurrent field in project
|
||||
branch: oldDeployment.branch,
|
||||
environment: Environment.Production,
|
||||
commitHash: oldDeployment.commitHash,
|
||||
commitMessage: oldDeployment.commitMessage,
|
||||
deployer: oldDeployment.deployer
|
||||
}
|
||||
newDeployment = await this.createDeploymentFromAuction(
|
||||
oldDeployment.project,
|
||||
oldDeployment.deployer,
|
||||
);
|
||||
} else {
|
||||
newDeployment = await this.createDeployment(user.id, octokit, {
|
||||
project: oldDeployment.project,
|
||||
// TODO: Put isCurrent field in project
|
||||
branch: oldDeployment.branch,
|
||||
environment: Environment.Production,
|
||||
commitHash: oldDeployment.commitHash,
|
||||
commitMessage: oldDeployment.commitMessage,
|
||||
deployer: oldDeployment.deployer,
|
||||
});
|
||||
}
|
||||
|
||||
return newDeployment;
|
||||
@ -1188,6 +1282,7 @@ export class Service {
|
||||
async rollbackDeployment(
|
||||
projectId: string,
|
||||
deploymentId: string,
|
||||
deployerId: string,
|
||||
): Promise<boolean> {
|
||||
// TODO: Implement transactions
|
||||
const oldCurrentDeployment = await this.db.getDeployment({
|
||||
@ -1199,6 +1294,9 @@ export class Service {
|
||||
project: {
|
||||
id: projectId,
|
||||
},
|
||||
deployer: {
|
||||
deployerId
|
||||
},
|
||||
isCurrent: true,
|
||||
isCanonical: false,
|
||||
},
|
||||
@ -1218,23 +1316,25 @@ export class Service {
|
||||
{ isCurrent: true },
|
||||
);
|
||||
|
||||
if (!newCurrentDeploymentUpdate || !oldCurrentDeploymentUpdate){
|
||||
if (!newCurrentDeploymentUpdate || !oldCurrentDeploymentUpdate) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const newCurrentDeployment = await this.db.getDeployment({ where: { id: deploymentId }, relations: { project: true, deployer: true } });
|
||||
const newCurrentDeployment = await this.db.getDeployment({
|
||||
where: { id: deploymentId },
|
||||
relations: { project: true, deployer: true },
|
||||
});
|
||||
|
||||
if (!newCurrentDeployment) {
|
||||
throw new Error(`Deployment with Id ${deploymentId} not found`);
|
||||
}
|
||||
|
||||
const applicationDeploymentRequestData = newCurrentDeployment.applicationDeploymentRequestData;
|
||||
const applicationDeploymentRequestData =
|
||||
newCurrentDeployment.applicationDeploymentRequestData;
|
||||
|
||||
const customDomain = await this.db.getOldestDomainByProjectId(projectId);
|
||||
const dns = await this.getDnsForDeployerByProjectId(projectId, newCurrentDeployment.deployer!.version, newCurrentDeployment.project.name)
|
||||
|
||||
if (customDomain && applicationDeploymentRequestData) {
|
||||
applicationDeploymentRequestData.dns = customDomain.name
|
||||
}
|
||||
applicationDeploymentRequestData!.dns = dns
|
||||
|
||||
// Create a canonical deployment for the new current deployment
|
||||
const canonicalDeployment = await this.createDeploymentFromData(
|
||||
@ -1249,20 +1349,23 @@ export class Service {
|
||||
applicationDeploymentRequestData!.meta = JSON.stringify({
|
||||
...JSON.parse(applicationDeploymentRequestData!.meta),
|
||||
note: `Updated by Snowball @ ${DateTime.utc().toFormat(
|
||||
"EEE LLL dd HH:mm:ss 'UTC' yyyy"
|
||||
)}`
|
||||
"EEE LLL dd HH:mm:ss 'UTC' yyyy",
|
||||
)}`,
|
||||
});
|
||||
|
||||
const result = await this.laconicRegistry.publishRecord(
|
||||
applicationDeploymentRequestData,
|
||||
);
|
||||
|
||||
log(`Application deployment request record published: ${result.id}`)
|
||||
log(`Application deployment request record published: ${result.id}`);
|
||||
|
||||
const updateResult = await this.db.updateDeploymentById(canonicalDeployment.id, {
|
||||
applicationDeploymentRequestId: result.id,
|
||||
applicationDeploymentRequestData,
|
||||
});
|
||||
const updateResult = await this.db.updateDeploymentById(
|
||||
canonicalDeployment.id,
|
||||
{
|
||||
applicationDeploymentRequestId: result.id,
|
||||
applicationDeploymentRequestData,
|
||||
},
|
||||
);
|
||||
|
||||
return updateResult;
|
||||
}
|
||||
@ -1589,6 +1692,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 = {
|
||||
@ -1598,7 +1703,8 @@ export class Service {
|
||||
baseDomain,
|
||||
minimumPayment,
|
||||
paymentAddress,
|
||||
publicKey
|
||||
publicKey,
|
||||
version,
|
||||
};
|
||||
|
||||
// TODO: Update deployers table in a separate job
|
||||
@ -1637,4 +1743,28 @@ export class Service {
|
||||
|
||||
return amount === amountSent && sender === senderAddress && recipient === recipientAddress;
|
||||
}
|
||||
|
||||
async getDnsForDeployerByProjectId(projectId: string, deployerVersion: string | undefined | null, projectName: string): Promise<string> {
|
||||
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
|
||||
// TODO: Check version number
|
||||
if (deployerVersion) {
|
||||
const customDomains = await this.db.getDomainsByProjectId(
|
||||
projectId,
|
||||
);
|
||||
|
||||
dns =
|
||||
customDomains.length > 0
|
||||
? customDomains.map((d) => d.name).join(',')
|
||||
: `${projectName}`;
|
||||
} else {
|
||||
const domain = await this.db.getOldestDomainByProjectId(
|
||||
projectId
|
||||
);
|
||||
dns = domain?.name ?? `${projectName}`;
|
||||
}
|
||||
|
||||
return dns;
|
||||
}
|
||||
}
|
||||
|
@ -120,5 +120,6 @@ export interface DeployerRecord {
|
||||
publicKey: string;
|
||||
type: string;
|
||||
version: string;
|
||||
deployerVersion: string;
|
||||
};
|
||||
}
|
||||
|
@ -99,6 +99,7 @@ export const DeploymentMenu = ({
|
||||
const isRollbacked = await client.rollbackDeployment(
|
||||
project.id,
|
||||
deployment.id,
|
||||
deployment.deployer.deployerId
|
||||
);
|
||||
if (isRollbacked.rollbackDeployment) {
|
||||
await onUpdate();
|
||||
|
@ -8,13 +8,14 @@ import {
|
||||
MenuList,
|
||||
MenuItem,
|
||||
Card,
|
||||
Tooltip,
|
||||
} from '@snowballtools/material-tailwind-react-fork';
|
||||
|
||||
import EditDomainDialog from './EditDomainDialog';
|
||||
import { useGQLClient } from 'context/GQLClientContext';
|
||||
import { DeleteDomainDialog } from 'components/projects/Dialog/DeleteDomainDialog';
|
||||
import { useToast } from 'components/shared/Toast';
|
||||
import { GearIcon } from 'components/shared/CustomIcon';
|
||||
import { GearIcon, InfoRoundFilledIcon } from 'components/shared/CustomIcon';
|
||||
import { Heading } from 'components/shared/Heading';
|
||||
import { Button } from 'components/shared/Button';
|
||||
import { useParams } from 'react-router-dom';
|
||||
@ -44,7 +45,6 @@ interface DomainCardProps {
|
||||
onUpdate: () => Promise<void>;
|
||||
}
|
||||
|
||||
|
||||
const DomainCard = ({
|
||||
domains,
|
||||
domain,
|
||||
@ -56,7 +56,9 @@ const DomainCard = ({
|
||||
const { id } = useParams();
|
||||
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
|
||||
const [editDialogOpen, setEditDialogOpen] = useState(false);
|
||||
const [dnsRecord, setDnsRecord] = useState<DNSRecordAttributes | null>(null);
|
||||
const [dnsRecordsWithLRN, setDnsRecordsWithLRN] = useState<
|
||||
{ dnsRecord: DNSRecordAttributes; deployerLRN: string }[]
|
||||
>([]);
|
||||
// const [refreshStatus, SetRefreshStatus] = useState(RefreshStatus.IDLE);
|
||||
|
||||
const client = useGQLClient();
|
||||
@ -94,9 +96,26 @@ const DomainCard = ({
|
||||
return;
|
||||
}
|
||||
|
||||
const dnsRecordResponse = await client.getLatestDNSRecordByProjectId(id);
|
||||
const dnsRecordResponse = await client.getProject(id);
|
||||
|
||||
setDnsRecord(dnsRecordResponse.latestDNSRecord);
|
||||
if (!dnsRecordResponse.project) {
|
||||
return;
|
||||
}
|
||||
|
||||
const tempDNSRecords: {
|
||||
dnsRecord: DNSRecordAttributes;
|
||||
deployerLRN: string;
|
||||
}[] = [];
|
||||
for (const deployment of dnsRecordResponse.project.deployments) {
|
||||
if (deployment.dnsRecordData.value) {
|
||||
tempDNSRecords.push({
|
||||
dnsRecord: deployment.dnsRecordData,
|
||||
deployerLRN: deployment.deployer.deployerLrn,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
setDnsRecordsWithLRN(tempDNSRecords);
|
||||
};
|
||||
|
||||
fetchDNSData();
|
||||
@ -182,11 +201,16 @@ const DomainCard = ({
|
||||
<Typography variant="small">Production</Typography>
|
||||
{domain.status === DomainStatus.Pending && (
|
||||
<Card className="bg-slate-100 p-4 text-sm">
|
||||
{/* {refreshStatus === RefreshStatus.IDLE ? ( */}
|
||||
<Heading>
|
||||
^ Add these records to your domain {/* and refresh to check */}
|
||||
</Heading>
|
||||
{/* ) : refreshStatus === RefreshStatus.CHECKING ? (
|
||||
{dnsRecordsWithLRN.length ? (
|
||||
<>
|
||||
{/* {refreshStatus === RefreshStatus.IDLE ? ( */}
|
||||
<Heading>
|
||||
<p className="text-blue-gray-500 pb-3">
|
||||
^ Add these records to your domain{' '}
|
||||
{/* and refresh to check */}
|
||||
</p>
|
||||
</Heading>
|
||||
{/* ) : refreshStatus === RefreshStatus.CHECKING ? (
|
||||
<Heading className="text-blue-500">
|
||||
^ Checking records for {domain.name}
|
||||
</Heading>
|
||||
@ -199,26 +223,49 @@ const DomainCard = ({
|
||||
</div>
|
||||
)} */}
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th className="text-left">Type</th>
|
||||
<th className="text-left">Name</th>
|
||||
<th className="text-left">Value</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{dnsRecord ? (
|
||||
<tr>
|
||||
<td>{dnsRecord.resourceType}</td>
|
||||
<td>@</td>
|
||||
<td>{dnsRecord.value ?? 'Not Configured'}</td>
|
||||
</tr>
|
||||
) : (
|
||||
<p className={'text-red-500'}>DNS record data not available</p>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th className="text-left">Type</th>
|
||||
<th className="text-left">Name</th>
|
||||
<th className="text-left">Value</th>
|
||||
</tr>
|
||||
</thead>
|
||||
{dnsRecordsWithLRN.map((record) => {
|
||||
return (
|
||||
<>
|
||||
<tbody>
|
||||
<tr>
|
||||
<Tooltip
|
||||
content={
|
||||
<div>
|
||||
<p className="inline text-white">
|
||||
Service Provider:
|
||||
</p>
|
||||
<p className="text-blue-gray-300 pl-2 inline">
|
||||
{record.deployerLRN}
|
||||
</p>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<td>
|
||||
<InfoRoundFilledIcon />
|
||||
</td>
|
||||
</Tooltip>
|
||||
<td>{record.dnsRecord.resourceType}</td>
|
||||
<td>@</td>
|
||||
<td>{record.dnsRecord.value}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</>
|
||||
);
|
||||
})}
|
||||
</table>
|
||||
</>
|
||||
) : (
|
||||
<p className="text-red-500">DNS record data not available</p>
|
||||
)}
|
||||
</Card>
|
||||
)}
|
||||
|
||||
|
@ -13,6 +13,7 @@ import {
|
||||
AppDeploymentRecordAttributes,
|
||||
Deployment,
|
||||
DeploymentStatus,
|
||||
DNSRecordAttributes,
|
||||
Domain,
|
||||
DomainStatus,
|
||||
Environment,
|
||||
@ -50,6 +51,7 @@ const deployment: Deployment = {
|
||||
applicationDeploymentRequestId:
|
||||
'bafyreiaycvq6imoppnpwdve4smj6t6ql5svt5zl3x6rimu4qwyzgjorize',
|
||||
applicationDeploymentRecordData: {} as AppDeploymentRecordAttributes,
|
||||
dnsRecordData: {} as DNSRecordAttributes,
|
||||
};
|
||||
|
||||
const domains: Domain[] = [
|
||||
|
@ -60,39 +60,31 @@ const Domains = () => {
|
||||
return (
|
||||
<ProjectSettingContainer
|
||||
headingText="Domains"
|
||||
{...(!project.auctionId && {
|
||||
button: (
|
||||
<Button
|
||||
as="a"
|
||||
href="add"
|
||||
variant="secondary"
|
||||
leftIcon={<PlusIcon />}
|
||||
size="md"
|
||||
>
|
||||
Add domain
|
||||
</Button>
|
||||
),
|
||||
})}
|
||||
button={
|
||||
<Button
|
||||
as="a"
|
||||
href="add"
|
||||
variant="secondary"
|
||||
leftIcon={<PlusIcon />}
|
||||
size="md"
|
||||
>
|
||||
Add domain
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
{project.auctionId ? (
|
||||
<p className="text-gray-500">
|
||||
Custom domains not supported for auction driven deployments.
|
||||
</p>
|
||||
) : (
|
||||
domains.map((domain) => {
|
||||
return (
|
||||
<DomainCard
|
||||
domains={domains}
|
||||
domain={domain}
|
||||
key={domain.id}
|
||||
// TODO: Use github API for getting linked repository
|
||||
branches={branches}
|
||||
project={project}
|
||||
onUpdate={fetchDomains}
|
||||
/>
|
||||
);
|
||||
})
|
||||
)}
|
||||
{domains.map((domain) => {
|
||||
return (
|
||||
<DomainCard
|
||||
domains={domains}
|
||||
domain={domain}
|
||||
key={domain.id}
|
||||
// TODO: Use github API for getting linked repository
|
||||
branches={branches}
|
||||
project={project}
|
||||
onUpdate={fetchDomains}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</ProjectSettingContainer>
|
||||
);
|
||||
};
|
||||
|
@ -18,7 +18,9 @@ const Config = () => {
|
||||
const primaryDomainName = searchParams.get('name');
|
||||
const { toast, dismiss } = useToast();
|
||||
|
||||
const [dnsRecord, setDnsRecord] = useState<DNSRecordAttributes | null>(null);
|
||||
const [dnsRecordsWithLRN, setDnsRecordsWithLRN] = useState<
|
||||
{ dnsRecord: DNSRecordAttributes; deployerLRN: string }[]
|
||||
>([]);
|
||||
|
||||
const handleSubmitDomain = async () => {
|
||||
if (primaryDomainName === null) {
|
||||
@ -75,68 +77,100 @@ const Config = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
const dnsRecordResponse = await client.getLatestDNSRecordByProjectId(id);
|
||||
const dnsRecordResponse = await client.getProject(id);
|
||||
|
||||
setDnsRecord(dnsRecordResponse.latestDNSRecord);
|
||||
if (!dnsRecordResponse.project) {
|
||||
return;
|
||||
}
|
||||
|
||||
const tempDNSRecords: {
|
||||
dnsRecord: DNSRecordAttributes;
|
||||
deployerLRN: string;
|
||||
}[] = [];
|
||||
for (const deployment of dnsRecordResponse.project.deployments) {
|
||||
if (deployment.dnsRecordData.value) {
|
||||
tempDNSRecords.push({
|
||||
dnsRecord: deployment.dnsRecordData,
|
||||
deployerLRN: deployment.deployer.deployerLrn,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
setDnsRecordsWithLRN(tempDNSRecords);
|
||||
|
||||
// console.log('DNS RECORD', dnsRecordResponse)
|
||||
|
||||
// setDnsRecord({} as DNSRecordAttributes);
|
||||
};
|
||||
|
||||
fetchDNSData();
|
||||
}, [id, client]);
|
||||
|
||||
// TODO: Figure out DNS Provider if possible and update appropriatly
|
||||
// TODO: Handle case where dnsRecords only have one entry and IP address for that record is not availble
|
||||
return (
|
||||
<ProjectSettingContainer headingText="Setup domain name">
|
||||
{dnsRecord ? (
|
||||
{dnsRecordsWithLRN.length ? (
|
||||
<>
|
||||
<p className="text-blue-gray-500">
|
||||
Add the following records to your domain.
|
||||
</p>
|
||||
|
||||
<Table>
|
||||
<Table.Header>
|
||||
<Table.Row>
|
||||
<Table.ColumnHeaderCell>Type</Table.ColumnHeaderCell>
|
||||
<Table.ColumnHeaderCell>Host</Table.ColumnHeaderCell>
|
||||
<Table.ColumnHeaderCell>Value</Table.ColumnHeaderCell>
|
||||
</Table.Row>
|
||||
</Table.Header>
|
||||
|
||||
<Table.Body>
|
||||
<Table.Row>
|
||||
<Table.RowHeaderCell>
|
||||
{dnsRecord.resourceType}
|
||||
</Table.RowHeaderCell>
|
||||
<Table.Cell>@</Table.Cell>
|
||||
<Table.Cell>
|
||||
<p className={!dnsRecord.value ? 'text-red-500' : ''}>
|
||||
{dnsRecord.value ?? 'Not available'}
|
||||
</p>
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
</Table.Body>
|
||||
</Table>
|
||||
|
||||
{dnsRecord?.value && (
|
||||
<InlineNotification
|
||||
variant="info"
|
||||
title={`It can take up to 48 hours for these updates to reflect
|
||||
globally.`}
|
||||
/>
|
||||
)}
|
||||
<Button
|
||||
className="w-fit"
|
||||
disabled={!dnsRecord?.value}
|
||||
onClick={handleSubmitDomain}
|
||||
variant="primary"
|
||||
shape="default"
|
||||
rightIcon={<ArrowRightCircleIcon />}
|
||||
>
|
||||
FINISH
|
||||
</Button>
|
||||
{dnsRecordsWithLRN.map((record) => {
|
||||
if (record.dnsRecord.value) {
|
||||
return (
|
||||
<>
|
||||
<div className="pt-6">
|
||||
<p className="text-gray-100 inline">Service Provider:</p>
|
||||
<p className="text-blue-gray-500 pl-2 inline">
|
||||
{record.deployerLRN}
|
||||
</p>
|
||||
</div>
|
||||
<Table>
|
||||
<Table.Header>
|
||||
<Table.Row>
|
||||
<Table.ColumnHeaderCell>Type</Table.ColumnHeaderCell>
|
||||
<Table.ColumnHeaderCell>Host</Table.ColumnHeaderCell>
|
||||
<Table.ColumnHeaderCell>Value</Table.ColumnHeaderCell>
|
||||
</Table.Row>
|
||||
</Table.Header>
|
||||
<Table.Body>
|
||||
<Table.Row>
|
||||
<Table.RowHeaderCell>
|
||||
{record.dnsRecord.resourceType}
|
||||
</Table.RowHeaderCell>
|
||||
<Table.Cell>@</Table.Cell>
|
||||
<Table.Cell>
|
||||
<p>{record.dnsRecord.value}</p>
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
</Table.Body>
|
||||
</Table>
|
||||
</>
|
||||
);
|
||||
}
|
||||
})}
|
||||
</>
|
||||
) : (
|
||||
<p className={'text-red-500'}>DNS record data not available</p>
|
||||
)}
|
||||
{dnsRecordsWithLRN.length && (
|
||||
<InlineNotification
|
||||
variant="info"
|
||||
title={`It can take up to 48 hours for these updates to reflect
|
||||
globally.`}
|
||||
/>
|
||||
)}
|
||||
<Button
|
||||
className="w-fit"
|
||||
disabled={!dnsRecordsWithLRN.length}
|
||||
onClick={handleSubmitDomain}
|
||||
variant="primary"
|
||||
shape="default"
|
||||
rightIcon={<ArrowRightCircleIcon />}
|
||||
>
|
||||
FINISH
|
||||
</Button>
|
||||
;
|
||||
</ProjectSettingContainer>
|
||||
);
|
||||
};
|
||||
|
@ -13,6 +13,7 @@ import {
|
||||
Environment,
|
||||
Permission,
|
||||
AppDeploymentRecordAttributes,
|
||||
DNSRecordAttributes,
|
||||
} from 'gql-client';
|
||||
|
||||
export const user: User = {
|
||||
@ -112,6 +113,7 @@ export const deployment0: Deployment = {
|
||||
applicationDeploymentRequestId:
|
||||
'bafyreiaycvq6imoppnpwdve4smj6t6ql5svt5zl3x6rimu4qwyzgjorize',
|
||||
applicationDeploymentRecordData: {} as AppDeploymentRecordAttributes,
|
||||
dnsRecordData: {} as DNSRecordAttributes,
|
||||
};
|
||||
|
||||
export const project: Project = {
|
||||
|
@ -337,13 +337,15 @@ export class GQLClient {
|
||||
|
||||
async rollbackDeployment(
|
||||
projectId: string,
|
||||
deploymentId: string
|
||||
deploymentId: string,
|
||||
deployerId: string,
|
||||
): Promise<types.RollbackDeploymentResponse> {
|
||||
const { data } = await this.client.mutate({
|
||||
mutation: mutations.rollbackDeployment,
|
||||
variables: {
|
||||
projectId,
|
||||
deploymentId,
|
||||
deployerId,
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -62,11 +62,19 @@ query ($projectId: String!) {
|
||||
}
|
||||
deployer {
|
||||
baseDomain
|
||||
deployerLrn
|
||||
}
|
||||
createdBy {
|
||||
id
|
||||
name
|
||||
}
|
||||
dnsRecordData {
|
||||
name
|
||||
value
|
||||
request
|
||||
resourceType
|
||||
version
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -112,6 +112,7 @@ export type Deployment = {
|
||||
createdBy: User;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
dnsRecordData: DNSRecordAttributes;
|
||||
applicationDeploymentRequestId: string;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user