2024-02-16 09:35:52 +00:00
|
|
|
import debug from 'debug';
|
|
|
|
import { DataSource } from 'typeorm';
|
|
|
|
import path from 'path';
|
|
|
|
|
|
|
|
import { Registry } from '@cerc-io/laconic-sdk';
|
|
|
|
|
|
|
|
import { Config } from '../src/config';
|
2024-02-22 11:56:26 +00:00
|
|
|
import { DEFAULT_CONFIG_FILE_PATH } from '../src/constants';
|
2024-02-16 09:35:52 +00:00
|
|
|
import { getConfig } from '../src/utils';
|
|
|
|
import { Deployment, DeploymentStatus } from '../src/entity/Deployment';
|
|
|
|
|
|
|
|
const log = debug('snowball:publish-deploy-records');
|
|
|
|
|
|
|
|
async function main () {
|
2024-02-22 11:56:26 +00:00
|
|
|
const { registryConfig, database, misc } = await getConfig<Config>(DEFAULT_CONFIG_FILE_PATH);
|
2024-02-16 09:35:52 +00:00
|
|
|
|
2024-02-22 05:45:17 +00:00
|
|
|
const registry = new Registry(
|
|
|
|
registryConfig.gqlEndpoint,
|
|
|
|
registryConfig.restEndpoint,
|
|
|
|
registryConfig.chainId
|
|
|
|
);
|
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-02-22 11:56:26 +00:00
|
|
|
const url = `${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
|
|
|
|
};
|
|
|
|
|
|
|
|
const result = await registry.setRecord(
|
|
|
|
{
|
|
|
|
privateKey: registryConfig.privateKey,
|
|
|
|
record: applicationDeploymentRecord,
|
|
|
|
bondId: registryConfig.bondId
|
|
|
|
},
|
|
|
|
'',
|
|
|
|
registryConfig.fee
|
|
|
|
);
|
|
|
|
|
|
|
|
log('Application deployment record data:', applicationDeploymentRecord);
|
|
|
|
log(`Application deployment record published: ${result.data.id}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
main().catch((err) => {
|
|
|
|
log(err);
|
|
|
|
});
|