Integrate SP auctions for app deployment #2
@ -6,7 +6,6 @@ import { DeepPartial } from 'typeorm';
|
|||||||
import { Octokit } from 'octokit';
|
import { Octokit } from 'octokit';
|
||||||
|
|
||||||
import { Registry as LaconicRegistry, getGasPrice, parseGasAndFees } from '@cerc-io/registry-sdk';
|
import { Registry as LaconicRegistry, getGasPrice, parseGasAndFees } from '@cerc-io/registry-sdk';
|
||||||
import { Auction } from '@cerc-io/registry-sdk/dist/proto/cerc/auction/v1/auction';
|
|
||||||
|
|
||||||
import { RegistryConfig } from './config';
|
import { RegistryConfig } from './config';
|
||||||
import {
|
import {
|
||||||
@ -15,7 +14,7 @@ import {
|
|||||||
ApplicationDeploymentRequest,
|
ApplicationDeploymentRequest,
|
||||||
ApplicationDeploymentRemovalRequest
|
ApplicationDeploymentRemovalRequest
|
||||||
} from './entity/Deployment';
|
} from './entity/Deployment';
|
||||||
import { AppDeploymentRecord, AppDeploymentRemovalRecord, AuctionData, PackageJSON } from './types';
|
import { AppDeploymentRecord, AppDeploymentRemovalRecord, Auction, AuctionData, PackageJSON } from './types';
|
||||||
import { getConfig, sleep } from './utils';
|
import { getConfig, sleep } from './utils';
|
||||||
|
|
||||||
const log = debug('snowball:registry');
|
const log = debug('snowball:registry');
|
||||||
@ -195,7 +194,7 @@ export class Registry {
|
|||||||
})
|
})
|
||||||
).data.html_url;
|
).data.html_url;
|
||||||
|
|
||||||
// TODO: Set environment variables for each deployment (environment variables can`t be set in application record)
|
// TODO: Set environment variables for each deployment (environment variables can't be set in application record)
|
||||||
const { applicationRecordId } =
|
const { applicationRecordId } =
|
||||||
await this.createApplicationRecord({
|
await this.createApplicationRecord({
|
||||||
appName: repo,
|
appName: repo,
|
||||||
@ -221,7 +220,6 @@ export class Registry {
|
|||||||
const auctionConfig = config.auction;
|
const auctionConfig = config.auction;
|
||||||
|
|
||||||
const fee = parseGasAndFees(this.registryConfig.fee.gas, this.registryConfig.fee.fees);
|
const fee = parseGasAndFees(this.registryConfig.fee.gas, this.registryConfig.fee.fees);
|
||||||
|
|
||||||
const auctionResult = await this.registry.createProviderAuction(
|
const auctionResult = await this.registry.createProviderAuction(
|
||||||
{
|
{
|
||||||
commitFee: auctionConfig.commitFee,
|
commitFee: auctionConfig.commitFee,
|
||||||
@ -472,7 +470,6 @@ export class Registry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getRecordsByName(name: string): Promise<any> {
|
async getRecordsByName(name: string): Promise<any> {
|
||||||
|
|
||||||
return this.registry.resolveNames([name]);
|
return this.registry.resolveNames([name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ export class Service {
|
|||||||
|
|
||||||
const recordToDeploymentsMap = deployments.reduce(
|
const recordToDeploymentsMap = deployments.reduce(
|
||||||
(acc: { [key: string]: Deployment }, deployment) => {
|
(acc: { [key: string]: Deployment }, deployment) => {
|
||||||
acc[deployment.applicationRecordId] = deployment;
|
acc[deployment.applicationDeploymentRequestId!] = deployment;
|
||||||
return acc;
|
return acc;
|
||||||
},
|
},
|
||||||
{},
|
{},
|
||||||
@ -202,7 +202,7 @@ export class Service {
|
|||||||
|
|
||||||
// Update deployment data for ApplicationDeploymentRecords
|
// Update deployment data for ApplicationDeploymentRecords
|
||||||
const deploymentUpdatePromises = records.map(async (record) => {
|
const deploymentUpdatePromises = records.map(async (record) => {
|
||||||
const deployment = recordToDeploymentsMap[record.attributes.application];
|
const deployment = recordToDeploymentsMap[record.attributes.request];
|
||||||
|
|
||||||
await this.db.updateDeploymentById(deployment.id, {
|
await this.db.updateDeploymentById(deployment.id, {
|
||||||
applicationDeploymentRecordId: record.id,
|
applicationDeploymentRecordId: record.id,
|
||||||
@ -282,11 +282,11 @@ export class Service {
|
|||||||
const completedAuctionIds = await this.registry.getCompletedAuctionIds(auctionIds);
|
const completedAuctionIds = await this.registry.getCompletedAuctionIds(auctionIds);
|
||||||
|
|
||||||
if (completedAuctionIds) {
|
if (completedAuctionIds) {
|
||||||
const auctionProjects = projects.filter((project) =>
|
const projectsToBedeployed = projects.filter((project) =>
|
||||||
completedAuctionIds.includes(project.auctionId!)
|
completedAuctionIds.includes(project.auctionId!)
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const project of auctionProjects) {
|
for (const project of projectsToBedeployed) {
|
||||||
await this.createDeploymentFromAuction(project);
|
await this.createDeploymentFromAuction(project);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -688,12 +688,12 @@ export class Service {
|
|||||||
async createDeploymentFromAuction(
|
async createDeploymentFromAuction(
|
||||||
project: DeepPartial<Project>,
|
project: DeepPartial<Project>,
|
||||||
) {
|
) {
|
||||||
const deployerLrns = await this.registry.getAuctionWinners(project!.auctionId!);
|
|
||||||
|
|
||||||
// Update project with deployer LRNs
|
// Update project with deployer LRNs
|
||||||
|
const deployerLrns = await this.registry.getAuctionWinners(project!.auctionId!);
|
||||||
await this.db.updateProjectById(project.id!, {
|
await this.db.updateProjectById(project.id!, {
|
||||||
deployerLrn: deployerLrns
|
deployerLrn: deployerLrns
|
||||||
})
|
})
|
||||||
|
|
||||||
const octokit = await this.getOctokit(project.ownerId!);
|
const octokit = await this.getOctokit(project.ownerId!);
|
||||||
const [owner, repo] = project.repository!.split('/');
|
const [owner, repo] = project.repository!.split('/');
|
||||||
|
|
||||||
|
@ -70,6 +70,25 @@ export interface AddProjectFromTemplateInput {
|
|||||||
isPrivate: boolean;
|
isPrivate: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface Auction {
|
||||||
|
id: string;
|
||||||
|
kind: string;
|
||||||
|
status: string;
|
||||||
|
ownerAddress: string;
|
||||||
|
createTime?: Date;
|
||||||
|
commitsEndTime?: Date;
|
||||||
|
revealsEndTime?: Date;
|
||||||
|
commitFee?: string;
|
||||||
|
revealFee?: string;
|
||||||
|
minimumBid?: string;
|
||||||
|
winnerAddresses: string[];
|
||||||
|
winningBids: string[];
|
||||||
|
winningPrice?: string;
|
||||||
|
maxPrice?: string;
|
||||||
|
numProviders: number;
|
||||||
|
fundsReleased: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export interface AuctionData {
|
export interface AuctionData {
|
||||||
maxPrice: string,
|
maxPrice: string,
|
||||||
numProviders: number,
|
numProviders: number,
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import assert from 'assert';
|
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import toml from 'toml';
|
import toml from 'toml';
|
||||||
|
Loading…
Reference in New Issue
Block a user