2024-02-16 09:35:52 +00:00
|
|
|
import debug from 'debug';
|
|
|
|
import { DataSource } from 'typeorm';
|
|
|
|
import path from 'path';
|
|
|
|
|
2024-10-16 08:43:51 +00:00
|
|
|
import { parseGasAndFees, Registry } from '@cerc-io/registry-sdk';
|
2024-02-16 09:35:52 +00:00
|
|
|
|
|
|
|
import { getConfig } from '../src/utils';
|
2024-04-25 11:21:22 +00:00
|
|
|
import { Deployment, DeploymentStatus, Environment } from '../src/entity/Deployment';
|
2024-02-16 09:35:52 +00:00
|
|
|
|
|
|
|
const log = debug('snowball:publish-deploy-records');
|
|
|
|
|
2024-10-16 08:43:51 +00:00
|
|
|
async function main() {
|
|
|
|
const { registryConfig, database, misc } = await getConfig();
|
2024-02-16 09:35:52 +00:00
|
|
|
|
2024-02-22 05:45:17 +00:00
|
|
|
const registry = new Registry(
|
|
|
|
registryConfig.gqlEndpoint,
|
|
|
|
registryConfig.restEndpoint,
|
2024-10-16 08:43:51 +00:00
|
|
|
{ chainId: registryConfig.chainId }
|
2024-02-22 05:45:17 +00:00
|
|
|
);
|
2024-02-16 09:35:52 +00:00
|
|
|
|
|
|
|
const dataSource = new DataSource({
|
|
|
|
type: 'better-sqlite3',
|
|
|
|
database: database.dbPath,
|
|
|
|
synchronize: true,
|
|
|
|
entities: [path.join(__dirname, '../src/entity/*')]
|
|
|
|
});
|
|
|
|
|
|
|
|
await dataSource.initialize();
|
|
|
|
|
|
|
|
const deploymentRepository = dataSource.getRepository(Deployment);
|
|
|
|
const deployments = await deploymentRepository.find({
|
|
|
|
relations: {
|
|
|
|
project: true
|
|
|
|
},
|
|
|
|
where: {
|
|
|
|
status: DeploymentStatus.Building
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
for await (const deployment of deployments) {
|
2024-04-25 11:21:22 +00:00
|
|
|
const url = `https://${deployment.project.name}-${deployment.id}.${misc.projectDomain}`;
|
2024-02-16 09:35:52 +00:00
|
|
|
|
|
|
|
const applicationDeploymentRecord = {
|
|
|
|
type: 'ApplicationDeploymentRecord',
|
|
|
|
version: '0.0.1',
|
2024-02-19 08:13:29 +00:00
|
|
|
name: deployment.applicationRecordData.name,
|
|
|
|
application: deployment.applicationRecordId,
|
2024-02-16 09:35:52 +00:00
|
|
|
|
|
|
|
// TODO: Create DNS record
|
|
|
|
dns: 'bafyreihlymqggsgqiqawvehkpr2imt4l3u6q7um7xzjrux5rhsvwnuyewm',
|
|
|
|
|
|
|
|
// Using dummy values
|
|
|
|
meta: JSON.stringify({
|
|
|
|
config: 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
|
|
|
|
so: '66fcfa49a1664d4cb4ce4f72c1c0e151'
|
|
|
|
}),
|
|
|
|
|
2024-02-22 04:34:33 +00:00
|
|
|
request: deployment.applicationDeploymentRequestId,
|
2024-02-16 09:35:52 +00:00
|
|
|
url
|
|
|
|
};
|
|
|
|
|
2024-10-16 08:43:51 +00:00
|
|
|
const fee = parseGasAndFees(registryConfig.fee.gas, registryConfig.fee.fees);
|
|
|
|
|
2024-02-16 09:35:52 +00:00
|
|
|
const result = await registry.setRecord(
|
|
|
|
{
|
|
|
|
privateKey: registryConfig.privateKey,
|
|
|
|
record: applicationDeploymentRecord,
|
|
|
|
bondId: registryConfig.bondId
|
|
|
|
},
|
|
|
|
'',
|
2024-10-16 08:43:51 +00:00
|
|
|
fee
|
2024-02-16 09:35:52 +00:00
|
|
|
);
|
|
|
|
|
2024-04-25 11:21:22 +00:00
|
|
|
// Remove deployment for project subdomain if deployment is for production environment
|
|
|
|
if (deployment.environment === Environment.Production) {
|
2024-10-11 07:03:25 +00:00
|
|
|
applicationDeploymentRecord.url = `https://${deployment.project.name}.${deployment.baseDomain}`;
|
2024-04-25 11:21:22 +00:00
|
|
|
|
|
|
|
await registry.setRecord(
|
|
|
|
{
|
|
|
|
privateKey: registryConfig.privateKey,
|
|
|
|
record: applicationDeploymentRecord,
|
|
|
|
bondId: registryConfig.bondId
|
|
|
|
},
|
|
|
|
'',
|
2024-10-16 08:43:51 +00:00
|
|
|
fee
|
2024-04-25 11:21:22 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-02-16 09:35:52 +00:00
|
|
|
log('Application deployment record data:', applicationDeploymentRecord);
|
2024-10-16 08:43:51 +00:00
|
|
|
log(`Application deployment record published: ${result.id}`);
|
2024-02-16 09:35:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
main().catch((err) => {
|
|
|
|
log(err);
|
|
|
|
});
|