revamp manifest types

This commit is contained in:
Matt Hill
2024-03-21 17:21:37 -06:00
parent ab836c6922
commit 66b0108c51
43 changed files with 279 additions and 834 deletions

View File

@@ -1,16 +1,17 @@
import {
DockerIoFormat,
InstalledState,
Manifest,
PackageDataEntry,
PackageMainStatus,
PackageState,
ServerStatusInfo,
} from 'src/app/services/patch-db/data-model'
import { Metric, NotificationLevel, RR, ServerNotifications } from './api.types'
import { BTC_ICON, LND_ICON, PROXY_ICON } from './api-icons'
import { DependencyMetadata, MarketplacePkg } from '@start9labs/marketplace'
import {
DependencyMetadata,
Manifest,
MarketplacePkg,
} from '@start9labs/marketplace'
import { Log } from '@start9labs/shared'
export module Mock {
@@ -57,14 +58,6 @@ export module Mock {
},
replaces: ['banks', 'governments'],
'release-notes': 'Taproot, Schnorr, and more.',
assets: {
icon: 'icon.png',
license: 'LICENSE.md',
instructions: 'INSTRUCTIONS.md',
docker_images: 'image.tar',
assets: './assets',
scripts: './scripts',
},
license: 'MIT',
'wrapper-repo': 'https://github.com/start9labs/bitcoind-wrapper',
'upstream-repo': 'https://github.com/bitcoin/bitcoin',
@@ -79,231 +72,9 @@ export module Mock {
start: 'Starting Bitcoin is good for your health.',
stop: null,
},
'health-checks': {},
config: {
get: null,
set: null,
},
volumes: {},
'min-os-version': '0.2.12',
backup: {
create: {
type: 'docker',
image: '',
system: true,
entrypoint: '',
args: [],
mounts: {},
'io-format': DockerIoFormat.Yaml,
inject: false,
'shm-size': '',
'sigterm-timeout': null,
},
restore: {
type: 'docker',
image: '',
system: true,
entrypoint: '',
args: [],
mounts: {},
'io-format': DockerIoFormat.Yaml,
inject: false,
'shm-size': '',
'sigterm-timeout': null,
},
},
migrations: null,
actions: {
resync: {
name: 'Resync Blockchain',
description: 'Use this to resync the Bitcoin blockchain from genesis',
warning: 'This will take a couple of days.',
'allowed-statuses': [
PackageMainStatus.Running,
PackageMainStatus.Stopped,
],
implementation: {
type: 'docker',
image: '',
system: true,
entrypoint: '',
args: [],
mounts: {},
'io-format': DockerIoFormat.Yaml,
inject: false,
'shm-size': '',
'sigterm-timeout': null,
},
'input-spec': {
reason: {
type: 'string',
name: 'Re-sync Reason',
description: 'Your reason for re-syncing. Why are you doing this?',
nullable: false,
masked: false,
copyable: false,
pattern: '^[a-zA-Z]+$',
'pattern-description': 'Must contain only letters.',
},
name: {
type: 'string',
name: 'Your Name',
description: 'Tell the class your name.',
nullable: true,
masked: false,
copyable: false,
warning: 'You may loose all your money by providing your name.',
},
notifications: {
name: 'Notification Preferences',
type: 'list',
subtype: 'enum',
description: 'how you want to be notified',
range: '[1,3]',
default: ['email'],
spec: {
'value-names': {
email: 'Email',
text: 'Text',
call: 'Call',
push: 'Push',
webhook: 'Webhook',
},
values: ['email', 'text', 'call', 'push', 'webhook'],
},
},
'days-ago': {
type: 'number',
name: 'Days Ago',
description: 'Number of days to re-sync.',
nullable: false,
default: 100,
range: '[0, 9999]',
integral: true,
},
'top-speed': {
type: 'number',
name: 'Top Speed',
description: 'The fastest you can possibly run.',
nullable: false,
range: '[-1000, 1000]',
integral: false,
units: 'm/s',
},
testnet: {
name: 'Testnet',
type: 'boolean',
description:
'<ul><li>determines whether your node is running on testnet or mainnet</li></ul><script src="fake"></script>',
warning: 'Chain will have to resync!',
default: false,
},
randomEnum: {
name: 'Random Enum',
type: 'enum',
'value-names': {
null: 'Null',
good: 'Good',
bad: 'Bad',
ugly: 'Ugly',
},
default: 'null',
description: 'This is not even real.',
warning: 'Be careful changing this!',
values: ['null', 'good', 'bad', 'ugly'],
},
'emergency-contact': {
name: 'Emergency Contact',
type: 'object',
description: 'The person to contact in case of emergency.',
spec: {
name: {
type: 'string',
name: 'Name',
nullable: false,
masked: false,
copyable: false,
pattern: '^[a-zA-Z]+$',
'pattern-description': 'Must contain only letters.',
},
email: {
type: 'string',
name: 'Email',
nullable: false,
masked: false,
copyable: true,
},
},
},
ips: {
name: 'Whitelist IPs',
type: 'list',
subtype: 'string',
description:
'external ip addresses that are authorized to access your Bitcoin node',
warning:
'Any IP you allow here will have RPC access to your Bitcoin node.',
range: '[1,10]',
default: ['192.168.1.1'],
spec: {
pattern: '^[0-9]{1,3}([,.][0-9]{1,3})?$',
'pattern-description': 'Must be a valid IP address',
masked: false,
copyable: false,
},
},
bitcoinNode: {
type: 'union',
default: 'internal',
tag: {
id: 'type',
'variant-names': {
internal: 'Internal',
external: 'External',
},
name: 'Bitcoin Node Settings',
description: 'The node settings',
warning: 'Careful changing this',
},
variants: {
internal: {
'lan-address': {
name: 'LAN Address',
type: 'pointer',
subtype: 'package',
target: 'lan-address',
description: 'the lan address',
interface: 'tor-address',
'package-id': '12341234',
},
'friendly-name': {
name: 'Friendly Name',
type: 'string',
description: 'the lan address',
nullable: true,
masked: false,
copyable: false,
},
},
external: {
'public-domain': {
name: 'Public Domain',
type: 'string',
description: 'the public address of the node',
nullable: false,
default: 'bitcoinnode.com',
pattern: '.*',
'pattern-description': 'anything',
masked: false,
copyable: true,
},
},
},
},
},
},
},
'os-version': '0.2.12',
dependencies: {},
'has-config': true,
}
export const MockManifestLnd: Manifest = {
@@ -315,14 +86,6 @@ export module Mock {
long: 'More info about LND. More info about LND. More info about LND.',
},
'release-notes': 'Dual funded channels!',
assets: {
icon: 'icon.png',
license: 'LICENSE.md',
instructions: 'INSTRUCTIONS.md',
docker_images: 'image.tar',
assets: './assets',
scripts: './scripts',
},
license: 'MIT',
'wrapper-repo': 'https://github.com/start9labs/lnd-wrapper',
'upstream-repo': 'https://github.com/lightningnetwork/lnd',
@@ -337,82 +100,19 @@ export module Mock {
start: 'Starting LND is good for your health.',
stop: null,
},
'health-checks': {},
config: {
get: null,
set: null,
},
volumes: {},
'min-os-version': '0.2.12',
backup: {
create: {
type: 'docker',
image: '',
system: true,
entrypoint: '',
args: [],
mounts: {},
'io-format': DockerIoFormat.Yaml,
inject: false,
'shm-size': '',
'sigterm-timeout': null,
},
restore: {
type: 'docker',
image: '',
system: true,
entrypoint: '',
args: [],
mounts: {},
'io-format': DockerIoFormat.Yaml,
inject: false,
'shm-size': '',
'sigterm-timeout': null,
},
},
migrations: null,
actions: {
resync: {
name: 'Resync Network Graph',
description: 'Your node will resync its network graph.',
warning: 'This will take a couple hours.',
'allowed-statuses': [PackageMainStatus.Running],
implementation: {
type: 'docker',
image: '',
system: true,
entrypoint: '',
args: [],
mounts: {},
'io-format': DockerIoFormat.Yaml,
inject: false,
'shm-size': '',
'sigterm-timeout': null,
},
'input-spec': null,
},
},
'os-version': '0.2.12',
dependencies: {
bitcoind: {
version: '=0.21.0',
description: 'LND needs bitcoin to live.',
requirement: {
type: 'opt-out',
how: 'You can use an external node from your server if you prefer.',
},
config: null,
optional: true,
},
'btc-rpc-proxy': {
version: '>=0.2.2',
description:
'As long as Bitcoin is pruned, LND needs Bitcoin Proxy to fetch block over the P2P network.',
requirement: {
type: 'opt-in',
how: `To use Proxy's user management system, go to LND config and select Bitcoin Proxy under Bitcoin config.`,
},
config: null,
optional: true,
},
},
'has-config': true,
}
export const MockManifestBitcoinProxy: Manifest = {
@@ -425,14 +125,6 @@ export module Mock {
long: 'More info about Bitcoin Proxy. More info about Bitcoin Proxy. More info about Bitcoin Proxy.',
},
'release-notes': 'Even better support for Bitcoin and wallets!',
assets: {
icon: 'icon.png',
license: 'LICENSE.md',
instructions: 'INSTRUCTIONS.md',
docker_images: 'image.tar',
assets: './assets',
scripts: './scripts',
},
license: 'MIT',
'wrapper-repo': 'https://github.com/start9labs/btc-rpc-proxy-wrapper',
'upstream-repo': 'https://github.com/Kixunil/btc-rpc-proxy',
@@ -446,84 +138,27 @@ export module Mock {
start: null,
stop: null,
},
'health-checks': {},
config: { get: {} as any, set: {} as any },
volumes: {},
'min-os-version': '0.2.12',
backup: {
create: {
type: 'docker',
image: '',
system: true,
entrypoint: '',
args: [''],
mounts: {},
'io-format': DockerIoFormat.Yaml,
inject: false,
'shm-size': '',
'sigterm-timeout': null,
},
restore: {
type: 'docker',
image: '',
system: true,
entrypoint: '',
args: [''],
mounts: {},
'io-format': DockerIoFormat.Yaml,
inject: false,
'shm-size': '',
'sigterm-timeout': null,
},
},
migrations: null,
actions: {},
'os-version': '0.2.12',
dependencies: {
bitcoind: {
version: '>=0.20.0',
description: 'Bitcoin Proxy requires a Bitcoin node.',
requirement: {
type: 'required',
},
config: {
check: {
type: 'docker',
image: 'alpine',
system: true,
entrypoint: 'true',
args: [],
mounts: {},
'io-format': DockerIoFormat.Cbor,
inject: false,
'shm-size': '10m',
'sigterm-timeout': null,
},
'auto-configure': {
type: 'docker',
image: 'alpine',
system: true,
entrypoint: 'cat',
args: [],
mounts: {},
'io-format': DockerIoFormat.Cbor,
inject: false,
'shm-size': '10m',
'sigterm-timeout': null,
},
},
optional: false,
},
},
'has-config': false,
}
export const BitcoinDep: DependencyMetadata = {
title: 'Bitcoin Core',
icon: BTC_ICON,
optional: false,
hidden: true,
}
export const ProxyDep: DependencyMetadata = {
title: 'Bitcoin Proxy',
icon: PROXY_ICON,
optional: true,
hidden: false,
}
@@ -1765,6 +1400,7 @@ export module Mock {
},
'dependency-config-errors': {},
},
actions: {}, // @TODO need mocks
'service-interfaces': {
ui: {
id: 'ui',
@@ -1981,12 +1617,6 @@ export module Mock {
},
},
},
'current-dependents': {
lnd: {
pointers: [],
'health-checks': [],
},
},
'current-dependencies': {},
'dependency-info': {},
'marketplace-url': 'https://registry.start9.com/',
@@ -2007,6 +1637,7 @@ export module Mock {
},
'dependency-config-errors': {},
},
actions: {},
'service-interfaces': {
ui: {
id: 'ui',
@@ -2115,15 +1746,9 @@ export module Mock {
},
},
},
'current-dependents': {
lnd: {
pointers: [],
'health-checks': [],
},
},
'current-dependencies': {
bitcoind: {
pointers: [],
versionRange: '>=26.0.0',
'health-checks': [],
},
},
@@ -2153,6 +1778,7 @@ export module Mock {
'btc-rpc-proxy': 'Username not found',
},
},
actions: {},
'service-interfaces': {
grpc: {
id: 'grpc',
@@ -2365,14 +1991,13 @@ export module Mock {
},
},
},
'current-dependents': {},
'current-dependencies': {
bitcoind: {
pointers: [],
versionRange: '>=26.0.0',
'health-checks': [],
},
'btc-rpc-proxy': {
pointers: [],
versionRange: '>2.0.0', // @TODO
'health-checks': [],
},
},

View File

@@ -1,11 +1,10 @@
import { Dump, Revision } from 'patch-db-client'
import { MarketplacePkg, StoreInfo } from '@start9labs/marketplace'
import { Manifest, MarketplacePkg, StoreInfo } from '@start9labs/marketplace'
import { PackagePropertiesVersioned } from 'src/app/util/properties.util'
import { ConfigSpec } from 'src/app/pkg-config/config-types'
import {
DataModel,
HealthCheckResult,
Manifest,
} from 'src/app/services/patch-db/data-model'
import { StartOSDiskInfo, LogsRes, ServerLogsReq } from '@start9labs/shared'

View File

@@ -571,7 +571,7 @@ export class MockApiService extends ApiService {
setTimeout(async () => {
for (let i = 0; i < ids.length; i++) {
const id = ids[i]
const appPath = `/package-data/${id}/installed/status/main/status`
const appPath = `/package-data/${id}/status/main/status`
const appPatch = [
{
op: PatchOp.REPLACE,
@@ -735,7 +735,7 @@ export class MockApiService extends ApiService {
const patch = [
{
op: PatchOp.REPLACE,
path: `/package-data/${params.id}/installed/status/configured`,
path: `/package-data/${params.id}/status/configured`,
value: true,
},
]
@@ -782,7 +782,7 @@ export class MockApiService extends ApiService {
}
async startPackage(params: RR.StartPackageReq): Promise<RR.StartPackageRes> {
const path = `/package-data/${params.id}/installed/status/main`
const path = `/package-data/${params.id}/status/main`
await pauseFor(2000)
@@ -865,7 +865,7 @@ export class MockApiService extends ApiService {
): Promise<RR.RestartPackageRes> {
// first enact stop
await pauseFor(2000)
const path = `/package-data/${params.id}/installed/status/main`
const path = `/package-data/${params.id}/status/main`
setTimeout(async () => {
const patch2: Operation<any>[] = [
@@ -941,7 +941,7 @@ export class MockApiService extends ApiService {
async stopPackage(params: RR.StopPackageReq): Promise<RR.StopPackageRes> {
await pauseFor(2000)
const path = `/package-data/${params.id}/installed/status/main`
const path = `/package-data/${params.id}/status/main`
setTimeout(() => {
const patch2 = [

View File

@@ -1,6 +1,5 @@
import {
DataModel,
DockerIoFormat,
HealthResult,
PackageMainStatus,
PackageState,
@@ -93,26 +92,33 @@ export const mockPatchData: DataModel = {
started: '2021-06-14T20:49:17.774Z',
health: {
'ephemeral-health-check': {
name: 'Ephemeral Health Check',
result: HealthResult.Starting,
},
'chain-state': {
name: 'Chain State',
result: HealthResult.Loading,
message: 'Bitcoin is syncing from genesis',
},
'p2p-interface': {
name: 'P2P',
result: HealthResult.Success,
message: 'Health check successful',
},
'rpc-interface': {
name: 'RPC',
result: HealthResult.Failure,
error: 'RPC interface unreachable.',
message: 'RPC interface unreachable.',
},
'unnecessary-health-check': {
name: 'Unnecessary Health Check',
result: HealthResult.Disabled,
},
},
},
'dependency-config-errors': {},
},
actions: {}, // @TODO
'service-interfaces': {
ui: {
id: 'ui',
@@ -329,12 +335,6 @@ export const mockPatchData: DataModel = {
},
},
},
'current-dependents': {
lnd: {
pointers: [],
'health-checks': [],
},
},
'current-dependencies': {},
'dependency-info': {},
'marketplace-url': 'https://registry.start9.com/',
@@ -359,6 +359,7 @@ export const mockPatchData: DataModel = {
'btc-rpc-proxy': 'This is a config unsatisfied error',
},
},
actions: {},
'service-interfaces': {
grpc: {
id: 'grpc',
@@ -569,14 +570,13 @@ export const mockPatchData: DataModel = {
},
},
},
'current-dependents': {},
'current-dependencies': {
bitcoind: {
pointers: [],
versionRange: '>=26.0.0',
'health-checks': [],
},
'btc-rpc-proxy': {
pointers: [],
versionRange: '>2.0.0',
'health-checks': [],
},
},

View File

@@ -85,19 +85,14 @@ export class DepErrorService {
}
}
const pkgManifest = pkg['state-info'].manifest
const versionRange = pkg['current-dependencies'][depId].versionRange
const depManifest = dep['state-info'].manifest
// incorrect version
if (
!this.emver.satisfies(
depManifest.version,
pkgManifest.dependencies[depId].version,
)
) {
if (!this.emver.satisfies(depManifest.version, versionRange)) {
return {
type: DependencyErrorType.IncorrectVersion,
expected: pkgManifest.dependencies[depId].version,
expected: versionRange,
received: depManifest.version,
}
}

View File

@@ -1,8 +1,9 @@
import { ConfigSpec } from 'src/app/pkg-config/config-types'
import { Url } from '@start9labs/shared'
import { MarketplaceManifest } from '@start9labs/marketplace'
import { Manifest } from '@start9labs/marketplace'
import { BasicInfo } from 'src/app/pages/developer-routes/developer-menu/form-info'
import { types } from '@start9labs/start-sdk'
import { InputSpec } from '@start9labs/start-sdk/cjs/sdk/lib/config/configTypes'
import { ActionMetadata } from '@start9labs/start-sdk/cjs/sdk/lib/types'
type ServiceInterfaceWithHostInfo = types.ServiceInterfaceWithHostInfo
export interface DataModel {
@@ -111,8 +112,8 @@ export type PackageDataEntry<T extends StateInfo = StateInfo> = {
'state-info': T
icon: Url
status: Status
actions: Record<string, ActionMetadata>
'last-backup': string | null
'current-dependents': { [id: string]: CurrentDependencyInfo }
'current-dependencies': { [id: string]: CurrentDependencyInfo }
'dependency-info': {
[id: string]: {
@@ -152,125 +153,10 @@ export enum PackageState {
}
export interface CurrentDependencyInfo {
pointers: any[]
versionRange: string
'health-checks': string[] // array of health check IDs
}
export interface Manifest extends MarketplaceManifest<DependencyConfig | null> {
assets: {
license: string // filename
instructions: string // filename
icon: string // filename
docker_images: string // filename
assets: string // path to assets folder
scripts: string // path to scripts folder
}
'health-checks': Record<
string,
ActionImpl & { name: string; 'success-message': string | null }
>
config: ConfigActions | null
volumes: Record<string, Volume>
'min-os-version': string
backup: BackupActions
migrations: Migrations | null
actions: Record<string, Action>
}
export interface DependencyConfig {
check: ActionImpl
'auto-configure': ActionImpl
}
export interface ActionImpl {
type: 'docker'
image: string
system: boolean
entrypoint: string
args: string[]
mounts: { [id: string]: string }
'io-format': DockerIoFormat | null
inject: boolean
'shm-size': string
'sigterm-timeout': string | null
}
export enum DockerIoFormat {
Json = 'json',
Yaml = 'yaml',
Cbor = 'cbor',
Toml = 'toml',
}
export interface ConfigActions {
get: ActionImpl | null
set: ActionImpl | null
}
export type Volume = VolumeData
export interface VolumeData {
type: VolumeType.Data
readonly: boolean
}
export interface VolumeAssets {
type: VolumeType.Assets
}
export interface VolumePointer {
type: VolumeType.Pointer
'package-id': string
'volume-id': string
path: string
readonly: boolean
}
export interface VolumeCertificate {
type: VolumeType.Certificate
'interface-id': string
}
export interface VolumeBackup {
type: VolumeType.Backup
readonly: boolean
}
export enum VolumeType {
Data = 'data',
Assets = 'assets',
Pointer = 'pointer',
Certificate = 'certificate',
Backup = 'backup',
}
export interface TorConfig {
'port-mapping': { [port: number]: number }
}
export type LanConfig = {
[port: number]: { ssl: boolean; mapping: number }
}
export interface BackupActions {
create: ActionImpl
restore: ActionImpl
}
export interface Migrations {
from: { [versionRange: string]: ActionImpl }
to: { [versionRange: string]: ActionImpl }
}
export interface Action {
name: string
description: string
warning: string | null
implementation: ActionImpl
'allowed-statuses': (PackageMainStatus.Stopped | PackageMainStatus.Running)[]
'input-spec': ConfigSpec | null
}
export interface Status {
configured: boolean
main: MainStatus
@@ -302,7 +188,7 @@ export interface MainStatusStarting {
export interface MainStatusRunning {
status: PackageMainStatus.Running
started: string // UTC date string
health: { [id: string]: HealthCheckResult }
health: Record<string, HealthCheckResult>
}
export interface MainStatusBackingUp {
@@ -323,12 +209,13 @@ export enum PackageMainStatus {
Restarting = 'restarting',
}
export type HealthCheckResult =
export type HealthCheckResult = { name: string } & (
| HealthCheckResultStarting
| HealthCheckResultLoading
| HealthCheckResultDisabled
| HealthCheckResultSuccess
| HealthCheckResultFailure
)
export enum HealthResult {
Starting = 'starting',
@@ -348,6 +235,7 @@ export interface HealthCheckResultDisabled {
export interface HealthCheckResultSuccess {
result: HealthResult.Success
message: string
}
export interface HealthCheckResultLoading {
@@ -357,7 +245,7 @@ export interface HealthCheckResultLoading {
export interface HealthCheckResultFailure {
result: HealthResult.Failure
error: string
message: string
}
export type InstallingInfo = {

View File

@@ -25,10 +25,7 @@ export function renderPkgStatus(
if (pkg['state-info'].state === PackageState.Installed) {
primary = getPrimaryStatus(pkg.status)
dependency = getDependencyStatus(depErrors)
health = getHealthStatus(
pkg.status,
!isEmptyObject(pkg['state-info'].manifest['health-checks']),
)
health = getHealthStatus(pkg.status)
} else {
primary = pkg['state-info'].state as string as PrimaryStatus
}
@@ -52,29 +49,26 @@ function getDependencyStatus(depErrors: PkgDependencyErrors): DependencyStatus {
: DependencyStatus.Satisfied
}
function getHealthStatus(
status: Status,
hasHealthChecks: boolean,
): HealthStatus | null {
function getHealthStatus(status: Status): HealthStatus | null {
if (status.main.status !== PackageMainStatus.Running || !status.main.health) {
return null
}
const values = Object.values(status.main.health)
if (values.some(h => h.result === 'failure')) {
return HealthStatus.Failure
if (values.some(h => !h.result)) {
return HealthStatus.Waiting
}
if (!values.length && hasHealthChecks) {
return HealthStatus.Waiting
if (values.some(h => h.result === 'failure')) {
return HealthStatus.Failure
}
if (values.some(h => h.result === 'loading')) {
return HealthStatus.Loading
}
if (values.some(h => !h.result || h.result === 'starting')) {
if (values.some(h => h.result === 'starting')) {
return HealthStatus.Starting
}