Compare commits
47 Commits
main
...
custom-dom
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 |
@ -17,13 +17,14 @@ import { DatabaseConfig } from './config';
|
||||
import { User } from './entity/User';
|
||||
import { Organization } from './entity/Organization';
|
||||
import { Project } from './entity/Project';
|
||||
import { Deployment } from './entity/Deployment';
|
||||
import { Deployment, DeploymentStatus } from './entity/Deployment';
|
||||
import { ProjectMember } from './entity/ProjectMember';
|
||||
import { EnvironmentVariable } from './entity/EnvironmentVariable';
|
||||
import { Domain } from './entity/Domain';
|
||||
import { getEntities, loadAndSaveData } from './utils';
|
||||
import { UserOrganization } from './entity/UserOrganization';
|
||||
import { Deployer } from './entity/Deployer';
|
||||
import { DNSRecordAttributes } from './types';
|
||||
|
||||
const ORGANIZATION_DATA_PATH = '../test/fixtures/organizations.json';
|
||||
|
||||
@ -60,7 +61,7 @@ export class Database {
|
||||
// Hotfix for updating old DB data
|
||||
if (organizations[0].slug === 'snowball-tools-1') {
|
||||
const [orgEntity] = await getEntities(path.resolve(__dirname, ORGANIZATION_DATA_PATH));
|
||||
|
||||
|
||||
await this.updateOrganization(
|
||||
organizations[0].id,
|
||||
{
|
||||
@ -157,7 +158,7 @@ export class Database {
|
||||
.leftJoinAndSelect(
|
||||
'project.deployments',
|
||||
'deployments',
|
||||
'deployments.isCurrent = true'
|
||||
'deployments.isCurrent = true AND deployments.isDNS = true'
|
||||
)
|
||||
.leftJoinAndSelect('deployments.createdBy', 'user')
|
||||
.leftJoinAndSelect('deployments.domain', 'domain')
|
||||
@ -202,7 +203,7 @@ export class Database {
|
||||
.leftJoinAndSelect(
|
||||
'project.deployments',
|
||||
'deployments',
|
||||
'deployments.isCurrent = true'
|
||||
'deployments.isCurrent = true AND deployments.isDNS = true'
|
||||
)
|
||||
.leftJoinAndSelect('deployments.domain', 'domain')
|
||||
.leftJoin('project.projectMembers', 'projectMembers')
|
||||
@ -250,6 +251,26 @@ export class Database {
|
||||
});
|
||||
}
|
||||
|
||||
async getCommitDeploymentsByProjectId(projectId: string): Promise<Deployment[]> {
|
||||
return this.getDeployments({
|
||||
relations: {
|
||||
project: true,
|
||||
domain: true,
|
||||
createdBy: true,
|
||||
deployer: true,
|
||||
},
|
||||
where: {
|
||||
project: {
|
||||
id: projectId
|
||||
},
|
||||
isDNS: false
|
||||
},
|
||||
order: {
|
||||
createdAt: 'DESC'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async getDeployment(
|
||||
options: FindOneOptions<Deployment>
|
||||
): Promise<Deployment | null> {
|
||||
@ -602,6 +623,49 @@ export class Database {
|
||||
return domains;
|
||||
}
|
||||
|
||||
async getOldestDomainByProjectId(
|
||||
projectId: string,
|
||||
): Promise<Domain | null> {
|
||||
const domainRepository = this.dataSource.getRepository(Domain);
|
||||
|
||||
const domain = await domainRepository.findOne({
|
||||
where: {
|
||||
project: {
|
||||
id: projectId
|
||||
},
|
||||
},
|
||||
order: {
|
||||
createdAt: 'ASC'
|
||||
}
|
||||
});
|
||||
|
||||
return domain;
|
||||
}
|
||||
|
||||
async getLatestDNSRecordByProjectId(
|
||||
projectId: string,
|
||||
): Promise<DNSRecordAttributes | null> {
|
||||
const deploymentRepository = this.dataSource.getRepository(Deployment);
|
||||
|
||||
const deployment = await deploymentRepository.findOne({
|
||||
where: {
|
||||
project: {
|
||||
id: projectId,
|
||||
},
|
||||
status: DeploymentStatus.Ready,
|
||||
},
|
||||
order: {
|
||||
createdAt: 'DESC'
|
||||
}
|
||||
});
|
||||
|
||||
if (deployment === null) {
|
||||
throw new Error(`No deployment found for project ${projectId}`);
|
||||
}
|
||||
|
||||
return deployment.dnsRecordData;
|
||||
}
|
||||
|
||||
async addDeployer(data: DeepPartial<Deployer>): Promise<Deployer> {
|
||||
const deployerRepository = this.dataSource.getRepository(Deployer);
|
||||
const newDomain = await deployerRepository.save(data);
|
||||
|
@ -14,7 +14,7 @@ import { Project } from './Project';
|
||||
import { Domain } from './Domain';
|
||||
import { User } from './User';
|
||||
import { Deployer } from './Deployer';
|
||||
import { AppDeploymentRecordAttributes, AppDeploymentRemovalRecordAttributes } from '../types';
|
||||
import { AppDeploymentRecordAttributes, AppDeploymentRemovalRecordAttributes, DNSRecordAttributes } from '../types';
|
||||
|
||||
export enum Environment {
|
||||
Production = 'Production',
|
||||
@ -126,6 +126,9 @@ export class Deployment {
|
||||
@Column('simple-json', { nullable: true })
|
||||
applicationDeploymentRemovalRecordData!: AppDeploymentRemovalRecordAttributes | null;
|
||||
|
||||
@Column('simple-json', { nullable: true })
|
||||
dnsRecordData!: DNSRecordAttributes | null;
|
||||
|
||||
@ManyToOne(() => Deployer)
|
||||
@JoinColumn({ name: 'deployerLrn' })
|
||||
deployer!: Deployer;
|
||||
@ -138,6 +141,10 @@ export class Deployment {
|
||||
@Column('boolean', { default: false })
|
||||
isCurrent!: boolean;
|
||||
|
||||
// TODO: Rename field
|
||||
@Column('boolean', { default: false })
|
||||
isDNS!: boolean;
|
||||
|
||||
@Column({
|
||||
enum: DeploymentStatus
|
||||
})
|
||||
|
@ -16,7 +16,7 @@ import {
|
||||
ApplicationDeploymentRequest,
|
||||
ApplicationDeploymentRemovalRequest
|
||||
} from './entity/Deployment';
|
||||
import { AppDeploymentRecord, AppDeploymentRemovalRecord, AuctionParams, DeployerRecord } from './types';
|
||||
import { AppDeploymentRecord, AppDeploymentRemovalRecord, AuctionParams, DeployerRecord, RegistryRecord } from './types';
|
||||
import { getConfig, getRepoDetails, registryTransactionWithRetry, sleep } from './utils';
|
||||
|
||||
const log = debug('snowball:registry');
|
||||
@ -27,7 +27,7 @@ const APP_DEPLOYMENT_REQUEST_TYPE = 'ApplicationDeploymentRequest';
|
||||
const APP_DEPLOYMENT_REMOVAL_REQUEST_TYPE = 'ApplicationDeploymentRemovalRequest';
|
||||
const APP_DEPLOYMENT_RECORD_TYPE = 'ApplicationDeploymentRecord';
|
||||
const APP_DEPLOYMENT_REMOVAL_RECORD_TYPE = 'ApplicationDeploymentRemovalRecord';
|
||||
const WEBAPP_DEPLOYER_RECORD_TYPE = 'WebappDeployer'
|
||||
const WEBAPP_DEPLOYER_RECORD_TYPE = 'WebappDeployer';
|
||||
const SLEEP_DURATION = 1000;
|
||||
|
||||
// TODO: Move registry code to registry-sdk/watcher-ts
|
||||
@ -108,19 +108,7 @@ export class Registry {
|
||||
...(packageJSON.version && { app_version: packageJSON.version })
|
||||
};
|
||||
|
||||
const fee = parseGasAndFees(this.registryConfig.fee.gas, this.registryConfig.fee.fees);
|
||||
|
||||
const result = await registryTransactionWithRetry(() =>
|
||||
this.registry.setRecord(
|
||||
{
|
||||
privateKey: this.registryConfig.privateKey,
|
||||
record: applicationRecord,
|
||||
bondId: this.registryConfig.bondId
|
||||
},
|
||||
this.registryConfig.privateKey,
|
||||
fee
|
||||
)
|
||||
);
|
||||
const result = await this.publishRecord(applicationRecord);
|
||||
|
||||
log(`Published application record ${result.id}`);
|
||||
log('Application record data:', applicationRecord);
|
||||
@ -129,6 +117,8 @@ export class Registry {
|
||||
const lrn = this.getLrn(repo);
|
||||
log(`Setting name: ${lrn} for record ID: ${result.id}`);
|
||||
|
||||
const fee = parseGasAndFees(this.registryConfig.fee.gas, this.registryConfig.fee.fees);
|
||||
|
||||
await sleep(SLEEP_DURATION);
|
||||
await registryTransactionWithRetry(() =>
|
||||
this.registry.setName(
|
||||
@ -220,17 +210,7 @@ export class Registry {
|
||||
type: APP_DEPLOYMENT_AUCTION_RECORD_TYPE,
|
||||
};
|
||||
|
||||
const result = await registryTransactionWithRetry(() =>
|
||||
this.registry.setRecord(
|
||||
{
|
||||
privateKey: this.registryConfig.privateKey,
|
||||
record: applicationDeploymentAuction,
|
||||
bondId: this.registryConfig.bondId
|
||||
},
|
||||
this.registryConfig.privateKey,
|
||||
fee
|
||||
)
|
||||
);
|
||||
const result = await this.publishRecord(applicationDeploymentAuction);
|
||||
|
||||
log(`Application deployment auction created: ${auctionResult.auction.id}`);
|
||||
log(`Application deployment auction record published: ${result.id}`);
|
||||
@ -265,12 +245,15 @@ export class Registry {
|
||||
throw new Error(`No record found for ${lrn}`);
|
||||
}
|
||||
|
||||
const hash = await this.generateConfigHash(
|
||||
data.environmentVariables,
|
||||
data.requesterAddress,
|
||||
data.publicKey,
|
||||
data.apiUrl,
|
||||
);
|
||||
let hash;
|
||||
if (Object.keys(data.environmentVariables).length !== 0) {
|
||||
hash = await this.generateConfigHash(
|
||||
data.environmentVariables,
|
||||
data.requesterAddress,
|
||||
data.publicKey,
|
||||
data.apiUrl,
|
||||
);
|
||||
}
|
||||
|
||||
// Create record of type ApplicationDeploymentRequest and publish
|
||||
const applicationDeploymentRequest = {
|
||||
@ -281,9 +264,7 @@ export class Registry {
|
||||
dns: data.dns,
|
||||
|
||||
// https://git.vdb.to/cerc-io/laconic-registry-cli/commit/129019105dfb93bebcea02fde0ed64d0f8e5983b
|
||||
config: JSON.stringify({
|
||||
ref: hash,
|
||||
}),
|
||||
config: JSON.stringify(hash ? { ref: hash } : {}),
|
||||
meta: JSON.stringify({
|
||||
note: `Added by Snowball @ ${DateTime.utc().toFormat(
|
||||
"EEE LLL dd HH:mm:ss 'UTC' yyyy"
|
||||
@ -298,19 +279,7 @@ export class Registry {
|
||||
|
||||
await sleep(SLEEP_DURATION);
|
||||
|
||||
const fee = parseGasAndFees(this.registryConfig.fee.gas, this.registryConfig.fee.fees);
|
||||
|
||||
const result = await registryTransactionWithRetry(() =>
|
||||
this.registry.setRecord(
|
||||
{
|
||||
privateKey: this.registryConfig.privateKey,
|
||||
record: applicationDeploymentRequest,
|
||||
bondId: this.registryConfig.bondId
|
||||
},
|
||||
this.registryConfig.privateKey,
|
||||
fee
|
||||
)
|
||||
);
|
||||
const result = await this.publishRecord(applicationDeploymentRequest);
|
||||
|
||||
log(`Application deployment request record published: ${result.id}`);
|
||||
log('Application deployment request data:', applicationDeploymentRequest);
|
||||
@ -382,12 +351,11 @@ export class Registry {
|
||||
true
|
||||
);
|
||||
|
||||
// Filter records with ApplicationDeploymentRequestId ID and Deployment specific URL
|
||||
// Filter records with ApplicationDeploymentRequestId ID
|
||||
return records.filter((record: AppDeploymentRecord) =>
|
||||
deployments.some(
|
||||
(deployment) =>
|
||||
deployment.applicationDeploymentRequestId === record.attributes.request &&
|
||||
record.attributes.url.includes(deployment.id)
|
||||
deployment.applicationDeploymentRequestId === record.attributes.request
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -442,6 +410,18 @@ export class Registry {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch record by Id
|
||||
*/
|
||||
async getRecordById(id: string): Promise<RegistryRecord | null> {
|
||||
const record = await this.registry.getRecordsByIds([id]);
|
||||
if (record.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return record[0];
|
||||
}
|
||||
|
||||
async createApplicationDeploymentRemovalRequest(data: {
|
||||
deploymentId: string;
|
||||
deployerLrn: string;
|
||||
@ -460,18 +440,8 @@ export class Registry {
|
||||
...(data.payment && { payment: data.payment }),
|
||||
};
|
||||
|
||||
const fee = parseGasAndFees(this.registryConfig.fee.gas, this.registryConfig.fee.fees);
|
||||
|
||||
const result = await registryTransactionWithRetry(() =>
|
||||
this.registry.setRecord(
|
||||
{
|
||||
privateKey: this.registryConfig.privateKey,
|
||||
record: applicationDeploymentRemovalRequest,
|
||||
bondId: this.registryConfig.bondId
|
||||
},
|
||||
this.registryConfig.privateKey,
|
||||
fee
|
||||
)
|
||||
const result = await this.publishRecord(
|
||||
applicationDeploymentRemovalRequest,
|
||||
);
|
||||
|
||||
log(`Application deployment removal request record published: ${result.id}`);
|
||||
@ -497,6 +467,27 @@ export class Registry {
|
||||
return completedAuctions;
|
||||
}
|
||||
|
||||
async publishRecord(recordData: any): Promise<any> {
|
||||
const fee = parseGasAndFees(
|
||||
this.registryConfig.fee.gas,
|
||||
this.registryConfig.fee.fees,
|
||||
);
|
||||
|
||||
const result = await registryTransactionWithRetry(() =>
|
||||
this.registry.setRecord(
|
||||
{
|
||||
privateKey: this.registryConfig.privateKey,
|
||||
record: recordData,
|
||||
bondId: this.registryConfig.bondId,
|
||||
},
|
||||
this.registryConfig.privateKey,
|
||||
fee,
|
||||
),
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
async getRecordsByName(name: string): Promise<any> {
|
||||
return this.registry.resolveNames([name]);
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ export const createResolvers = async (service: Service): Promise<any> => {
|
||||
},
|
||||
|
||||
deployments: async (_: any, { projectId }: { projectId: string }) => {
|
||||
return service.getDeploymentsByProjectId(projectId);
|
||||
return service.getCommitDeploymentsByProjectId(projectId);
|
||||
},
|
||||
|
||||
environmentVariables: async (
|
||||
@ -95,6 +95,13 @@ export const createResolvers = async (service: Service): Promise<any> => {
|
||||
) => {
|
||||
return service.verifyTx(txHash, amount, senderAddress);
|
||||
},
|
||||
|
||||
latestDNSRecord: async (
|
||||
_: any,
|
||||
{ projectId }: { projectId: string },
|
||||
) => {
|
||||
return service.getLatestDNSRecordByProjectId(projectId);
|
||||
},
|
||||
},
|
||||
|
||||
// TODO: Return error in GQL response
|
||||
|
@ -108,6 +108,7 @@ type Deployment {
|
||||
environment: Environment!
|
||||
deployer: Deployer
|
||||
applicationDeploymentRequestId: String
|
||||
applicationDeploymentRecordData: AppDeploymentRecordAttributes
|
||||
isCurrent: Boolean!
|
||||
baseDomain: String
|
||||
status: DeploymentStatus!
|
||||
@ -249,6 +250,27 @@ type Auction {
|
||||
bids: [Bid!]!
|
||||
}
|
||||
|
||||
type DNSRecordAttributes {
|
||||
name: String
|
||||
value: String
|
||||
request: String
|
||||
resourceType: String
|
||||
version: String
|
||||
}
|
||||
|
||||
type AppDeploymentRecordAttributes {
|
||||
application: String
|
||||
auction: String
|
||||
deployer: String
|
||||
dns: String
|
||||
meta: String
|
||||
name: String
|
||||
request: String
|
||||
type: String
|
||||
url: String
|
||||
version: String
|
||||
}
|
||||
|
||||
input AuctionParams {
|
||||
maxPrice: String,
|
||||
numProviders: Int,
|
||||
@ -265,6 +287,7 @@ type Query {
|
||||
projectMembers(projectId: String!): [ProjectMember!]
|
||||
searchProjects(searchText: String!): [Project!]
|
||||
getAuctionData(auctionId: String!): Auction!
|
||||
latestDNSRecord(projectId: String!): DNSRecordAttributes
|
||||
domains(projectId: String!, filter: FilterDomainsInput): [Domain]
|
||||
deployers: [Deployer]
|
||||
address: String!
|
||||
|
@ -1,7 +1,8 @@
|
||||
import assert from 'assert';
|
||||
import debug from 'debug';
|
||||
import { DeepPartial, FindOptionsWhere, IsNull, Not } from 'typeorm';
|
||||
import { DeepPartial, FindOptionsWhere } from 'typeorm';
|
||||
import { Octokit, RequestError } from 'octokit';
|
||||
import { DateTime } from 'luxon';
|
||||
|
||||
import { OAuthApp } from '@octokit/oauth-app';
|
||||
|
||||
@ -22,6 +23,8 @@ import {
|
||||
AppDeploymentRemovalRecord,
|
||||
AuctionParams,
|
||||
DeployerRecord,
|
||||
DNSRecord,
|
||||
DNSRecordAttributes,
|
||||
EnvironmentVariables,
|
||||
GitPushEventPayload,
|
||||
} from './types';
|
||||
@ -199,52 +202,114 @@ export class Service {
|
||||
if (!deployment.project) {
|
||||
log(`Project ${deployment.projectId} not found`);
|
||||
return;
|
||||
} else {
|
||||
deployment.applicationDeploymentRecordId = record.id;
|
||||
deployment.applicationDeploymentRecordData = record.attributes;
|
||||
deployment.url = record.attributes.url;
|
||||
deployment.status = DeploymentStatus.Ready;
|
||||
deployment.isCurrent = deployment.environment === Environment.Production;
|
||||
}
|
||||
|
||||
await this.db.updateDeploymentById(deployment.id, deployment);
|
||||
const registryRecord = await this.laconicRegistry.getRecordById(record.attributes.dns);
|
||||
|
||||
// Release deployer funds on successful deployment
|
||||
if (!deployment.project.fundsReleased) {
|
||||
const fundsReleased = await this.releaseDeployerFundsByProjectId(deployment.projectId);
|
||||
if (!registryRecord) {
|
||||
log(`DNS record not found for deployment ${deployment.id}`);
|
||||
return;
|
||||
}
|
||||
|
||||
// Return remaining amount to owner
|
||||
await this.returnUserFundsByProjectId(deployment.projectId, true);
|
||||
const dnsRecord = registryRecord as DNSRecord;
|
||||
|
||||
await this.db.updateProjectById(deployment.projectId, {
|
||||
fundsReleased,
|
||||
});
|
||||
const dnsRecordData: DNSRecordAttributes = {
|
||||
name: dnsRecord.attributes.name,
|
||||
request: dnsRecord.attributes.request,
|
||||
resourceType: dnsRecord.attributes.resource_type,
|
||||
value: dnsRecord.attributes.value,
|
||||
version: dnsRecord.attributes.version,
|
||||
}
|
||||
|
||||
deployment.applicationDeploymentRecordId = record.id;
|
||||
deployment.applicationDeploymentRecordData = record.attributes;
|
||||
deployment.url = record.attributes.url;
|
||||
deployment.status = DeploymentStatus.Ready;
|
||||
deployment.isCurrent = deployment.environment === Environment.Production;
|
||||
deployment.dnsRecordData = dnsRecordData;
|
||||
|
||||
if (deployment.isDNS) {
|
||||
const oldDNSDeployment = await this.db.getDeployment({
|
||||
where: {
|
||||
projectId: deployment.project.id,
|
||||
deployer: deployment.deployer,
|
||||
isDNS: true,
|
||||
isCurrent: true,
|
||||
},
|
||||
relations: {
|
||||
project: true,
|
||||
deployer: true,
|
||||
}
|
||||
});
|
||||
|
||||
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(oldDNSDeployment.id);
|
||||
}
|
||||
|
||||
log(
|
||||
`Updated deployment ${deployment.id} with URL ${record.attributes.url}`,
|
||||
);
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
await this.db.updateDeploymentById(deployment.id, deployment);
|
||||
|
||||
// Release deployer funds on successful deployment
|
||||
if (!deployment.project.fundsReleased) {
|
||||
const fundsReleased = await this.releaseDeployerFundsByProjectId(deployment.projectId);
|
||||
|
||||
// Return remaining amount to owner
|
||||
await this.returnUserFundsByProjectId(deployment.projectId, true);
|
||||
|
||||
await this.db.updateProjectById(deployment.projectId, {
|
||||
fundsReleased,
|
||||
});
|
||||
}
|
||||
|
||||
log(
|
||||
`Updated deployment ${deployment.id} with URL ${record.attributes.url}`,
|
||||
);
|
||||
});
|
||||
|
||||
await Promise.all(deploymentUpdatePromises);
|
||||
|
||||
// Get deployments that are in production environment
|
||||
const prodDeployments = Object.values(recordToDeploymentsMap).filter(deployment => deployment.isCurrent);
|
||||
|
||||
const prodDeployments = Object.values(recordToDeploymentsMap).filter(
|
||||
(deployment) => deployment.isCurrent,
|
||||
);
|
||||
// Set the isCurrent state to false for the old deployments
|
||||
for (const deployment of prodDeployments) {
|
||||
const projectDeployments = await this.db.getDeploymentsByProjectId(deployment.projectId);
|
||||
const oldDeployments = projectDeployments
|
||||
.filter(projectDeployment => projectDeployment.deployer.deployerLrn === deployment.deployer.deployerLrn && projectDeployment.id !== deployment.id);
|
||||
const projectDeployments = await this.db.getDeploymentsByProjectId(
|
||||
deployment.projectId,
|
||||
);
|
||||
|
||||
const oldDeployments = projectDeployments.filter(
|
||||
(projectDeployment) =>
|
||||
projectDeployment.deployer.deployerLrn ===
|
||||
deployment.deployer.deployerLrn &&
|
||||
projectDeployment.id !== deployment.id &&
|
||||
projectDeployment.isDNS == deployment.isDNS,
|
||||
);
|
||||
for (const oldDeployment of oldDeployments) {
|
||||
await this.db.updateDeployment(
|
||||
{ id: oldDeployment.id },
|
||||
{ isCurrent: false }
|
||||
{ isCurrent: false },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
await Promise.all(deploymentUpdatePromises);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -428,9 +493,14 @@ export class Service {
|
||||
return dbProjects;
|
||||
}
|
||||
|
||||
async getDeploymentsByProjectId(projectId: string): Promise<Deployment[]> {
|
||||
const dbDeployments = await this.db.getDeploymentsByProjectId(projectId);
|
||||
return dbDeployments;
|
||||
async getCommitDeploymentsByProjectId(projectId: string): Promise<Deployment[]> {
|
||||
const commitDeployments = await this.db.getCommitDeploymentsByProjectId(projectId);
|
||||
return commitDeployments;
|
||||
}
|
||||
|
||||
async getLatestDNSRecordByProjectId(projectId: string): Promise<DNSRecordAttributes | null> {
|
||||
const dnsDeployments = await this.db.getLatestDNSRecordByProjectId(projectId);
|
||||
return dnsDeployments;
|
||||
}
|
||||
|
||||
async getEnvironmentVariablesByProjectId(
|
||||
@ -639,51 +709,62 @@ export class Service {
|
||||
deployer = data.deployer;
|
||||
}
|
||||
|
||||
const newDeployment = await this.createDeploymentFromData(userId, data, deployer!.deployerLrn!, applicationRecordId, applicationRecordData);
|
||||
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!);
|
||||
|
||||
// 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) {
|
||||
// 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
|
||||
await this.laconicRegistry.createApplicationDeploymentRequest({
|
||||
deployment: newDeployment,
|
||||
appName: repo,
|
||||
repository: repoUrl,
|
||||
environmentVariables: environmentVariablesObj,
|
||||
dns: `${newDeployment.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: 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!
|
||||
});
|
||||
|
||||
await this.db.updateDeploymentById(dnsDeployment.id, {
|
||||
applicationDeploymentRequestId,
|
||||
applicationDeploymentRequestData,
|
||||
});
|
||||
}
|
||||
|
||||
const { applicationDeploymentRequestId, applicationDeploymentRequestData } =
|
||||
await this.laconicRegistry.createApplicationDeploymentRequest({
|
||||
deployment: newDeployment,
|
||||
deployment: deployment,
|
||||
appName: repo,
|
||||
repository: repoUrl,
|
||||
lrn: deployer!.deployerLrn!,
|
||||
apiUrl: deployer!.deployerApiUrl!,
|
||||
environmentVariables: environmentVariablesObj,
|
||||
dns: `${newDeployment.project.name}-${newDeployment.id}`,
|
||||
dns: `${deployment.project.name}-${deployment.id}`,
|
||||
payment: data.project.txHash,
|
||||
auctionId: data.project.auctionId,
|
||||
requesterAddress: address,
|
||||
publicKey: deployer!.publicKey!
|
||||
});
|
||||
|
||||
await this.db.updateDeploymentById(newDeployment.id, {
|
||||
await this.db.updateDeploymentById(deployment.id, {
|
||||
applicationDeploymentRequestId,
|
||||
applicationDeploymentRequestData,
|
||||
});
|
||||
|
||||
return newDeployment;
|
||||
return deployment;
|
||||
}
|
||||
|
||||
async createDeploymentFromAuction(
|
||||
@ -726,7 +807,8 @@ export class Service {
|
||||
commitMessage: latestCommit.commit.message,
|
||||
};
|
||||
|
||||
const newDeployment = await this.createDeploymentFromData(project.ownerId!, deploymentData, deployerLrn, applicationRecordId, applicationRecordData);
|
||||
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!);
|
||||
@ -734,41 +816,47 @@ export class Service {
|
||||
if (deploymentData.environment === Environment.Production) {
|
||||
// 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
|
||||
await this.laconicRegistry.createApplicationDeploymentRequest({
|
||||
deployment: newDeployment,
|
||||
appName: repo,
|
||||
repository: repoUrl,
|
||||
environmentVariables: environmentVariablesObj,
|
||||
dns: `${newDeployment.project.name}`,
|
||||
auctionId: project.auctionId!,
|
||||
lrn: deployerLrn,
|
||||
apiUrl: deployer!.deployerApiUrl!,
|
||||
requesterAddress: address,
|
||||
publicKey: deployer!.publicKey!
|
||||
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!
|
||||
});
|
||||
|
||||
await this.db.updateDeploymentById(dnsDeployment.id, {
|
||||
applicationDeploymentRequestId,
|
||||
applicationDeploymentRequestData,
|
||||
});
|
||||
}
|
||||
|
||||
const { applicationDeploymentRequestId, applicationDeploymentRequestData } =
|
||||
// Create requests for all the deployers
|
||||
await this.laconicRegistry.createApplicationDeploymentRequest({
|
||||
deployment: newDeployment,
|
||||
deployment: deployment,
|
||||
appName: repo,
|
||||
repository: repoUrl,
|
||||
auctionId: project.auctionId!,
|
||||
lrn: deployerLrn,
|
||||
apiUrl: deployer!.deployerApiUrl!,
|
||||
environmentVariables: environmentVariablesObj,
|
||||
dns: `${newDeployment.project.name}-${newDeployment.id}`,
|
||||
dns: `${deployment.project.name}-${deployment.id}`,
|
||||
requesterAddress: address,
|
||||
publicKey: deployer!.publicKey!
|
||||
});
|
||||
|
||||
await this.db.updateDeploymentById(newDeployment.id, {
|
||||
await this.db.updateDeploymentById(deployment.id, {
|
||||
applicationDeploymentRequestId,
|
||||
applicationDeploymentRequestData,
|
||||
});
|
||||
|
||||
return newDeployment;
|
||||
return deployment;
|
||||
}
|
||||
|
||||
async createDeploymentFromData(
|
||||
@ -777,6 +865,7 @@ export class Service {
|
||||
deployerLrn: string,
|
||||
applicationRecordId: string,
|
||||
applicationRecordData: ApplicationRecord,
|
||||
isDNS: boolean,
|
||||
): Promise<Deployment> {
|
||||
const newDeployment = await this.db.addDeployment({
|
||||
project: data.project,
|
||||
@ -794,6 +883,7 @@ export class Service {
|
||||
deployer: Object.assign(new Deployer(), {
|
||||
deployerLrn,
|
||||
}),
|
||||
isDNS
|
||||
});
|
||||
|
||||
log(`Created deployment ${newDeployment.id}`);
|
||||
@ -1133,17 +1223,20 @@ export class Service {
|
||||
const oldCurrentDeployment = await this.db.getDeployment({
|
||||
relations: {
|
||||
domain: true,
|
||||
project: true,
|
||||
deployer: true,
|
||||
},
|
||||
where: {
|
||||
project: {
|
||||
id: projectId,
|
||||
},
|
||||
isCurrent: true,
|
||||
isDNS: false,
|
||||
},
|
||||
});
|
||||
|
||||
if (!oldCurrentDeployment) {
|
||||
throw new Error('Current deployment doesnot exist');
|
||||
throw new Error('Current deployment does not exist');
|
||||
}
|
||||
|
||||
const oldCurrentDeploymentUpdate = await this.db.updateDeploymentById(
|
||||
@ -1153,9 +1246,46 @@ export class Service {
|
||||
|
||||
const newCurrentDeploymentUpdate = await this.db.updateDeploymentById(
|
||||
deploymentId,
|
||||
{ isCurrent: true, domain: oldCurrentDeployment?.domain },
|
||||
{ isCurrent: true, domain: oldCurrentDeployment.domain },
|
||||
);
|
||||
|
||||
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`);
|
||||
}
|
||||
|
||||
// Create a DNS deployment for the new current deployment
|
||||
const dnsDeployment = await this.createDeploymentFromData(
|
||||
newCurrentDeployment.project.ownerId,
|
||||
newCurrentDeployment,
|
||||
newCurrentDeployment.deployer!.deployerLrn!,
|
||||
newCurrentDeployment.applicationRecordId,
|
||||
newCurrentDeployment.applicationRecordData,
|
||||
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"
|
||||
)}`
|
||||
});
|
||||
|
||||
const result = await this.laconicRegistry.publishRecord(
|
||||
applicationDeploymentRequestData,
|
||||
);
|
||||
|
||||
log(`Application deployment request record published: ${result.id}`)
|
||||
|
||||
await this.db.updateDeploymentById(dnsDeployment.id, {
|
||||
applicationDeploymentRequestId: result.id,
|
||||
applicationDeploymentRequestData,
|
||||
});
|
||||
|
||||
return newCurrentDeploymentUpdate && oldCurrentDeploymentUpdate;
|
||||
}
|
||||
|
||||
@ -1173,32 +1303,38 @@ export class Service {
|
||||
if (deployment && deployment.applicationDeploymentRecordId) {
|
||||
// If deployment is current, remove deployment for project subdomain as well
|
||||
if (deployment.isCurrent) {
|
||||
const currentDeploymentURL = `https://${(deployment.project.name).toLowerCase()}.${deployment.deployer.baseDomain}`;
|
||||
const dnsDeployment = await this.db.getDeployment({
|
||||
where: {
|
||||
projectId: deployment.project.id,
|
||||
deployer: deployment.deployer,
|
||||
isDNS: true
|
||||
},
|
||||
relations: {
|
||||
project: true,
|
||||
deployer: true,
|
||||
},
|
||||
})
|
||||
|
||||
// TODO: Store the latest DNS deployment record
|
||||
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}`,
|
||||
);
|
||||
if (!dnsDeployment) {
|
||||
log(`DNS deployment for deployment with id ${deployment.id} not found`);
|
||||
|
||||
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];
|
||||
const dnsResult =
|
||||
await this.laconicRegistry.createApplicationDeploymentRemovalRequest({
|
||||
deploymentId: dnsDeployment.applicationDeploymentRecordId!,
|
||||
deployerLrn: dnsDeployment.deployer.deployerLrn,
|
||||
auctionId: dnsDeployment.project.auctionId,
|
||||
payment: dnsDeployment.project.txHash
|
||||
});
|
||||
|
||||
await this.laconicRegistry.createApplicationDeploymentRemovalRequest({
|
||||
deploymentId: latestRecord.id,
|
||||
deployerLrn: deployment.deployer.deployerLrn,
|
||||
auctionId: deployment.project.auctionId,
|
||||
payment: deployment.project.txHash
|
||||
await this.db.updateDeploymentById(dnsDeployment.id, {
|
||||
status: DeploymentStatus.Deleting,
|
||||
applicationDeploymentRemovalRequestId:
|
||||
dnsResult.applicationDeploymentRemovalRequestId,
|
||||
applicationDeploymentRemovalRequestData:
|
||||
dnsResult.applicationDeploymentRemovalRequestData,
|
||||
});
|
||||
}
|
||||
|
||||
@ -1229,7 +1365,7 @@ export class Service {
|
||||
data: { name: string },
|
||||
): Promise<{
|
||||
primaryDomain: Domain;
|
||||
redirectedDomain: Domain;
|
||||
// redirectedDomain: Domain;
|
||||
}> {
|
||||
const currentProject = await this.db.getProjectById(projectId);
|
||||
|
||||
@ -1245,22 +1381,22 @@ export class Service {
|
||||
|
||||
const savedPrimaryDomain = await this.db.addDomain(primaryDomainDetails);
|
||||
|
||||
const domainArr = data.name.split('www.');
|
||||
// const domainArr = data.name.split('www.');
|
||||
|
||||
const redirectedDomainDetails = {
|
||||
name: domainArr.length > 1 ? domainArr[1] : `www.${domainArr[0]}`,
|
||||
branch: currentProject.prodBranch,
|
||||
project: currentProject,
|
||||
redirectTo: savedPrimaryDomain,
|
||||
};
|
||||
// const redirectedDomainDetails = {
|
||||
// name: domainArr.length > 1 ? domainArr[1] : `www.${domainArr[0]}`,
|
||||
// branch: currentProject.prodBranch,
|
||||
// project: currentProject,
|
||||
// redirectTo: savedPrimaryDomain,
|
||||
// };
|
||||
|
||||
const savedRedirectedDomain = await this.db.addDomain(
|
||||
redirectedDomainDetails,
|
||||
);
|
||||
// const savedRedirectedDomain = await this.db.addDomain(
|
||||
// redirectedDomainDetails,
|
||||
// );
|
||||
|
||||
return {
|
||||
primaryDomain: savedPrimaryDomain,
|
||||
redirectedDomain: savedRedirectedDomain,
|
||||
// redirectedDomain: savedRedirectedDomain,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,22 @@ export interface AppDeploymentRecordAttributes {
|
||||
version: string;
|
||||
}
|
||||
|
||||
export interface DNSRecordAttributes {
|
||||
name: string;
|
||||
value: string;
|
||||
request: string;
|
||||
resourceType: string;
|
||||
version: string;
|
||||
}
|
||||
|
||||
export interface RegistryDNSRecordAttributes {
|
||||
name: string;
|
||||
value: string;
|
||||
request: string;
|
||||
resource_type: string;
|
||||
version: string;
|
||||
}
|
||||
|
||||
export interface AppDeploymentRemovalRecordAttributes {
|
||||
deployment: string;
|
||||
request: string;
|
||||
@ -47,7 +63,7 @@ export interface AppDeploymentRemovalRecordAttributes {
|
||||
version: string;
|
||||
}
|
||||
|
||||
interface RegistryRecord {
|
||||
export interface RegistryRecord {
|
||||
id: string;
|
||||
names: string[] | null;
|
||||
owners: string[];
|
||||
@ -64,6 +80,10 @@ export interface AppDeploymentRemovalRecord extends RegistryRecord {
|
||||
attributes: AppDeploymentRemovalRecordAttributes;
|
||||
}
|
||||
|
||||
export interface DNSRecord extends RegistryRecord {
|
||||
attributes: RegistryDNSRecordAttributes
|
||||
}
|
||||
|
||||
export interface AddProjectFromTemplateInput {
|
||||
templateOwner: string;
|
||||
templateRepo: string;
|
||||
|
@ -4,7 +4,11 @@ import {
|
||||
MenuItem,
|
||||
MenuList,
|
||||
} from '@snowballtools/material-tailwind-react-fork';
|
||||
import { ComponentPropsWithoutRef, MouseEvent, useCallback } from 'react';
|
||||
import {
|
||||
ComponentPropsWithoutRef,
|
||||
MouseEvent,
|
||||
useCallback,
|
||||
} from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { Project } from 'gql-client';
|
||||
import { Avatar } from 'components/shared/Avatar';
|
||||
@ -83,7 +87,7 @@ export const ProjectCard = ({
|
||||
<p className={theme.title()}>{project.name}</p>
|
||||
</Tooltip>
|
||||
<p className={theme.description()}>
|
||||
{project.deployments[0]?.domain?.name ?? 'No domain'}
|
||||
{project.deployments[0]?.applicationDeploymentRecordData?.url ?? 'No domain'}
|
||||
</p>
|
||||
</div>
|
||||
{/* Icons */}
|
||||
|
@ -566,7 +566,7 @@ const Configure = () => {
|
||||
<Button
|
||||
{...buttonSize}
|
||||
type="submit"
|
||||
disabled={isLoading || !selectedDeployer || !selectedAccount}
|
||||
disabled={isLoading || !selectedDeployer}
|
||||
rightIcon={
|
||||
isLoading ? (
|
||||
<LoadingIcon className="animate-spin" />
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { useState } from 'react';
|
||||
import { Domain, DomainStatus, Project } from 'gql-client';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { DNSRecordAttributes, Domain, DomainStatus, Project } from 'gql-client';
|
||||
|
||||
import {
|
||||
Typography,
|
||||
@ -14,22 +14,27 @@ import EditDomainDialog from './EditDomainDialog';
|
||||
import { useGQLClient } from 'context/GQLClientContext';
|
||||
import { DeleteDomainDialog } from 'components/projects/Dialog/DeleteDomainDialog';
|
||||
import { useToast } from 'components/shared/Toast';
|
||||
import { Tag } from 'components/shared/Tag';
|
||||
import {
|
||||
CheckIcon,
|
||||
CrossIcon,
|
||||
GearIcon,
|
||||
LoadingIcon,
|
||||
} 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';
|
||||
|
||||
enum RefreshStatus {
|
||||
IDLE,
|
||||
CHECKING,
|
||||
CHECK_SUCCESS,
|
||||
CHECK_FAIL,
|
||||
}
|
||||
// NOTE: Commented code for verify domain functionality
|
||||
// import { Tag } from 'components/shared/Tag';
|
||||
// import {
|
||||
// CheckIcon,
|
||||
// CrossIcon,
|
||||
// LoadingIcon,
|
||||
// } from 'components/shared/CustomIcon';
|
||||
|
||||
// enum RefreshStatus {
|
||||
// IDLE,
|
||||
// CHECKING,
|
||||
// CHECK_SUCCESS,
|
||||
// CHECK_FAIL,
|
||||
// }
|
||||
|
||||
// const CHECK_FAIL_TIMEOUT = 5000; // In milliseconds
|
||||
|
||||
interface DomainCardProps {
|
||||
domains: Domain[];
|
||||
@ -39,14 +44,6 @@ interface DomainCardProps {
|
||||
onUpdate: () => Promise<void>;
|
||||
}
|
||||
|
||||
const CHECK_FAIL_TIMEOUT = 5000; // In milliseconds
|
||||
|
||||
// TODO: Get domain record
|
||||
const DOMAIN_RECORD = {
|
||||
type: 'A',
|
||||
name: '@',
|
||||
value: '56.49.19.21',
|
||||
};
|
||||
|
||||
const DomainCard = ({
|
||||
domains,
|
||||
@ -56,9 +53,11 @@ const DomainCard = ({
|
||||
onUpdate,
|
||||
}: DomainCardProps) => {
|
||||
const { toast, dismiss } = useToast();
|
||||
const [refreshStatus, SetRefreshStatus] = useState(RefreshStatus.IDLE);
|
||||
const { id } = useParams();
|
||||
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
|
||||
const [editDialogOpen, setEditDialogOpen] = useState(false);
|
||||
const [dnsRecord, setDnsRecord] = useState<DNSRecordAttributes | null>(null);
|
||||
// const [refreshStatus, SetRefreshStatus] = useState(RefreshStatus.IDLE);
|
||||
|
||||
const client = useGQLClient();
|
||||
|
||||
@ -83,13 +82,33 @@ const DomainCard = ({
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const fetchDNSData = async () => {
|
||||
if (id === undefined) {
|
||||
toast({
|
||||
id: 'domain_cannot_find_project',
|
||||
title: 'Cannot find project',
|
||||
variant: 'error',
|
||||
onDismiss: dismiss,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const dnsRecordResponse = await client.getLatestDNSRecordByProjectId(id);
|
||||
|
||||
setDnsRecord(dnsRecordResponse.latestDNSRecord);
|
||||
};
|
||||
|
||||
fetchDNSData();
|
||||
}, [id, client]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex justify-between py-3">
|
||||
<div className="flex justify-start gap-1">
|
||||
<Heading as="h6" className="flex-col">
|
||||
{domain.name}{' '}
|
||||
<Tag
|
||||
{/* <Tag
|
||||
type={
|
||||
domain.status === DomainStatus.Live ? 'positive' : 'negative'
|
||||
}
|
||||
@ -102,12 +121,12 @@ const DomainCard = ({
|
||||
}
|
||||
>
|
||||
{domain.status}
|
||||
</Tag>
|
||||
</Tag> */}
|
||||
</Heading>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-start gap-1">
|
||||
<i
|
||||
{/* <i
|
||||
id="refresh"
|
||||
className="cursor-pointer"
|
||||
onClick={() => {
|
||||
@ -122,7 +141,7 @@ const DomainCard = ({
|
||||
) : (
|
||||
'L'
|
||||
)}
|
||||
</i>
|
||||
</i> */}
|
||||
<Menu placement="bottom-end">
|
||||
<MenuHandler>
|
||||
<Button iconOnly>
|
||||
@ -163,11 +182,11 @@ 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 ? (
|
||||
{/* {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>
|
||||
@ -178,7 +197,7 @@ const DomainCard = ({
|
||||
hours. Please ensure you added the correct records and refresh.
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
)} */}
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
@ -189,11 +208,15 @@ const DomainCard = ({
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>{DOMAIN_RECORD.type}</td>
|
||||
<td>{DOMAIN_RECORD.name}</td>
|
||||
<td>{DOMAIN_RECORD.value}</td>
|
||||
</tr>
|
||||
{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>
|
||||
|
@ -1,11 +1,15 @@
|
||||
import { useCallback, useEffect, useMemo } from 'react';
|
||||
import { Controller, useForm, SubmitHandler } from 'react-hook-form';
|
||||
import {
|
||||
useCallback,
|
||||
useEffect,
|
||||
} from 'react';
|
||||
import {
|
||||
useForm,
|
||||
SubmitHandler,
|
||||
} from 'react-hook-form';
|
||||
import { Domain } from 'gql-client';
|
||||
|
||||
import {
|
||||
Typography,
|
||||
Select,
|
||||
Option,
|
||||
} from '@snowballtools/material-tailwind-react-fork';
|
||||
|
||||
import { useGQLClient } from 'context/GQLClientContext';
|
||||
@ -14,7 +18,15 @@ import { Button } from 'components/shared/Button';
|
||||
import { Input } from 'components/shared/Input';
|
||||
import { useToast } from 'components/shared/Toast';
|
||||
|
||||
const DEFAULT_REDIRECT_OPTIONS = ['none'];
|
||||
// NOTE: Commented code for redirect domain functionality
|
||||
// import {
|
||||
// Select,
|
||||
// Option,
|
||||
// } from '@snowballtools/material-tailwind-react-fork';
|
||||
// import { Controller } from 'react-hook-form';
|
||||
// import { useMemo } from 'react';
|
||||
|
||||
// const DEFAULT_REDIRECT_OPTIONS = ['none'];
|
||||
|
||||
interface EditDomainDialogProp {
|
||||
domains: Domain[];
|
||||
@ -28,7 +40,7 @@ interface EditDomainDialogProp {
|
||||
type EditDomainValues = {
|
||||
name: string;
|
||||
branch: string;
|
||||
redirectedTo: string;
|
||||
// redirectedTo: string;
|
||||
};
|
||||
|
||||
const EditDomainDialog = ({
|
||||
@ -42,58 +54,58 @@ const EditDomainDialog = ({
|
||||
const client = useGQLClient();
|
||||
const { toast, dismiss } = useToast();
|
||||
|
||||
const getRedirectUrl = (domain: Domain) => {
|
||||
const redirectDomain = domain.redirectTo;
|
||||
// const getRedirectUrl = (domain: Domain) => {
|
||||
// const redirectDomain = domain.redirectTo;
|
||||
|
||||
if (redirectDomain !== null) {
|
||||
return redirectDomain?.name;
|
||||
} else {
|
||||
return 'none';
|
||||
}
|
||||
};
|
||||
// if (redirectDomain !== null) {
|
||||
// return redirectDomain?.name;
|
||||
// } else {
|
||||
// return 'none';
|
||||
// }
|
||||
// };
|
||||
|
||||
const redirectOptions = useMemo(() => {
|
||||
const domainNames = domains
|
||||
.filter((domainData) => domainData.id !== domain.id)
|
||||
.map((domain) => domain.name);
|
||||
return ['none', ...domainNames];
|
||||
}, [domain, domains]);
|
||||
// const redirectOptions = useMemo(() => {
|
||||
// const domainNames = domains
|
||||
// .filter((domainData) => domainData.id !== domain.id)
|
||||
// .map((domain) => domain.name);
|
||||
// return ['none', ...domainNames];
|
||||
// }, [domain, domains]);
|
||||
|
||||
const domainRedirectedFrom = useMemo(() => {
|
||||
return domains.find(
|
||||
(domainData) => domainData.redirectTo?.id === domain.id,
|
||||
);
|
||||
}, [domains, domain]);
|
||||
// const domainRedirectedFrom = useMemo(() => {
|
||||
// return domains.find(
|
||||
// (domainData) => domainData.redirectTo?.id === domain.id,
|
||||
// );
|
||||
// }, [domains, domain]);
|
||||
|
||||
const isDisableDropdown = useMemo(() => {
|
||||
return domainRedirectedFrom !== undefined;
|
||||
}, [domain, domains]);
|
||||
// const isDisableDropdown = useMemo(() => {
|
||||
// return domainRedirectedFrom !== undefined;
|
||||
// }, [domain, domains]);
|
||||
|
||||
const {
|
||||
handleSubmit,
|
||||
register,
|
||||
control,
|
||||
watch,
|
||||
// control,
|
||||
// watch,
|
||||
reset,
|
||||
formState: { isValid, isDirty },
|
||||
} = useForm({
|
||||
defaultValues: {
|
||||
name: domain.name,
|
||||
branch: domain.branch,
|
||||
redirectedTo: getRedirectUrl(domain),
|
||||
// redirectedTo: getRedirectUrl(domain),
|
||||
},
|
||||
});
|
||||
|
||||
const updateDomainHandler: SubmitHandler<EditDomainValues> = useCallback(
|
||||
async (data) => {
|
||||
const domainRedirectTo = domains.find(
|
||||
(domainData) => data.redirectedTo === domainData.name,
|
||||
);
|
||||
// const domainRedirectTo = domains.find(
|
||||
// (domainData) => data.redirectedTo === domainData.name,
|
||||
// );
|
||||
|
||||
const updates = {
|
||||
name: data.name ? data.name : domain.name,
|
||||
branch: data.branch ? data.branch : domain.branch,
|
||||
redirectToId: domainRedirectTo ? domainRedirectTo.id : null,
|
||||
// redirectToId: domainRedirectTo ? domainRedirectTo.id : null,
|
||||
};
|
||||
|
||||
const { updateDomain } = await client.updateDomain(domain.id, updates);
|
||||
@ -125,7 +137,7 @@ const EditDomainDialog = ({
|
||||
reset({
|
||||
name: domain.name,
|
||||
branch: domain.branch,
|
||||
redirectedTo: getRedirectUrl(domain),
|
||||
// redirectedTo: getRedirectUrl(domain),
|
||||
});
|
||||
}, [domain]);
|
||||
|
||||
@ -137,7 +149,7 @@ const EditDomainDialog = ({
|
||||
<Modal.Body className="flex flex-col gap-2">
|
||||
<Typography variant="small">Domain name</Typography>
|
||||
<Input {...register('name')} />
|
||||
<Typography variant="small">Redirect to</Typography>
|
||||
{/* <Typography variant="small">Redirect to</Typography>
|
||||
<Controller
|
||||
name="redirectedTo"
|
||||
control={control}
|
||||
@ -161,7 +173,7 @@ const EditDomainDialog = ({
|
||||
further.
|
||||
</Typography>
|
||||
</div>
|
||||
)}
|
||||
)} */}
|
||||
<Typography variant="small">Git branch</Typography>
|
||||
<Input
|
||||
{...register('branch', {
|
||||
@ -169,8 +181,8 @@ const EditDomainDialog = ({
|
||||
Boolean(branches.length) ? branches.includes(value) : true,
|
||||
})}
|
||||
disabled={
|
||||
!Boolean(branches.length) ||
|
||||
watch('redirectedTo') !== DEFAULT_REDIRECT_OPTIONS[0]
|
||||
!Boolean(branches.length)
|
||||
// || watch('redirectedTo') !== DEFAULT_REDIRECT_OPTIONS[0]
|
||||
}
|
||||
/>
|
||||
{!isValid && (
|
||||
|
@ -1,12 +1,14 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useForm } from 'react-hook-form';
|
||||
|
||||
import { Heading } from 'components/shared/Heading';
|
||||
import { InlineNotification } from 'components/shared/InlineNotification';
|
||||
import { Input } from 'components/shared/Input';
|
||||
import { Button } from 'components/shared/Button';
|
||||
import { Radio } from 'components/shared/Radio';
|
||||
|
||||
// NOTE: Commented code for redirect domain functionality
|
||||
// import { useEffect, useState } from 'react';
|
||||
// import { InlineNotification } from 'components/shared/InlineNotification';
|
||||
// import { Radio } from 'components/shared/Radio';
|
||||
|
||||
interface SetupDomainFormValues {
|
||||
domainName: string;
|
||||
@ -18,47 +20,45 @@ const SetupDomain = () => {
|
||||
register,
|
||||
handleSubmit,
|
||||
formState: { isValid },
|
||||
watch,
|
||||
setValue,
|
||||
// watch,
|
||||
// setValue,
|
||||
} = useForm<SetupDomainFormValues>({
|
||||
defaultValues: {
|
||||
domainName: '',
|
||||
isWWW: 'false',
|
||||
// isWWW: 'false',
|
||||
},
|
||||
mode: 'onChange',
|
||||
});
|
||||
|
||||
const [domainStr, setDomainStr] = useState<string>('');
|
||||
const navigate = useNavigate();
|
||||
const isWWWRadioOptions = [
|
||||
{ label: domainStr, value: 'false' },
|
||||
{ label: `www.${domainStr}`, value: 'true' },
|
||||
];
|
||||
// const [domainStr, setDomainStr] = useState<string>('');
|
||||
// const isWWWRadioOptions = [
|
||||
// { label: domainStr, value: 'false' },
|
||||
// { label: `www.${domainStr}`, value: 'true' },
|
||||
// ];
|
||||
|
||||
useEffect(() => {
|
||||
const subscription = watch((value, { name }) => {
|
||||
if (name === 'domainName' && value.domainName) {
|
||||
const domainArr = value.domainName.split('www.');
|
||||
const cleanedDomain =
|
||||
domainArr.length > 1 ? domainArr[1] : domainArr[0];
|
||||
setDomainStr(cleanedDomain);
|
||||
// useEffect(() => {
|
||||
// const subscription = watch((value, { name }) => {
|
||||
// if (name === 'domainName' && value.domainName) {
|
||||
// const domainArr = value.domainName.split('www.');
|
||||
// const cleanedDomain =
|
||||
// domainArr.length > 1 ? domainArr[1] : domainArr[0];
|
||||
// setDomainStr(cleanedDomain);
|
||||
|
||||
setValue(
|
||||
'isWWW',
|
||||
value.domainName.startsWith('www.') ? 'true' : 'false',
|
||||
);
|
||||
}
|
||||
});
|
||||
// setValue(
|
||||
// 'isWWW',
|
||||
// value.domainName.startsWith('www.') ? 'true' : 'false',
|
||||
// );
|
||||
// }
|
||||
// });
|
||||
|
||||
return () => subscription.unsubscribe();
|
||||
}, [watch, setValue]);
|
||||
// return () => subscription.unsubscribe();
|
||||
// }, [watch, setValue]);
|
||||
|
||||
return (
|
||||
<form
|
||||
onSubmit={handleSubmit(() => {
|
||||
watch('isWWW') === 'true'
|
||||
? navigate(`config?name=www.${domainStr}`)
|
||||
: navigate(`config?name=${domainStr}`);
|
||||
onSubmit={handleSubmit((e) => {
|
||||
navigate(`config?name=${e.domainName}`)
|
||||
})}
|
||||
className="flex flex-col gap-6 w-full"
|
||||
>
|
||||
@ -67,7 +67,7 @@ const SetupDomain = () => {
|
||||
Setup domain name
|
||||
</Heading>
|
||||
<p className="text-slate-500 text-sm font-normal leading-tight">
|
||||
Add your domain and setup redirects
|
||||
Add your domain {/* and setup redirects */}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@ -80,7 +80,7 @@ const SetupDomain = () => {
|
||||
label="Domain name"
|
||||
/>
|
||||
|
||||
{isValid && (
|
||||
{/* {isValid && (
|
||||
<div className="self-stretch flex flex-col gap-4">
|
||||
<Heading className="text-sky-950 text-lg font-medium leading-normal">
|
||||
Primary domain
|
||||
@ -99,7 +99,7 @@ const SetupDomain = () => {
|
||||
}. Redirect preferences can be changed later`}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
)} */}
|
||||
|
||||
<div className="self-stretch">
|
||||
<Button disabled={!isValid} type="submit" shape="default">
|
||||
|
@ -10,6 +10,7 @@ import { DeleteVariableDialog } from 'components/projects/Dialog/DeleteVariableD
|
||||
import { DeleteDomainDialog } from 'components/projects/Dialog/DeleteDomainDialog';
|
||||
import { CancelDeploymentDialog } from 'components/projects/Dialog/CancelDeploymentDialog';
|
||||
import {
|
||||
AppDeploymentRecordAttributes,
|
||||
Deployment,
|
||||
DeploymentStatus,
|
||||
Domain,
|
||||
@ -57,6 +58,7 @@ const deployment: Deployment = {
|
||||
updatedAt: '1677680400', // 2023-03-01T13:00:00Z
|
||||
applicationDeploymentRequestId:
|
||||
'bafyreiaycvq6imoppnpwdve4smj6t6ql5svt5zl3x6rimu4qwyzgjorize',
|
||||
applicationDeploymentRecordData: {} as AppDeploymentRecordAttributes,
|
||||
};
|
||||
|
||||
const domains: Domain[] = [
|
||||
|
@ -1,39 +1,54 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Link, useNavigate, useOutletContext } from 'react-router-dom';
|
||||
import {
|
||||
Link,
|
||||
useOutletContext,
|
||||
} from 'react-router-dom';
|
||||
import { RequestError } from 'octokit';
|
||||
|
||||
import { useOctokit } from 'context/OctokitContext';
|
||||
import { GitCommitWithBranch, OutletContextType } from '../../../../types';
|
||||
import { useGQLClient } from 'context/GQLClientContext';
|
||||
import { Button, Heading, Avatar, Tag } from 'components/shared';
|
||||
import { getInitials } from 'utils/geInitials';
|
||||
import {
|
||||
Heading,
|
||||
Avatar,
|
||||
} from 'components/shared';
|
||||
import {
|
||||
BranchStrokeIcon,
|
||||
CheckRoundFilledIcon,
|
||||
ClockIcon,
|
||||
CursorBoxIcon,
|
||||
GithubStrokeIcon,
|
||||
GlobeIcon,
|
||||
LinkIcon,
|
||||
CalendarDaysIcon,
|
||||
} from 'components/shared/CustomIcon';
|
||||
import { useOctokit } from 'context/OctokitContext';
|
||||
import { GitCommitWithBranch, OutletContextType } from '../../../../types';
|
||||
import { getInitials } from 'utils/geInitials';
|
||||
import { Activity } from 'components/projects/project/overview/Activity';
|
||||
import { OverviewInfo } from 'components/projects/project/overview/OverviewInfo';
|
||||
import { relativeTimeMs } from 'utils/time';
|
||||
import { Domain, DomainStatus } from 'gql-client';
|
||||
import { AuctionCard } from 'components/projects/project/overview/Activity/AuctionCard';
|
||||
|
||||
// NOTE: Commented code for verify domain functionality
|
||||
// import { useGQLClient } from 'context/GQLClientContext';
|
||||
// import { Domain, DomainStatus } from 'gql-client';
|
||||
// import {
|
||||
// CheckRoundFilledIcon,
|
||||
// ClockIcon,
|
||||
// GlobeIcon,
|
||||
// } from 'components/shared/CustomIcon';
|
||||
// import {
|
||||
// Button,
|
||||
// Tag,
|
||||
// } from 'components/shared';
|
||||
// import { useNavigate } from 'react-router-dom';
|
||||
|
||||
const COMMITS_PER_PAGE = 4;
|
||||
const PROJECT_UPDATE_WAIT_MS = 5000;
|
||||
|
||||
const OverviewTabPanel = () => {
|
||||
const { octokit } = useOctokit();
|
||||
const navigate = useNavigate();
|
||||
// const navigate = useNavigate();
|
||||
const [activities, setActivities] = useState<GitCommitWithBranch[]>([]);
|
||||
const [fetchingActivities, setFetchingActivities] = useState(true);
|
||||
const [liveDomain, setLiveDomain] = useState<Domain>();
|
||||
// const [liveDomain, setLiveDomain] = useState<Domain>();
|
||||
|
||||
const client = useGQLClient();
|
||||
// const client = useGQLClient();
|
||||
const { project, onUpdate } = useOutletContext<OutletContextType>();
|
||||
|
||||
useEffect(() => {
|
||||
@ -107,22 +122,22 @@ const OverviewTabPanel = () => {
|
||||
return () => clearInterval(timerId);
|
||||
}, [onUpdate]);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchLiveProdDomain = async () => {
|
||||
const { domains } = await client.getDomains(project.id, {
|
||||
branch: project.prodBranch,
|
||||
status: DomainStatus.Live,
|
||||
});
|
||||
// useEffect(() => {
|
||||
// const fetchLiveProdDomain = async () => {
|
||||
// const { domains } = await client.getDomains(project.id, {
|
||||
// branch: project.prodBranch,
|
||||
// status: DomainStatus.Live,
|
||||
// });
|
||||
|
||||
if (domains.length === 0) {
|
||||
return;
|
||||
}
|
||||
// if (domains.length === 0) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
setLiveDomain(domains[0]);
|
||||
};
|
||||
// setLiveDomain(domains[0]);
|
||||
// };
|
||||
|
||||
fetchLiveProdDomain();
|
||||
}, [project]);
|
||||
// fetchLiveProdDomain();
|
||||
// }, [project]);
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-5 gap-6 md:gap-[72px]">
|
||||
@ -141,19 +156,16 @@ const OverviewTabPanel = () => {
|
||||
{project.deployments &&
|
||||
project.deployments.length > 0 &&
|
||||
project.deployments.map((deployment, index) => (
|
||||
<p>
|
||||
<a
|
||||
key={index}
|
||||
href={`https://${project.name.toLowerCase()}.${deployment.deployer.baseDomain}`}
|
||||
className="text-sm text-elements-low-em dark:text-foreground tracking-tight truncate"
|
||||
>
|
||||
{deployment.deployer.baseDomain}
|
||||
</a>
|
||||
<p
|
||||
key={index}
|
||||
className="text-sm text-elements-low-em dark:text-foreground tracking-tight truncate"
|
||||
>
|
||||
{deployment.deployer.baseDomain}
|
||||
</p>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<OverviewInfo label="Domain" icon={<GlobeIcon />}>
|
||||
{/* <OverviewInfo label="Domain" icon={<GlobeIcon />}>
|
||||
{liveDomain ? (
|
||||
<Tag type="positive" size="xs" leftIcon={<CheckRoundFilledIcon />}>
|
||||
Connected
|
||||
@ -174,7 +186,7 @@ const OverviewTabPanel = () => {
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</OverviewInfo>
|
||||
</OverviewInfo> */}
|
||||
{project.deployments.length !== 0 ? (
|
||||
<>
|
||||
{/* SOURCE */}
|
||||
@ -193,11 +205,9 @@ const OverviewTabPanel = () => {
|
||||
project.deployments.length > 0 &&
|
||||
project.deployments.map((deployment) => (
|
||||
<div className="flex gap-2 items-center">
|
||||
<Link
|
||||
to={`https://${project.name.toLowerCase()}.${deployment.deployer.baseDomain}`}
|
||||
>
|
||||
<Link to={deployment.applicationDeploymentRecordData.url}>
|
||||
<span className="text-controls-primary dark:text-foreground group hover:border-controls-primary transition-colors border-b border-b-transparent flex gap-2 items-center text-sm tracking-tight">
|
||||
{`https://${project.name.toLowerCase()}.${deployment.deployer.baseDomain}`}
|
||||
{deployment.applicationDeploymentRecordData.url}
|
||||
<LinkIcon className="group-hover:rotate-45 transition-transform" />
|
||||
</span>
|
||||
</Link>
|
||||
|
@ -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>
|
||||
);
|
||||
};
|
||||
|
@ -7,6 +7,8 @@ import { InlineNotification } from 'components/shared/InlineNotification';
|
||||
import { ArrowRightCircleIcon } from 'components/shared/CustomIcon';
|
||||
import { ProjectSettingContainer } from 'components/projects/project/settings/ProjectSettingContainer';
|
||||
import { useToast } from 'components/shared/Toast';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { DNSRecordAttributes } from 'gql-client';
|
||||
|
||||
const Config = () => {
|
||||
const { id, orgSlug } = useParams();
|
||||
@ -16,6 +18,8 @@ const Config = () => {
|
||||
const primaryDomainName = searchParams.get('name');
|
||||
const { toast, dismiss } = useToast();
|
||||
|
||||
const [dnsRecord, setDnsRecord] = useState<DNSRecordAttributes | null>(null);
|
||||
|
||||
const handleSubmitDomain = async () => {
|
||||
if (primaryDomainName === null) {
|
||||
toast({
|
||||
@ -59,51 +63,80 @@ const Config = () => {
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const fetchDNSData = async () => {
|
||||
if (id === undefined) {
|
||||
toast({
|
||||
id: 'domain_cannot_find_project',
|
||||
title: 'Cannot find project',
|
||||
variant: 'error',
|
||||
onDismiss: dismiss,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const dnsRecordResponse = await client.getLatestDNSRecordByProjectId(id);
|
||||
|
||||
setDnsRecord(dnsRecordResponse.latestDNSRecord);
|
||||
};
|
||||
|
||||
fetchDNSData();
|
||||
}, [id, client]);
|
||||
|
||||
// TODO: Figure out DNS Provider if possible and update appropriatly
|
||||
return (
|
||||
<ProjectSettingContainer headingText="Setup domain name">
|
||||
<p className="text-blue-gray-500">
|
||||
Add the following records to your domain.
|
||||
</p>
|
||||
{dnsRecord ? (
|
||||
<>
|
||||
<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>
|
||||
<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>A</Table.RowHeaderCell>
|
||||
<Table.Cell>@</Table.Cell>
|
||||
<Table.Cell>IP.OF.THE.SP</Table.Cell>
|
||||
</Table.Row>
|
||||
<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>
|
||||
|
||||
<Table.Row>
|
||||
<Table.RowHeaderCell>CNAME</Table.RowHeaderCell>
|
||||
<Table.Cell>subdomain</Table.Cell>
|
||||
<Table.Cell>domain.of.the.sp</Table.Cell>
|
||||
</Table.Row>
|
||||
</Table.Body>
|
||||
</Table>
|
||||
|
||||
<InlineNotification
|
||||
variant="info"
|
||||
title={`It can take up to 48 hours for these updates to reflect
|
||||
globally.`}
|
||||
/>
|
||||
<Button
|
||||
className="w-fit"
|
||||
onClick={handleSubmitDomain}
|
||||
variant="primary"
|
||||
shape="default"
|
||||
rightIcon={<ArrowRightCircleIcon />}
|
||||
>
|
||||
FINISH
|
||||
</Button>
|
||||
{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>
|
||||
)}
|
||||
</ProjectSettingContainer>
|
||||
);
|
||||
};
|
||||
|
@ -12,6 +12,7 @@ import {
|
||||
Domain,
|
||||
Environment,
|
||||
Permission,
|
||||
AppDeploymentRecordAttributes,
|
||||
} from 'gql-client';
|
||||
|
||||
export const user: User = {
|
||||
@ -111,6 +112,7 @@ export const deployment0: Deployment = {
|
||||
},
|
||||
applicationDeploymentRequestId:
|
||||
'bafyreiaycvq6imoppnpwdve4smj6t6ql5svt5zl3x6rimu4qwyzgjorize',
|
||||
applicationDeploymentRecordData: {} as AppDeploymentRecordAttributes,
|
||||
};
|
||||
|
||||
export const project: Project = {
|
||||
|
@ -453,4 +453,15 @@ export class GQLClient {
|
||||
|
||||
return data.verifyTx;
|
||||
}
|
||||
|
||||
async getLatestDNSRecordByProjectId(projectId: string): Promise<types.GetLatestDNSDataResponse> {
|
||||
const { data } = await this.client.query({
|
||||
query: queries.getLatestDNSRecordByProjectId,
|
||||
variables: {
|
||||
projectId,
|
||||
},
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,9 @@ query ($projectId: String!) {
|
||||
commitHash
|
||||
createdAt
|
||||
environment
|
||||
applicationDeploymentRecordData {
|
||||
url
|
||||
}
|
||||
deployer {
|
||||
baseDomain
|
||||
}
|
||||
@ -112,6 +115,9 @@ query ($organizationSlug: String!) {
|
||||
commitMessage
|
||||
createdAt
|
||||
environment
|
||||
applicationDeploymentRecordData {
|
||||
url
|
||||
}
|
||||
domain {
|
||||
status
|
||||
branch
|
||||
@ -343,3 +349,15 @@ query ($txHash: String!, $amount: String!, $senderAddress: String!) {
|
||||
verifyTx(txHash: $txHash, amount: $amount, senderAddress: $senderAddress)
|
||||
}
|
||||
`;
|
||||
|
||||
export const getLatestDNSRecordByProjectId = gql`
|
||||
query($projectId: String!) {
|
||||
latestDNSRecord(projectId: $projectId) {
|
||||
name
|
||||
value
|
||||
request
|
||||
resourceType
|
||||
version
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
@ -108,6 +108,7 @@ export type Deployment = {
|
||||
environment: Environment;
|
||||
isCurrent: boolean;
|
||||
baseDomain?: string;
|
||||
applicationDeploymentRecordData: AppDeploymentRecordAttributes;
|
||||
status: DeploymentStatus;
|
||||
createdBy: User;
|
||||
createdAt: string;
|
||||
@ -376,3 +377,28 @@ export type AuctionParams = {
|
||||
maxPrice: string;
|
||||
numProviders: number;
|
||||
};
|
||||
|
||||
export type DNSRecordAttributes = {
|
||||
name: string;
|
||||
value: string;
|
||||
request: string;
|
||||
resourceType: string;
|
||||
version: string;
|
||||
}
|
||||
|
||||
export type GetLatestDNSDataResponse = {
|
||||
latestDNSRecord: DNSRecordAttributes | null
|
||||
}
|
||||
|
||||
export interface AppDeploymentRecordAttributes {
|
||||
application: string;
|
||||
auction: string;
|
||||
deployer: string;
|
||||
dns: string;
|
||||
meta: string;
|
||||
name: string;
|
||||
request: string;
|
||||
type: string;
|
||||
url: string;
|
||||
version: string;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user