-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: helm chart install & template prototype (#98)
* feat: helm chart install & template prototype feat: cluster ts feat: helm charts install & template prototype * feat(helm): create basic helm chart * feat(helm): helm install in infra * feat(bdk): bdk cluster apply network * feat(bdk): bdk cluster generate network * fix: generate yaml issues * feat(helm): cloud native helm config * feat(helm): aws region choice * feat(helm): bdk network migrate with loadbalancer * feat(bdk): bdk quorum cluster delete network * docs(cluster): write cluster docs * chore: fix command typo and wrong example * fix: cluster generate template func
- Loading branch information
1 parent
00a7e17
commit a49479f
Showing
48 changed files
with
3,032 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Argv } from 'yargs' | ||
|
||
export const command = 'cluster' | ||
|
||
export const desc = '管理 Quorum cluster 的指令' | ||
|
||
export const builder = (yargs: Argv) => { | ||
return yargs.commandDir('cluster').demandCommand() | ||
} | ||
|
||
export const handler = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
import { Argv, Arguments } from 'yargs' | ||
import { ethers } from 'ethers' | ||
import config from '../../config' | ||
import Cluster from '../../service/cluster' | ||
import Wallet from '../../../wallet/service/wallet' | ||
import { onCancel } from '../../../util/error' | ||
import { ClusterCreateType } from '../../model/type/kubernetes.type' | ||
import { WalletType } from '../../../wallet/model/type/wallet.type' | ||
import { defaultNetworkConfig } from '../../model/defaultNetworkConfig' | ||
import prompts from 'prompts' | ||
import ora from 'ora' | ||
|
||
export const command = 'apply' | ||
|
||
export const desc = '產生 Quorum Cluster 所需的相關設定檔案並建立網路' | ||
|
||
interface OptType { | ||
interactive: boolean | ||
} | ||
|
||
export const builder = (yargs: Argv<OptType>) => { | ||
return yargs | ||
.example('bdk quorum cluster apply --interactive', 'Cathay BDK 互動式問答') | ||
.option('interactive', { type: 'boolean', description: '是否使用 Cathay BDK 互動式問答', alias: 'i' }) | ||
} | ||
|
||
export const handler = async (argv: Arguments<OptType>) => { | ||
const cluster = new Cluster(config) | ||
const wallet = new Wallet() | ||
|
||
const confirm: boolean = await (async () => { | ||
const fileList = cluster.getHelmChartFiles() | ||
if (fileList.length !== 0) { | ||
const confirmDelete = (await prompts({ | ||
type: 'confirm', | ||
name: 'value', | ||
message: '⚠️ Detecting quorum cluster already exists. The following processes will remove all existing files. Continue?', | ||
initial: false, | ||
}, { onCancel })).value | ||
if (confirmDelete) { | ||
const spinner = ora('Quorum Cluster Delete ...').start() | ||
cluster.removeHelmChartFiles() | ||
spinner.succeed('Remove all existing files!') | ||
} | ||
return confirmDelete | ||
} else { | ||
return true | ||
} | ||
})() | ||
|
||
if (confirm) { | ||
// network create | ||
const clusterCreate: ClusterCreateType = await (async () => { | ||
if (argv.interactive) { | ||
const { provider } = await prompts({ | ||
type: 'select', | ||
name: 'provider', | ||
message: 'What is your cloud provider?', | ||
choices: [ | ||
{ | ||
title: 'GCP/local', | ||
value: 'local', | ||
}, | ||
{ | ||
title: 'AWS', | ||
value: 'aws', | ||
}, | ||
{ | ||
title: 'Azure', | ||
value: 'azure', | ||
}, | ||
], | ||
initial: 0, | ||
}, { onCancel }) | ||
|
||
let region: string | undefined = '' | ||
if (provider === 'aws') { | ||
const { awsRegion } = await prompts({ | ||
type: 'text', | ||
name: 'awsRegion', | ||
message: 'What is your region?', | ||
initial: 'ap-southeast-2', | ||
}, { onCancel }) | ||
region = awsRegion | ||
} | ||
|
||
const { chainId, validatorNumber, memberNumber } = await prompts([ | ||
{ | ||
type: 'number', | ||
name: 'chainId', | ||
message: 'What is your chain id?', | ||
min: 0, | ||
initial: 81712, | ||
}, | ||
{ | ||
type: 'number', | ||
name: 'validatorNumber', | ||
message: 'How many validator do you want?', | ||
min: 1, | ||
initial: 4, | ||
}, | ||
{ | ||
type: 'number', | ||
name: 'memberNumber', | ||
message: 'How many member do you want?', | ||
min: 0, | ||
initial: 0, | ||
}, | ||
], { onCancel }) | ||
|
||
const { walletOwner } = await prompts({ | ||
type: 'select', | ||
name: 'walletOwner', | ||
message: 'Do you already own a wallet?', | ||
choices: [ | ||
{ | ||
title: 'true', | ||
value: true, | ||
}, | ||
{ | ||
title: 'false', | ||
value: false, | ||
}, | ||
], | ||
initial: 1, | ||
}) | ||
|
||
let walletAddress: string | ||
|
||
if (walletOwner) { | ||
const { address } = await prompts({ | ||
type: 'text', | ||
name: 'address', | ||
message: 'What is your wallet address?', | ||
validate: walletAddress => ethers.utils.isAddress(walletAddress) ? true : 'Address not valid.', | ||
}, { onCancel }) | ||
|
||
walletAddress = address | ||
} else { | ||
const { address, privateKey } = wallet.createWalletAddress(WalletType.ETHEREUM) | ||
walletAddress = address | ||
ora().stopAndPersist({ | ||
text: `Your ${WalletType.ETHEREUM} wallet address: 0x${walletAddress}`, | ||
symbol: '🔑', | ||
}) | ||
ora().stopAndPersist({ | ||
text: `Wallet private key: ${privateKey}`, | ||
symbol: '🔑', | ||
}) | ||
} | ||
|
||
const alloc = [{ | ||
account: walletAddress, | ||
amount: '1000000000000000000000000000', | ||
}] | ||
|
||
const isBootNode = false | ||
const bootNodeList: boolean[] = Array(validatorNumber + memberNumber).fill(false) | ||
|
||
return { provider, region, chainId, validatorNumber, memberNumber, alloc, isBootNode, bootNodeList } | ||
} else { | ||
const { address, privateKey } = wallet.createWalletAddress(WalletType.ETHEREUM) | ||
const config = defaultNetworkConfig(address, privateKey) | ||
return { ...config, provider: 'local' } | ||
} | ||
})() | ||
const spinner = ora('Quorum Cluster Apply ...').start() | ||
await cluster.apply(clusterCreate, spinner) | ||
spinner.succeed('Quorum Cluster Apply Successfully!') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Argv } from 'yargs' | ||
import config from '../../config' | ||
import Cluster from '../../service/cluster' | ||
import { onCancel } from '../../../util/error' | ||
import prompts from 'prompts' | ||
import ora from 'ora' | ||
|
||
export const command = 'delete' | ||
|
||
export const desc = '刪除現有的 Quorum Cluster 網路' | ||
|
||
interface OptType { | ||
interactive: boolean | ||
} | ||
|
||
export const builder = (yargs: Argv<OptType>) => { | ||
return yargs | ||
.example('bdk quorum cluster delete', 'Cathay BDK 互動式問答') | ||
} | ||
|
||
export const handler = async () => { | ||
const cluster = new Cluster(config) | ||
|
||
const confirm: boolean = await (async () => { | ||
const fileList = cluster.getHelmChartFiles() | ||
if (fileList.length !== 0) { | ||
const confirmDelete = (await prompts({ | ||
type: 'confirm', | ||
name: 'value', | ||
message: '⚠️ Detecting quorum cluster already exists. The following processes will remove all existing files. Continue?', | ||
initial: false, | ||
}, { onCancel })).value | ||
if (confirmDelete) { | ||
const spinner = ora('Quorum Cluster Create ...').start() | ||
cluster.removeHelmChartFiles() | ||
spinner.succeed('Remove all existing files!') | ||
} | ||
return confirmDelete | ||
} else { | ||
return true | ||
} | ||
})() | ||
|
||
if (confirm) { | ||
const spinner = ora('Deployments Under Namespace Quorum Delete ...').start() | ||
await cluster.delete() | ||
spinner.succeed('Quorum Cluster Delete Successfully!') | ||
} | ||
} |
Oops, something went wrong.