Compare commits
47
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
59329c18f6 | ||
|
|
8553c30b0d | ||
|
|
b409d43e51 | ||
|
|
b50efe315b | ||
|
|
ced815802e | ||
|
|
22bb409617 | ||
|
|
8322f877c0 | ||
|
|
fd38127cb5 | ||
|
|
b6084008b8 | ||
|
|
d1e6171874 | ||
|
|
ce56a4dc29 | ||
|
|
c685b7d5b1 | ||
|
|
32001b3d5a | ||
|
|
6f32ea4da8 | ||
|
|
a16b44b43a | ||
|
|
a17386eb68 | ||
|
|
f318a95641 | ||
|
|
e9f746cd8b | ||
|
|
e59c14440c | ||
|
|
22f8a8c943 | ||
|
|
df5062c75f | ||
|
|
22e814840e | ||
|
|
9d27dd568a | ||
|
|
fc62392c83 | ||
|
|
2ee65b8fd8 | ||
|
|
d0302d0153 | ||
|
|
90e9260eb6 | ||
|
|
6dcee29487 | ||
|
|
5be10b6b0a | ||
|
|
6e8af82dc2 | ||
|
|
1a5ab4d47e | ||
|
|
6df685831f | ||
|
|
13892015a5 | ||
|
|
55500b5914 | ||
|
|
a7190ed804 | ||
|
|
6a79ee5c47 | ||
|
|
f2ba931961 | ||
|
|
85b4265fbe | ||
|
|
63223a4807 | ||
|
|
9784eb4f4a | ||
|
|
624f36155a | ||
|
|
82c4b71694 | ||
|
|
5d9c965f54 | ||
|
|
56eccb48b3 | ||
|
|
b5762432e6 | ||
|
|
4ae4670dca | ||
|
|
c202554002 |
No files matched your search
@@ -158,9 +158,10 @@ export class Database {
|
||||
.leftJoinAndSelect(
|
||||
'project.deployments',
|
||||
'deployments',
|
||||
'deployments.isCurrent = true AND deployments.isCanonical = true'
|
||||
'deployments.isCurrent = true AND deployments.isDNS = true'
|
||||
)
|
||||
.leftJoinAndSelect('deployments.createdBy', 'user')
|
||||
.leftJoinAndSelect('deployments.domain', 'domain')
|
||||
.leftJoinAndSelect('deployments.deployer', 'deployer')
|
||||
.leftJoinAndSelect('project.owner', 'owner')
|
||||
.leftJoinAndSelect('project.deployers', 'deployers')
|
||||
@@ -202,8 +203,9 @@ export class Database {
|
||||
.leftJoinAndSelect(
|
||||
'project.deployments',
|
||||
'deployments',
|
||||
'deployments.isCurrent = true AND deployments.isCanonical = true'
|
||||
'deployments.isCurrent = true AND deployments.isDNS = true'
|
||||
)
|
||||
.leftJoinAndSelect('deployments.domain', 'domain')
|
||||
.leftJoin('project.projectMembers', 'projectMembers')
|
||||
.leftJoin('project.organization', 'organization')
|
||||
.where(
|
||||
@@ -234,6 +236,7 @@ export class Database {
|
||||
return this.getDeployments({
|
||||
relations: {
|
||||
project: true,
|
||||
domain: true,
|
||||
createdBy: true,
|
||||
deployer: true,
|
||||
},
|
||||
@@ -248,10 +251,11 @@ export class Database {
|
||||
});
|
||||
}
|
||||
|
||||
async getNonCanonicalDeploymentsByProjectId(projectId: string): Promise<Deployment[]> {
|
||||
async getCommitDeploymentsByProjectId(projectId: string): Promise<Deployment[]> {
|
||||
return this.getDeployments({
|
||||
relations: {
|
||||
project: true,
|
||||
domain: true,
|
||||
createdBy: true,
|
||||
deployer: true,
|
||||
},
|
||||
@@ -259,7 +263,7 @@ export class Database {
|
||||
project: {
|
||||
id: projectId
|
||||
},
|
||||
isCanonical: false
|
||||
isDNS: false
|
||||
},
|
||||
order: {
|
||||
createdAt: 'DESC'
|
||||
@@ -613,27 +617,26 @@ 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,9 +24,6 @@ export class Deployer {
|
||||
@Column('varchar', { nullable: true })
|
||||
paymentAddress!: string | null;
|
||||
|
||||
@Column('varchar', { nullable: true })
|
||||
version!: string | null;
|
||||
|
||||
@ManyToMany(() => Project, (project) => project.deployers)
|
||||
projects!: Project[];
|
||||
}
|
||||
@@ -39,7 +39,6 @@ export interface ApplicationDeploymentRequest {
|
||||
config: string;
|
||||
meta: string;
|
||||
payment?: string;
|
||||
dns?: string;
|
||||
}
|
||||
|
||||
export interface ApplicationDeploymentRemovalRequest {
|
||||
@@ -78,6 +77,13 @@ export class Deployment {
|
||||
@JoinColumn({ name: 'projectId' })
|
||||
project!: Project;
|
||||
|
||||
@Column({ nullable: true })
|
||||
domainId!: string | null;
|
||||
|
||||
@OneToOne(() => Domain)
|
||||
@JoinColumn({ name: 'domainId' })
|
||||
domain!: Domain | null;
|
||||
|
||||
@Column('varchar')
|
||||
branch!: string;
|
||||
|
||||
@@ -135,8 +141,9 @@ export class Deployment {
|
||||
@Column('boolean', { default: false })
|
||||
isCurrent!: boolean;
|
||||
|
||||
// TODO: Rename field
|
||||
@Column('boolean', { default: false })
|
||||
isCanonical!: boolean;
|
||||
isDNS!: boolean;
|
||||
|
||||
@Column({
|
||||
enum: DeploymentStatus
|
||||
|
||||
@@ -414,8 +414,12 @@ export class Registry {
|
||||
* Fetch record by Id
|
||||
*/
|
||||
async getRecordById(id: string): Promise<RegistryRecord | null> {
|
||||
const [record] = await this.registry.getRecordsByIds([id]);
|
||||
return record ?? null;
|
||||
const record = await this.registry.getRecordsByIds([id]);
|
||||
if (record.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return record[0];
|
||||
}
|
||||
|
||||
async createApplicationDeploymentRemovalRequest(data: {
|
||||
|
||||
@@ -38,7 +38,7 @@ export const createResolvers = async (service: Service): Promise<any> => {
|
||||
},
|
||||
|
||||
deployments: async (_: any, { projectId }: { projectId: string }) => {
|
||||
return service.getNonCanonicalDeploymentsByProjectId(projectId);
|
||||
return service.getCommitDeploymentsByProjectId(projectId);
|
||||
},
|
||||
|
||||
environmentVariables: async (
|
||||
@@ -345,11 +345,10 @@ export const createResolvers = async (service: Service): Promise<any> => {
|
||||
{
|
||||
projectId,
|
||||
deploymentId,
|
||||
deployerId,
|
||||
}: { deploymentId: string; projectId: string, deployerId: string },
|
||||
}: { deploymentId: string; projectId: string },
|
||||
) => {
|
||||
try {
|
||||
return await service.rollbackDeployment(projectId, deploymentId, deployerId);
|
||||
return await service.rollbackDeployment(projectId, deploymentId);
|
||||
} catch (err) {
|
||||
log(err);
|
||||
return false;
|
||||
|
||||
@@ -100,6 +100,7 @@ type ProjectMember {
|
||||
|
||||
type Deployment {
|
||||
id: String!
|
||||
domain: Domain
|
||||
branch: String!
|
||||
commitHash: String!
|
||||
commitMessage: String!
|
||||
@@ -111,7 +112,6 @@ type Deployment {
|
||||
isCurrent: Boolean!
|
||||
baseDomain: String
|
||||
status: DeploymentStatus!
|
||||
dnsRecordData: DNSRecordAttributes
|
||||
createdAt: String!
|
||||
updatedAt: String!
|
||||
createdBy: User!
|
||||
@@ -272,8 +272,8 @@ type AppDeploymentRecordAttributes {
|
||||
}
|
||||
|
||||
input AuctionParams {
|
||||
maxPrice: String
|
||||
numProviders: Int
|
||||
maxPrice: String,
|
||||
numProviders: Int,
|
||||
}
|
||||
|
||||
type Query {
|
||||
|
||||
+180
-314
@@ -7,12 +7,7 @@ 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';
|
||||
@@ -124,8 +119,7 @@ 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
|
||||
@@ -210,9 +204,7 @@ 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}`);
|
||||
@@ -227,7 +219,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;
|
||||
@@ -236,52 +228,40 @@ export class Service {
|
||||
deployment.isCurrent = deployment.environment === Environment.Production;
|
||||
deployment.dnsRecordData = dnsRecordData;
|
||||
|
||||
if (deployment.isCanonical) {
|
||||
const previousCanonicalDeployment = await this.db.getDeployment({
|
||||
if (deployment.isDNS) {
|
||||
const oldDNSDeployment = await this.db.getDeployment({
|
||||
where: {
|
||||
projectId: deployment.project.id,
|
||||
deployer: deployment.deployer,
|
||||
isCanonical: true,
|
||||
isDNS: true,
|
||||
isCurrent: true,
|
||||
},
|
||||
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
|
||||
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,
|
||||
},
|
||||
);
|
||||
if (oldDNSDeployment) {
|
||||
// Send removal request for the previous DNS deployment and delete DB entry
|
||||
if (oldDNSDeployment.url !== deployment.url) {
|
||||
await this.laconicRegistry.createApplicationDeploymentRemovalRequest({
|
||||
deploymentId: oldDNSDeployment.applicationDeploymentRecordId!,
|
||||
deployerLrn: oldDNSDeployment.deployer.deployerLrn,
|
||||
auctionId: oldDNSDeployment.project.auctionId,
|
||||
payment: oldDNSDeployment.project.txHash
|
||||
});
|
||||
}
|
||||
|
||||
await this.db.deleteDeploymentById(previousCanonicalDeployment.id);
|
||||
await this.db.deleteDeploymentById(oldDNSDeployment.id);
|
||||
}
|
||||
|
||||
// Update domain after the previous DNS deployment is deleted due to unique key constraint for domain
|
||||
// Set the domain for the new current DNS deployment to the custom domain that was added for that project
|
||||
const customDomain = await this.db.getOldestDomainByProjectId(deployment.project.id);
|
||||
|
||||
if (customDomain) {
|
||||
deployment.domain = customDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,9 +269,7 @@ 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);
|
||||
@@ -323,7 +301,7 @@ export class Service {
|
||||
projectDeployment.deployer.deployerLrn ===
|
||||
deployment.deployer.deployerLrn &&
|
||||
projectDeployment.id !== deployment.id &&
|
||||
projectDeployment.isCanonical == deployment.isCanonical,
|
||||
projectDeployment.isDNS == deployment.isDNS,
|
||||
);
|
||||
for (const oldDeployment of oldDeployments) {
|
||||
await this.db.updateDeployment(
|
||||
@@ -515,19 +493,14 @@ export class Service {
|
||||
return dbProjects;
|
||||
}
|
||||
|
||||
async getNonCanonicalDeploymentsByProjectId(
|
||||
projectId: string,
|
||||
): Promise<Deployment[]> {
|
||||
const nonCanonicalDeployments =
|
||||
await this.db.getNonCanonicalDeploymentsByProjectId(projectId);
|
||||
return nonCanonicalDeployments;
|
||||
async getCommitDeploymentsByProjectId(projectId: string): Promise<Deployment[]> {
|
||||
const commitDeployments = await this.db.getCommitDeploymentsByProjectId(projectId);
|
||||
return commitDeployments;
|
||||
}
|
||||
|
||||
async getLatestDNSRecordByProjectId(
|
||||
projectId: string,
|
||||
): Promise<DNSRecordAttributes | null> {
|
||||
const dnsRecord = await this.db.getLatestDNSRecordByProjectId(projectId);
|
||||
return dnsRecord;
|
||||
async getLatestDNSRecordByProjectId(projectId: string): Promise<DNSRecordAttributes | null> {
|
||||
const dnsDeployments = await this.db.getLatestDNSRecordByProjectId(projectId);
|
||||
return dnsDeployments;
|
||||
}
|
||||
|
||||
async getEnvironmentVariablesByProjectId(
|
||||
@@ -669,7 +642,6 @@ export class Service {
|
||||
where: { id: deploymentId },
|
||||
relations: {
|
||||
project: true,
|
||||
deployer: true,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -677,25 +649,22 @@ export class Service {
|
||||
throw new Error('Deployment does not exist');
|
||||
}
|
||||
|
||||
const prodBranchDomains = await this.db.getDomainsByProjectId(
|
||||
oldDeployment.project.id,
|
||||
{ branch: oldDeployment.project.prodBranch },
|
||||
);
|
||||
|
||||
const octokit = await this.getOctokit(user.id);
|
||||
|
||||
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,
|
||||
});
|
||||
}
|
||||
const newDeployment = await this.createDeployment(user.id, octokit, {
|
||||
project: oldDeployment.project,
|
||||
branch: oldDeployment.branch,
|
||||
environment: Environment.Production,
|
||||
domain: prodBranchDomains[0],
|
||||
commitHash: oldDeployment.commitHash,
|
||||
commitMessage: oldDeployment.commitMessage,
|
||||
deployer: oldDeployment.deployer
|
||||
});
|
||||
|
||||
return newDeployment;
|
||||
}
|
||||
@@ -704,7 +673,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(
|
||||
@@ -720,6 +689,19 @@ export class Service {
|
||||
commitHash: data.commitHash!,
|
||||
});
|
||||
|
||||
// Update previous deployment with prod branch domain
|
||||
// TODO: Fix unique constraint error for domain
|
||||
if (data.domain) {
|
||||
await this.db.updateDeployment(
|
||||
{
|
||||
domainId: data.domain.id,
|
||||
},
|
||||
{
|
||||
domain: null,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
let deployer;
|
||||
if (deployerLrn) {
|
||||
deployer = await this.db.getDeployerByLRN(deployerLrn);
|
||||
@@ -727,58 +709,36 @@ 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 dnsDeployment = await this.createDeploymentFromData(userId, data, deployer!.deployerLrn!, applicationRecordId, applicationRecordData, true);
|
||||
|
||||
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!);
|
||||
|
||||
// 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!);
|
||||
|
||||
// To set project DNS
|
||||
if (data.environment === Environment.Production) {
|
||||
const canonicalDeployment = await this.createDeploymentFromData(
|
||||
userId,
|
||||
data,
|
||||
deployer!.deployerLrn!,
|
||||
applicationRecordId,
|
||||
applicationRecordData,
|
||||
true,
|
||||
);
|
||||
// On deleting deployment later, project DNS deployment is also deleted
|
||||
// So publish project DNS deployment first so that ApplicationDeploymentRecord for the same is available when deleting deployment later
|
||||
const { applicationDeploymentRequestData, applicationDeploymentRequestId } =
|
||||
await this.laconicRegistry.createApplicationDeploymentRequest({
|
||||
deployment: dnsDeployment,
|
||||
appName: repo,
|
||||
repository: repoUrl,
|
||||
environmentVariables: environmentVariablesObj,
|
||||
dns: customDomain?.name ?? `${dnsDeployment.project.name}`,
|
||||
lrn: deployer!.deployerLrn!,
|
||||
apiUrl: deployer!.deployerApiUrl!,
|
||||
payment: data.project.txHash,
|
||||
auctionId: data.project.auctionId,
|
||||
requesterAddress: address,
|
||||
publicKey: deployer!.publicKey!
|
||||
});
|
||||
|
||||
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,
|
||||
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, {
|
||||
await this.db.updateDeploymentById(dnsDeployment.id, {
|
||||
applicationDeploymentRequestId,
|
||||
applicationDeploymentRequestData,
|
||||
});
|
||||
@@ -796,7 +756,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, {
|
||||
@@ -809,7 +769,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('/');
|
||||
@@ -835,7 +795,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 = {
|
||||
@@ -847,51 +807,30 @@ 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 dnsDeployment = await this.createDeploymentFromData(project.ownerId!, deploymentData, deployerLrn, applicationRecordId, applicationRecordData, true);
|
||||
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,
|
||||
);
|
||||
// On deleting deployment later, project DNS deployment is also deleted
|
||||
// So publish project DNS deployment first so that ApplicationDeploymentRecord for the same is available when deleting deployment later
|
||||
const { applicationDeploymentRequestId, applicationDeploymentRequestData } =
|
||||
await this.laconicRegistry.createApplicationDeploymentRequest({
|
||||
deployment: dnsDeployment,
|
||||
appName: repo,
|
||||
repository: repoUrl,
|
||||
environmentVariables: environmentVariablesObj,
|
||||
dns: `${dnsDeployment.project.name}`,
|
||||
auctionId: project.auctionId!,
|
||||
lrn: deployerLrn,
|
||||
apiUrl: deployer!.deployerApiUrl!,
|
||||
requesterAddress: address,
|
||||
publicKey: deployer!.publicKey!
|
||||
});
|
||||
|
||||
// If a custom domain is present then use that as the DNS in the deployment request
|
||||
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,
|
||||
auctionId: project.auctionId!,
|
||||
lrn: deployerLrn,
|
||||
apiUrl: deployer!.deployerApiUrl!,
|
||||
requesterAddress: address,
|
||||
publicKey: deployer!.publicKey!,
|
||||
});
|
||||
|
||||
await this.db.updateDeploymentById(canonicalDeployment.id, {
|
||||
await this.db.updateDeploymentById(dnsDeployment.id, {
|
||||
applicationDeploymentRequestId,
|
||||
applicationDeploymentRequestData,
|
||||
});
|
||||
@@ -909,7 +848,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, {
|
||||
@@ -926,7 +865,7 @@ export class Service {
|
||||
deployerLrn: string,
|
||||
applicationRecordId: string,
|
||||
applicationRecordData: ApplicationRecord,
|
||||
isCanonical: boolean,
|
||||
isDNS: boolean,
|
||||
): Promise<Deployment> {
|
||||
const newDeployment = await this.db.addDeployment({
|
||||
project: data.project,
|
||||
@@ -937,13 +876,14 @@ export class Service {
|
||||
status: DeploymentStatus.Building,
|
||||
applicationRecordId,
|
||||
applicationRecordData,
|
||||
domain: data.domain,
|
||||
createdBy: Object.assign(new User(), {
|
||||
id: userId,
|
||||
}),
|
||||
deployer: Object.assign(new Deployer(), {
|
||||
deployerLrn,
|
||||
}),
|
||||
isCanonical,
|
||||
isDNS
|
||||
});
|
||||
|
||||
log(`Created deployment ${newDeployment.id}`);
|
||||
@@ -953,11 +893,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) {
|
||||
@@ -1002,22 +942,15 @@ 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');
|
||||
@@ -1076,9 +1009,7 @@ 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!);
|
||||
@@ -1185,6 +1116,9 @@ export class Service {
|
||||
|
||||
for await (const project of projects) {
|
||||
const octokit = await this.getOctokit(project.ownerId);
|
||||
const [domain] = await this.db.getDomainsByProjectId(project.id, {
|
||||
branch,
|
||||
});
|
||||
|
||||
const deployers = project.deployers;
|
||||
if (!deployers) {
|
||||
@@ -1202,6 +1136,7 @@ export class Service {
|
||||
project.prodBranch === branch
|
||||
? Environment.Production
|
||||
: Environment.Preview,
|
||||
domain,
|
||||
commitHash: headCommit.id,
|
||||
commitMessage: headCommit.message,
|
||||
deployer: deployer
|
||||
@@ -1243,6 +1178,7 @@ export class Service {
|
||||
const oldDeployment = await this.db.getDeployment({
|
||||
relations: {
|
||||
project: true,
|
||||
domain: true,
|
||||
deployer: true,
|
||||
createdBy: true,
|
||||
},
|
||||
@@ -1260,20 +1196,20 @@ 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,
|
||||
// TODO: Put isCurrent field in project
|
||||
branch: oldDeployment.branch,
|
||||
environment: Environment.Production,
|
||||
commitHash: oldDeployment.commitHash,
|
||||
commitMessage: oldDeployment.commitMessage,
|
||||
deployer: oldDeployment.deployer,
|
||||
});
|
||||
newDeployment = await this.createDeployment(user.id, octokit,
|
||||
{
|
||||
project: oldDeployment.project,
|
||||
// TODO: Put isCurrent field in project
|
||||
branch: oldDeployment.branch,
|
||||
environment: Environment.Production,
|
||||
domain: oldDeployment.domain,
|
||||
commitHash: oldDeployment.commitHash,
|
||||
commitMessage: oldDeployment.commitMessage,
|
||||
deployer: oldDeployment.deployer
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return newDeployment;
|
||||
@@ -1282,11 +1218,11 @@ export class Service {
|
||||
async rollbackDeployment(
|
||||
projectId: string,
|
||||
deploymentId: string,
|
||||
deployerId: string,
|
||||
): Promise<boolean> {
|
||||
// TODO: Implement transactions
|
||||
const oldCurrentDeployment = await this.db.getDeployment({
|
||||
relations: {
|
||||
domain: true,
|
||||
project: true,
|
||||
deployer: true,
|
||||
},
|
||||
@@ -1294,11 +1230,8 @@ export class Service {
|
||||
project: {
|
||||
id: projectId,
|
||||
},
|
||||
deployer: {
|
||||
deployerId
|
||||
},
|
||||
isCurrent: true,
|
||||
isCanonical: false,
|
||||
isDNS: false,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1308,36 +1241,22 @@ export class Service {
|
||||
|
||||
const oldCurrentDeploymentUpdate = await this.db.updateDeploymentById(
|
||||
oldCurrentDeployment.id,
|
||||
{ isCurrent: false },
|
||||
{ isCurrent: false, domain: null },
|
||||
);
|
||||
|
||||
const newCurrentDeploymentUpdate = await this.db.updateDeploymentById(
|
||||
deploymentId,
|
||||
{ isCurrent: true },
|
||||
{ isCurrent: true, domain: oldCurrentDeployment.domain },
|
||||
);
|
||||
|
||||
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 dns = await this.getDnsForDeployerByProjectId(projectId, newCurrentDeployment.deployer!.version, newCurrentDeployment.project.name)
|
||||
|
||||
applicationDeploymentRequestData!.dns = dns
|
||||
|
||||
// Create a canonical deployment for the new current deployment
|
||||
const canonicalDeployment = await this.createDeploymentFromData(
|
||||
// Create a DNS deployment for the new current deployment
|
||||
const dnsDeployment = await this.createDeploymentFromData(
|
||||
newCurrentDeployment.project.ownerId,
|
||||
newCurrentDeployment,
|
||||
newCurrentDeployment.deployer!.deployerLrn!,
|
||||
@@ -1346,28 +1265,28 @@ export class Service {
|
||||
true,
|
||||
);
|
||||
|
||||
const applicationDeploymentRequestData = newCurrentDeployment.applicationDeploymentRequestData;
|
||||
|
||||
applicationDeploymentRequestData!.version = (Number(applicationDeploymentRequestData?.version) + 1).toString();
|
||||
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,
|
||||
},
|
||||
);
|
||||
await this.db.updateDeploymentById(dnsDeployment.id, {
|
||||
applicationDeploymentRequestId: result.id,
|
||||
applicationDeploymentRequestData,
|
||||
});
|
||||
|
||||
return updateResult;
|
||||
return newCurrentDeploymentUpdate && oldCurrentDeploymentUpdate;
|
||||
}
|
||||
|
||||
async deleteDeployment(deploymentId: string): Promise<boolean> {
|
||||
@@ -1384,11 +1303,11 @@ export class Service {
|
||||
if (deployment && deployment.applicationDeploymentRecordId) {
|
||||
// If deployment is current, remove deployment for project subdomain as well
|
||||
if (deployment.isCurrent) {
|
||||
const canonicalDeployment = await this.db.getDeployment({
|
||||
const dnsDeployment = await this.db.getDeployment({
|
||||
where: {
|
||||
projectId: deployment.project.id,
|
||||
deployer: deployment.deployer,
|
||||
isCanonical: true
|
||||
isDNS: true
|
||||
},
|
||||
relations: {
|
||||
project: true,
|
||||
@@ -1396,53 +1315,27 @@ export class Service {
|
||||
},
|
||||
})
|
||||
|
||||
// If the canonical deployment is not present then query the chain for the deployment record for backward compatibility
|
||||
if (!canonicalDeployment) {
|
||||
log(`Canonical deployment for deployment with id ${deployment.id} not found, querying the chain..`);
|
||||
const currentDeploymentURL = `https://${(deployment.project.name).toLowerCase()}.${deployment.deployer.baseDomain}`;
|
||||
if (!dnsDeployment) {
|
||||
log(`DNS deployment for deployment with id ${deployment.id} not found`);
|
||||
|
||||
const deploymentRecords =
|
||||
await this.laconicRegistry.getDeploymentRecordsByFilter({
|
||||
application: deployment.applicationRecordId,
|
||||
url: currentDeploymentURL,
|
||||
});
|
||||
|
||||
if (!deploymentRecords.length) {
|
||||
log(
|
||||
`No ApplicationDeploymentRecord found for URL ${currentDeploymentURL} and ApplicationDeploymentRecord id ${deployment.applicationDeploymentRecordId}`,
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Multiple records are fetched, take the latest record
|
||||
const latestRecord = deploymentRecords
|
||||
.sort((a, b) => new Date(b.createTime).getTime() - new Date(a.createTime).getTime())[0];
|
||||
|
||||
await this.laconicRegistry.createApplicationDeploymentRemovalRequest({
|
||||
deploymentId: latestRecord.id,
|
||||
deployerLrn: deployment.deployer.deployerLrn,
|
||||
auctionId: deployment.project.auctionId,
|
||||
payment: deployment.project.txHash
|
||||
});
|
||||
} else {
|
||||
// If canonical deployment is found in the DB, then send the removal request with that deployment record Id
|
||||
const result =
|
||||
await this.laconicRegistry.createApplicationDeploymentRemovalRequest({
|
||||
deploymentId: canonicalDeployment.applicationDeploymentRecordId!,
|
||||
deployerLrn: canonicalDeployment.deployer.deployerLrn,
|
||||
auctionId: canonicalDeployment.project.auctionId,
|
||||
payment: canonicalDeployment.project.txHash
|
||||
});
|
||||
|
||||
await this.db.updateDeploymentById(canonicalDeployment.id, {
|
||||
status: DeploymentStatus.Deleting,
|
||||
applicationDeploymentRemovalRequestId:
|
||||
result.applicationDeploymentRemovalRequestId,
|
||||
applicationDeploymentRemovalRequestData:
|
||||
result.applicationDeploymentRemovalRequestData,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
const dnsResult =
|
||||
await this.laconicRegistry.createApplicationDeploymentRemovalRequest({
|
||||
deploymentId: dnsDeployment.applicationDeploymentRecordId!,
|
||||
deployerLrn: dnsDeployment.deployer.deployerLrn,
|
||||
auctionId: dnsDeployment.project.auctionId,
|
||||
payment: dnsDeployment.project.txHash
|
||||
});
|
||||
|
||||
await this.db.updateDeploymentById(dnsDeployment.id, {
|
||||
status: DeploymentStatus.Deleting,
|
||||
applicationDeploymentRemovalRequestId:
|
||||
dnsResult.applicationDeploymentRemovalRequestId,
|
||||
applicationDeploymentRemovalRequestData:
|
||||
dnsResult.applicationDeploymentRemovalRequestData,
|
||||
});
|
||||
}
|
||||
|
||||
const result =
|
||||
@@ -1692,8 +1585,6 @@ 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 = {
|
||||
@@ -1703,8 +1594,7 @@ export class Service {
|
||||
baseDomain,
|
||||
minimumPayment,
|
||||
paymentAddress,
|
||||
publicKey,
|
||||
version,
|
||||
publicKey
|
||||
};
|
||||
|
||||
// TODO: Update deployers table in a separate job
|
||||
@@ -1743,28 +1633,4 @@ 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,6 +120,5 @@ export interface DeployerRecord {
|
||||
publicKey: string;
|
||||
type: string;
|
||||
version: string;
|
||||
deployerVersion: string;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import { CopyBlock, atomOneLight } from 'react-code-blocks';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
import { Modal } from 'components/shared/Modal';
|
||||
import { Button } from 'components/shared/Button';
|
||||
|
||||
interface AssignDomainProps {
|
||||
open: boolean;
|
||||
handleOpen: () => void;
|
||||
}
|
||||
|
||||
const AssignDomainDialog = ({ open, handleOpen }: AssignDomainProps) => {
|
||||
return (
|
||||
<Modal open={open} onOpenChange={handleOpen}>
|
||||
<Modal.Content>
|
||||
<Modal.Header>Assign Domain</Modal.Header>
|
||||
<Modal.Body>
|
||||
In order to assign a domain to your production deployments, configure
|
||||
it in the{' '}
|
||||
{/* TODO: Fix selection of project settings tab on navigation to domains */}
|
||||
<Link to="../settings/domains" className="text-light-blue-800 inline">
|
||||
project settings{' '}
|
||||
</Link>
|
||||
(recommended). If you want to assign to this specific deployment,
|
||||
however, you can do so using our command-line interface:
|
||||
{/* https://github.com/rajinwonderland/react-code-blocks/issues/138 */}
|
||||
<CopyBlock
|
||||
text="snowball alias <deployment> <domain>"
|
||||
language=""
|
||||
showLineNumbers={false}
|
||||
theme={atomOneLight}
|
||||
/>
|
||||
</Modal.Body>
|
||||
<Modal.Footer className="flex justify-start">
|
||||
<Button onClick={handleOpen}>Okay</Button>
|
||||
</Modal.Footer>
|
||||
</Modal.Content>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default AssignDomainDialog;
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
import { Deployment, Domain, Environment, Project } from 'gql-client';
|
||||
import { Button } from 'components/shared/Button';
|
||||
import {
|
||||
GlobeIcon,
|
||||
HorizontalDotIcon,
|
||||
LinkIcon,
|
||||
RefreshIcon,
|
||||
@@ -17,6 +18,7 @@ import {
|
||||
UndoIcon,
|
||||
CrossCircleIcon,
|
||||
} from 'components/shared/CustomIcon';
|
||||
import AssignDomainDialog from './AssignDomainDialog';
|
||||
import { useGQLClient } from 'context/GQLClientContext';
|
||||
import { cn } from 'utils/classnames';
|
||||
import { ChangeStateToProductionDialog } from 'components/projects/Dialog/ChangeStateToProductionDialog';
|
||||
@@ -47,8 +49,8 @@ export const DeploymentMenu = ({
|
||||
const [redeployToProduction, setRedeployToProduction] = useState(false);
|
||||
const [deleteDeploymentDialog, setDeleteDeploymentDialog] = useState(false);
|
||||
const [isConfirmDeleteLoading, setIsConfirmDeleteLoading] = useState(false);
|
||||
const [isConfirmUpdateLoading, setIsConfirmUpdateLoading] = useState(false);
|
||||
const [rollbackDeployment, setRollbackDeployment] = useState(false);
|
||||
const [assignDomainDialog, setAssignDomainDialog] = useState(false);
|
||||
const [isConfirmButtonLoading, setConfirmButtonLoadingLoading] =
|
||||
useState(false);
|
||||
|
||||
@@ -56,8 +58,6 @@ export const DeploymentMenu = ({
|
||||
const isUpdated = await client.updateDeploymentToProd(deployment.id);
|
||||
if (isUpdated.updateDeploymentToProd) {
|
||||
await onUpdate();
|
||||
setIsConfirmUpdateLoading(false);
|
||||
|
||||
toast({
|
||||
id: 'deployment_changed_to_production',
|
||||
title: 'Deployment changed to production',
|
||||
@@ -99,12 +99,9 @@ export const DeploymentMenu = ({
|
||||
const isRollbacked = await client.rollbackDeployment(
|
||||
project.id,
|
||||
deployment.id,
|
||||
deployment.deployer.deployerId
|
||||
);
|
||||
if (isRollbacked.rollbackDeployment) {
|
||||
await onUpdate();
|
||||
setIsConfirmUpdateLoading(false);
|
||||
|
||||
toast({
|
||||
id: 'deployment_rolled_back',
|
||||
title: 'Deployment rolled back',
|
||||
@@ -176,6 +173,12 @@ export const DeploymentMenu = ({
|
||||
<LinkIcon /> Visit
|
||||
</a>
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
className="hover:bg-base-bg-emphasized flex items-center gap-3"
|
||||
onClick={() => setAssignDomainDialog(!assignDomainDialog)}
|
||||
>
|
||||
<GlobeIcon /> Assign domain
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
className="hover:bg-base-bg-emphasized flex items-center gap-3"
|
||||
onClick={() => setChangeToProduction(!changeToProduction)}
|
||||
@@ -223,11 +226,9 @@ export const DeploymentMenu = ({
|
||||
handleCancel={() => setChangeToProduction((preVal) => !preVal)}
|
||||
open={changeToProduction}
|
||||
handleConfirm={async () => {
|
||||
setIsConfirmUpdateLoading(true);
|
||||
await updateDeployment();
|
||||
setChangeToProduction((preVal) => !preVal);
|
||||
}}
|
||||
isConfirmButtonLoading={isConfirmUpdateLoading}
|
||||
deployment={deployment}
|
||||
domains={prodBranchDomains}
|
||||
/>
|
||||
@@ -242,7 +243,7 @@ export const DeploymentMenu = ({
|
||||
setRedeployToProduction((preVal) => !preVal);
|
||||
}}
|
||||
deployment={deployment}
|
||||
domains={prodBranchDomains}
|
||||
domains={deployment.domain ? [deployment.domain] : []}
|
||||
isConfirmButtonLoading={isConfirmButtonLoading}
|
||||
/>
|
||||
{Boolean(currentDeployment) && (
|
||||
@@ -252,16 +253,18 @@ export const DeploymentMenu = ({
|
||||
open={rollbackDeployment}
|
||||
confirmButtonTitle="Rollback"
|
||||
handleConfirm={async () => {
|
||||
setIsConfirmUpdateLoading(true);
|
||||
await rollbackDeploymentHandler();
|
||||
setRollbackDeployment((preVal) => !preVal);
|
||||
}}
|
||||
deployment={currentDeployment}
|
||||
newDeployment={deployment}
|
||||
domains={prodBranchDomains}
|
||||
isConfirmButtonLoading={isConfirmUpdateLoading}
|
||||
domains={currentDeployment.domain ? [currentDeployment.domain] : []}
|
||||
/>
|
||||
)}
|
||||
<AssignDomainDialog
|
||||
open={assignDomainDialog}
|
||||
handleOpen={() => setAssignDomainDialog(!assignDomainDialog)}
|
||||
/>
|
||||
<DeleteDeploymentDialog
|
||||
open={deleteDeploymentDialog}
|
||||
handleConfirm={async () => {
|
||||
|
||||
@@ -8,14 +8,13 @@ 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, InfoRoundFilledIcon } from 'components/shared/CustomIcon';
|
||||
import { GearIcon } from 'components/shared/CustomIcon';
|
||||
import { Heading } from 'components/shared/Heading';
|
||||
import { Button } from 'components/shared/Button';
|
||||
import { useParams } from 'react-router-dom';
|
||||
@@ -45,6 +44,7 @@ interface DomainCardProps {
|
||||
onUpdate: () => Promise<void>;
|
||||
}
|
||||
|
||||
|
||||
const DomainCard = ({
|
||||
domains,
|
||||
domain,
|
||||
@@ -56,9 +56,7 @@ const DomainCard = ({
|
||||
const { id } = useParams();
|
||||
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
|
||||
const [editDialogOpen, setEditDialogOpen] = useState(false);
|
||||
const [dnsRecordsWithLRN, setDnsRecordsWithLRN] = useState<
|
||||
{ dnsRecord: DNSRecordAttributes; deployerLRN: string }[]
|
||||
>([]);
|
||||
const [dnsRecord, setDnsRecord] = useState<DNSRecordAttributes | null>(null);
|
||||
// const [refreshStatus, SetRefreshStatus] = useState(RefreshStatus.IDLE);
|
||||
|
||||
const client = useGQLClient();
|
||||
@@ -96,26 +94,9 @@ const DomainCard = ({
|
||||
return;
|
||||
}
|
||||
|
||||
const dnsRecordResponse = await client.getProject(id);
|
||||
const dnsRecordResponse = await client.getLatestDNSRecordByProjectId(id);
|
||||
|
||||
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);
|
||||
setDnsRecord(dnsRecordResponse.latestDNSRecord);
|
||||
};
|
||||
|
||||
fetchDNSData();
|
||||
@@ -201,16 +182,11 @@ const DomainCard = ({
|
||||
<Typography variant="small">Production</Typography>
|
||||
{domain.status === DomainStatus.Pending && (
|
||||
<Card className="bg-slate-100 p-4 text-sm">
|
||||
{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 ? (
|
||||
{/* {refreshStatus === RefreshStatus.IDLE ? ( */}
|
||||
<Heading>
|
||||
^ Add these records to your domain {/* and refresh to check */}
|
||||
</Heading>
|
||||
{/* ) : refreshStatus === RefreshStatus.CHECKING ? (
|
||||
<Heading className="text-blue-500">
|
||||
^ Checking records for {domain.name}
|
||||
</Heading>
|
||||
@@ -223,49 +199,26 @@ const DomainCard = ({
|
||||
</div>
|
||||
)} */}
|
||||
|
||||
<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>
|
||||
)}
|
||||
<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>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import {
|
||||
AppDeploymentRecordAttributes,
|
||||
Deployment,
|
||||
DeploymentStatus,
|
||||
DNSRecordAttributes,
|
||||
Domain,
|
||||
DomainStatus,
|
||||
Environment,
|
||||
@@ -22,6 +21,15 @@ import { ChangeStateToProductionDialog } from 'components/projects/Dialog/Change
|
||||
|
||||
const deployment: Deployment = {
|
||||
id: '1',
|
||||
domain: {
|
||||
id: 'domain1',
|
||||
branch: 'main',
|
||||
name: 'example.com',
|
||||
status: DomainStatus.Live,
|
||||
redirectTo: null,
|
||||
createdAt: '1677609600', // 2023-02-25T12:00:00Z
|
||||
updatedAt: '1677613200', // 2023-02-25T13:00:00Z
|
||||
},
|
||||
branch: 'main',
|
||||
commitHash: 'a1b2c3d',
|
||||
commitMessage:
|
||||
@@ -51,7 +59,6 @@ const deployment: Deployment = {
|
||||
applicationDeploymentRequestId:
|
||||
'bafyreiaycvq6imoppnpwdve4smj6t6ql5svt5zl3x6rimu4qwyzgjorize',
|
||||
applicationDeploymentRecordData: {} as AppDeploymentRecordAttributes,
|
||||
dnsRecordData: {} as DNSRecordAttributes,
|
||||
};
|
||||
|
||||
const domains: Domain[] = [
|
||||
@@ -247,7 +254,7 @@ const ModalsPage: React.FC = () => {
|
||||
setRedeployToProduction((preVal) => !preVal)
|
||||
}
|
||||
deployment={deployment}
|
||||
domains={domains}
|
||||
domains={deployment.domain ? [deployment.domain] : []}
|
||||
/>
|
||||
{/* Rollback to this deployment */}
|
||||
<Button onClick={() => setRollbackDeployment(true)}>
|
||||
@@ -263,7 +270,7 @@ const ModalsPage: React.FC = () => {
|
||||
}
|
||||
deployment={deployment}
|
||||
newDeployment={deployment}
|
||||
domains={domains}
|
||||
domains={deployment.domain ? [deployment.domain] : []}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -60,31 +60,39 @@ const Domains = () => {
|
||||
return (
|
||||
<ProjectSettingContainer
|
||||
headingText="Domains"
|
||||
button={
|
||||
<Button
|
||||
as="a"
|
||||
href="add"
|
||||
variant="secondary"
|
||||
leftIcon={<PlusIcon />}
|
||||
size="md"
|
||||
>
|
||||
Add domain
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
{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}
|
||||
/>
|
||||
);
|
||||
{...(!project.auctionId && {
|
||||
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}
|
||||
/>
|
||||
);
|
||||
})
|
||||
)}
|
||||
</ProjectSettingContainer>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -18,9 +18,7 @@ const Config = () => {
|
||||
const primaryDomainName = searchParams.get('name');
|
||||
const { toast, dismiss } = useToast();
|
||||
|
||||
const [dnsRecordsWithLRN, setDnsRecordsWithLRN] = useState<
|
||||
{ dnsRecord: DNSRecordAttributes; deployerLRN: string }[]
|
||||
>([]);
|
||||
const [dnsRecord, setDnsRecord] = useState<DNSRecordAttributes | null>(null);
|
||||
|
||||
const handleSubmitDomain = async () => {
|
||||
if (primaryDomainName === null) {
|
||||
@@ -77,100 +75,68 @@ const Config = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
const dnsRecordResponse = await client.getProject(id);
|
||||
const dnsRecordResponse = await client.getLatestDNSRecordByProjectId(id);
|
||||
|
||||
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);
|
||||
setDnsRecord(dnsRecordResponse.latestDNSRecord);
|
||||
};
|
||||
|
||||
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">
|
||||
{dnsRecordsWithLRN.length ? (
|
||||
{dnsRecord ? (
|
||||
<>
|
||||
<p className="text-blue-gray-500">
|
||||
Add the following records to your domain.
|
||||
</p>
|
||||
{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>
|
||||
</>
|
||||
);
|
||||
}
|
||||
})}
|
||||
|
||||
<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>
|
||||
</>
|
||||
) : (
|
||||
<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,7 +13,6 @@ import {
|
||||
Environment,
|
||||
Permission,
|
||||
AppDeploymentRecordAttributes,
|
||||
DNSRecordAttributes,
|
||||
} from 'gql-client';
|
||||
|
||||
export const user: User = {
|
||||
@@ -101,6 +100,7 @@ export const deployment0: Deployment = {
|
||||
environment: Environment.Development,
|
||||
isCurrent: true,
|
||||
commitHash: 'Commit Hash',
|
||||
domain: domain0,
|
||||
commitMessage: 'Commit Message',
|
||||
createdBy: user,
|
||||
deployer: {
|
||||
@@ -113,7 +113,6 @@ export const deployment0: Deployment = {
|
||||
applicationDeploymentRequestId:
|
||||
'bafyreiaycvq6imoppnpwdve4smj6t6ql5svt5zl3x6rimu4qwyzgjorize',
|
||||
applicationDeploymentRecordData: {} as AppDeploymentRecordAttributes,
|
||||
dnsRecordData: {} as DNSRecordAttributes,
|
||||
};
|
||||
|
||||
export const project: Project = {
|
||||
|
||||
@@ -337,15 +337,13 @@ export class GQLClient {
|
||||
|
||||
async rollbackDeployment(
|
||||
projectId: string,
|
||||
deploymentId: string,
|
||||
deployerId: string,
|
||||
deploymentId: string
|
||||
): Promise<types.RollbackDeploymentResponse> {
|
||||
const { data } = await this.client.mutate({
|
||||
mutation: mutations.rollbackDeployment,
|
||||
variables: {
|
||||
projectId,
|
||||
deploymentId,
|
||||
deployerId,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -62,19 +62,19 @@ query ($projectId: String!) {
|
||||
}
|
||||
deployer {
|
||||
baseDomain
|
||||
deployerLrn
|
||||
}
|
||||
domain {
|
||||
status
|
||||
branch
|
||||
createdAt
|
||||
updatedAt
|
||||
id
|
||||
name
|
||||
}
|
||||
createdBy {
|
||||
id
|
||||
name
|
||||
}
|
||||
dnsRecordData {
|
||||
name
|
||||
value
|
||||
request
|
||||
resourceType
|
||||
version
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,6 +118,14 @@ query ($organizationSlug: String!) {
|
||||
applicationDeploymentRecordData {
|
||||
url
|
||||
}
|
||||
domain {
|
||||
status
|
||||
branch
|
||||
createdAt
|
||||
updatedAt
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -139,6 +147,14 @@ export const getDeployments = gql`
|
||||
query ($projectId: String!) {
|
||||
deployments(projectId: $projectId) {
|
||||
id
|
||||
domain{
|
||||
branch
|
||||
createdAt
|
||||
id
|
||||
name
|
||||
status
|
||||
updatedAt
|
||||
}
|
||||
branch
|
||||
commitHash
|
||||
commitMessage
|
||||
|
||||
@@ -99,6 +99,7 @@ export type User = {
|
||||
|
||||
export type Deployment = {
|
||||
id: string;
|
||||
domain: Domain;
|
||||
branch: string;
|
||||
commitHash: string;
|
||||
commitMessage: string;
|
||||
@@ -112,7 +113,6 @@ export type Deployment = {
|
||||
createdBy: User;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
dnsRecordData: DNSRecordAttributes;
|
||||
applicationDeploymentRequestId: string;
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user