Store DNS record data for deployments

This commit is contained in:
IshaVenikar 2025-01-30 14:29:46 +05:30
parent 534871a7ae
commit c202554002
5 changed files with 43 additions and 4 deletions

View File

@ -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,
{

View File

@ -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;

View File

@ -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<DNSRecordAttributes[]> {
return this.registry.queryRecords(
{
type: DNS_RECORD_TYPE,
...filter
},
true
);
}
async createApplicationDeploymentRemovalRequest(data: {
deploymentId: string;
deployerLrn: string;

View File

@ -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);

View File

@ -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;