diff --git a/packages/backend/src/database.ts b/packages/backend/src/database.ts index f20eb455..6499b0e1 100644 --- a/packages/backend/src/database.ts +++ b/packages/backend/src/database.ts @@ -60,7 +60,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, { diff --git a/packages/backend/src/entity/Deployment.ts b/packages/backend/src/entity/Deployment.ts index 5c772b32..021cfc75 100644 --- a/packages/backend/src/entity/Deployment.ts +++ b/packages/backend/src/entity/Deployment.ts @@ -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; diff --git a/packages/backend/src/registry.ts b/packages/backend/src/registry.ts index 4847bd6d..d5f5ec12 100644 --- a/packages/backend/src/registry.ts +++ b/packages/backend/src/registry.ts @@ -16,7 +16,7 @@ import { ApplicationDeploymentRequest, ApplicationDeploymentRemovalRequest } from './entity/Deployment'; -import { AppDeploymentRecord, AppDeploymentRemovalRecord, AuctionParams, DeployerRecord } from './types'; +import { AppDeploymentRecord, AppDeploymentRemovalRecord, AuctionParams, DeployerRecord, DNSRecordAttributes } from './types'; import { getConfig, getRepoDetails, registryTransactionWithRetry, sleep } from './utils'; const log = debug('snowball:registry'); @@ -27,7 +27,8 @@ 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 DNS_RECORD_TYPE = 'DnsRecord'; const SLEEP_DURATION = 1000; // TODO: Move registry code to registry-sdk/watcher-ts @@ -442,6 +443,19 @@ export class Registry { ); } + /** + * Fetch deployment DNS Records by filter + */ + async getDNSRecordsByFilter(filter: { [key: string]: any }): Promise { + return this.registry.queryRecords( + { + type: DNS_RECORD_TYPE, + ...filter + }, + true + ); + } + async createApplicationDeploymentRemovalRequest(data: { deploymentId: string; deployerLrn: string; diff --git a/packages/backend/src/service.ts b/packages/backend/src/service.ts index aa8736a0..d3807dfc 100644 --- a/packages/backend/src/service.ts +++ b/packages/backend/src/service.ts @@ -22,6 +22,7 @@ import { AppDeploymentRemovalRecord, AuctionParams, DeployerRecord, + DNSRecordAttributes, EnvironmentVariables, GitPushEventPayload, } from './types'; @@ -200,11 +201,24 @@ export class Service { log(`Project ${deployment.projectId} not found`); return; } else { + const dnsRecords = await this.laconicRegistry.getDNSRecordsByFilter({ + request: deployment.applicationDeploymentRequestId + }) + + const dnsRecordData: DNSRecordAttributes = { + name: dnsRecords[0].name, + request: dnsRecords[0].request, + resourceType: dnsRecords[0].resourceType, + value: dnsRecords[0].value, + version: dnsRecords[0].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; await this.db.updateDeploymentById(deployment.id, deployment); diff --git a/packages/backend/src/types.ts b/packages/backend/src/types.ts index 83c810ae..96be83d5 100644 --- a/packages/backend/src/types.ts +++ b/packages/backend/src/types.ts @@ -40,6 +40,14 @@ export interface AppDeploymentRecordAttributes { version: string; } +export interface DNSRecordAttributes { + name: string; + value: string; + request: string; + resourceType: string; + version: string; +} + export interface AppDeploymentRemovalRecordAttributes { deployment: string; request: string;