Update method to rollback deployment
This commit is contained in:
parent
8553c30b0d
commit
59329c18f6
@ -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}`);
|
||||
@ -299,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);
|
||||
@ -472,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}`);
|
||||
@ -509,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]);
|
||||
}
|
||||
|
@ -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';
|
||||
|
||||
@ -260,7 +261,7 @@ export class Service {
|
||||
const customDomain = await this.db.getOldestDomainByProjectId(deployment.project.id);
|
||||
|
||||
if (customDomain) {
|
||||
await this.db.updateDeploymentById(deployment.id, { domain: customDomain });
|
||||
deployment.domain = customDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1222,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(
|
||||
@ -1242,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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user