script(*): add config.sh
This commit is contained in:
parent
6a9cce1b76
commit
91fccf8380
|
@ -0,0 +1,19 @@
|
|||
---
|
||||
name: 'Bug Report'
|
||||
about: 'As a User, I want to report a Bug.'
|
||||
labels: bug
|
||||
---
|
||||
|
||||
## Bug Report
|
||||
|
||||
Please answer these questions before submitting your issue. Thanks!
|
||||
|
||||
### 1. What did you do?
|
||||
|
||||
<!-- If possible, provide a recipe for reproducing the error. -->
|
||||
|
||||
### 2. What did you expect to see?
|
||||
|
||||
### 3. What did you see instead?
|
||||
|
||||
### 4. What version of BitXHub are you using? (`bitxhub version` on BitXHub)
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
name: 'Development Task'
|
||||
about: 'As a BitXHub developer, I want to record a development task.'
|
||||
labels: enhancement
|
||||
---
|
||||
|
||||
## Development Task
|
|
@ -0,0 +1,19 @@
|
|||
---
|
||||
name: 'Feature Request'
|
||||
about: 'As a user, I want to request a New Feature on the product.'
|
||||
labels: feature
|
||||
---
|
||||
|
||||
## Feature Request
|
||||
|
||||
**Is your feature request related to a problem? Please describe:**
|
||||
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->
|
||||
|
||||
**Describe the feature you'd like:**
|
||||
<!-- A clear and concise description of what you want to happen. -->
|
||||
|
||||
**Describe alternatives you've considered:**
|
||||
<!-- A clear and concise description of any alternative solutions or features you've considered. -->
|
||||
|
||||
**Teachability, Documentation, Adoption, Migration Strategy:**
|
||||
<!-- If you can, explain some scenarios how users might use this, situations it would be helpful in. Any API designs, mockups, or diagrams are also helpful. -->
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
name: 'Ask a Question'
|
||||
about: 'I want to ask a question.'
|
||||
labels: question
|
||||
---
|
||||
|
||||
## General Question
|
|
@ -11,7 +11,6 @@ dump
|
|||
build
|
||||
build_solo
|
||||
build.tar.gz
|
||||
bitxhub/bitxhub
|
||||
cover.out
|
||||
coverage.out
|
||||
cover.html
|
||||
|
|
140
CONTRIBUTING.md
140
CONTRIBUTING.md
|
@ -1 +1,141 @@
|
|||
# Contributing
|
||||
|
||||
## <a name="submit"></a> Submission Guidelines
|
||||
|
||||
### <a name="submit-pr"></a> Submitting a Pull Request (PR)
|
||||
Before you submit your Pull Request (PR) consider the following guidelines:
|
||||
|
||||
1. Search [GitHub](https://github.com/meshplus/bitxhub/pulls) for an open or closed PR
|
||||
that relates to your submission. You don't want to duplicate effort.
|
||||
1. Be sure that an issue describes the problem you're fixing, or documents the design for the feature you'd like to add.
|
||||
Discussing the design up front helps to ensure that we're ready to accept your work.
|
||||
1. Fork the meshplus/bitxhub repo.
|
||||
1. Make your changes in a new git branch:
|
||||
|
||||
```shell
|
||||
git checkout -b my-fix-branch master
|
||||
```
|
||||
|
||||
1. Create your patch, **including appropriate test cases**.
|
||||
1. Follow gofmt and golint specifications.
|
||||
1. Run the full test suite and ensure that all tests pass.
|
||||
1. Commit your changes using a descriptive commit message that follows our
|
||||
[commit message conventions](#commit). Adherence to these conventions
|
||||
is necessary because release notes are automatically generated from these messages.
|
||||
|
||||
```shell
|
||||
git commit -a
|
||||
```
|
||||
|
||||
Note: the optional commit `-a` command line option will automatically "add" and "rm" edited files.
|
||||
|
||||
1. Push your branch to GitHub:
|
||||
|
||||
```shell
|
||||
git push origin my-fix-branch
|
||||
```
|
||||
|
||||
1. In GitHub, send a pull request to `bitxhub:master`.
|
||||
|
||||
* If we suggest changes then:
|
||||
* Make the required updates.
|
||||
* Re-run the test suites to ensure tests are still passing.
|
||||
* Rebase your branch and force push to your GitHub repository (this will update your Pull Request):
|
||||
|
||||
```shell
|
||||
git rebase master -i
|
||||
git push -f
|
||||
```
|
||||
|
||||
That's it! Thank you for your contribution!
|
||||
|
||||
#### After your pull request is merged
|
||||
|
||||
After your pull request is merged, you can safely delete your branch and pull the changes
|
||||
from the main (upstream) repository:
|
||||
|
||||
* Delete the remote branch on GitHub either through the GitHub web UI or your local shell as follows:
|
||||
|
||||
```shell
|
||||
git push origin --delete my-fix-branch
|
||||
```
|
||||
|
||||
* Check out the master branch:
|
||||
|
||||
```shell
|
||||
git checkout master -f
|
||||
```
|
||||
|
||||
* Delete the local branch:
|
||||
|
||||
```shell
|
||||
git branch -D my-fix-branch
|
||||
```
|
||||
|
||||
* Update your master with the latest upstream version:
|
||||
|
||||
```shell
|
||||
git pull --ff upstream master
|
||||
```
|
||||
|
||||
## <a name="commit"> Commit Message Guidelines
|
||||
|
||||
Commit Message in this repository should strictly follow the [AngularJS Git Commit Message Conventions](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#-commit-message-guidelines). We explain the conventions below. For detail explanation, it can be found in this [document](https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit#).
|
||||
|
||||
### Commit Message Format
|
||||
|
||||
Each commit message consists of a **header**, a **body** and a **footer**. The header has a special
|
||||
format that includes a **type**, a **scope** and a **subject**:
|
||||
|
||||
```
|
||||
<type>(<scope>): <subject>
|
||||
<BLANK LINE>
|
||||
<body>
|
||||
<BLANK LINE>
|
||||
<footer>
|
||||
```
|
||||
|
||||
The **header** is mandatory and the **scope** of the header is optional.
|
||||
|
||||
Any line of the commit message cannot be longer than 100 characters! This allows the message to be easier
|
||||
to read on GitHub as well as in various git tools.
|
||||
|
||||
The footer should contain a [closing reference to an issue](https://help.github.com/articles/closing-issues-via-commit-messages/) if any.
|
||||
|
||||
### Revert
|
||||
|
||||
If the commit reverts a previous commit, it should begin with `revert:`, followed by the header of the reverted commit. In the body it should say: `This reverts commit <hash>.`, where the hash is the SHA of the commit being reverted.
|
||||
|
||||
### Type
|
||||
|
||||
Must be one of the following:
|
||||
|
||||
* **build**: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
|
||||
* **ci**: Changes to our CI configuration files and scripts (example scopes: Circle, BrowserStack, SauceLabs)
|
||||
* **docs**: Documentation only changes
|
||||
* **feat**: A new feature
|
||||
* **fix**: A bug fix
|
||||
* **perf**: A code change that improves performance
|
||||
* **refactor**: A code change that neither fixes a bug nor adds a feature
|
||||
* **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
|
||||
* **test**: Adding missing tests or correcting existing tests
|
||||
|
||||
### Subject
|
||||
|
||||
The subject contains a succinct description of the change:
|
||||
|
||||
* use the imperative, present tense: "change" not "changed" nor "changes"
|
||||
* don't capitalize the first letter
|
||||
* no dot (.) at the end
|
||||
|
||||
### Body
|
||||
|
||||
Just as in the **subject**, use the imperative, present tense: "change" not "changed" nor "changes".
|
||||
The body should include the motivation for the change and contrast this with previous behavior.
|
||||
|
||||
### Footer
|
||||
|
||||
The footer should contain any information about **Breaking Changes** and is also the place to
|
||||
reference GitHub issues that this commit **Closes**.
|
||||
|
||||
**Breaking Changes** should start with the word `BREAKING CHANGE:` with a space or two newlines. The rest of the commit message is then used for this.
|
||||
|
|
15
Makefile
15
Makefile
|
@ -51,13 +51,12 @@ install:
|
|||
$(GO) install -ldflags '${LDFLAGS}' ./cmd/${APP_NAME}
|
||||
@printf "${GREEN}Build bitxhub successfully!${NC}\n"
|
||||
|
||||
## make build-linux: Go build linux executable file
|
||||
build-linux:
|
||||
cd scripts && sh cross_compile.sh linux-amd64 ${CURRENT_PATH}
|
||||
|
||||
## make docs-build: Build vuepress docs
|
||||
docs-build:
|
||||
cd docs && sudo vuepress build
|
||||
build:
|
||||
cd internal/repo && packr
|
||||
@mkdir -p bin
|
||||
$(GO) build -ldflags '${LDFLAGS}' ./cmd/${APP_NAME}
|
||||
@mv ./bitxhub bin
|
||||
@printf "${GREEN}Build bitxhub successfully!${NC}\n"
|
||||
|
||||
## make linter: Run golanci-lint
|
||||
linter:
|
||||
|
@ -68,6 +67,6 @@ linter:
|
|||
|
||||
## make cluster: Run cluster including 4 nodes
|
||||
cluster:
|
||||
cd scripts && sh cluster.sh 4
|
||||
@cd scripts && bash cluster.sh
|
||||
|
||||
.PHONY: tester
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
@ -13,7 +11,6 @@ import (
|
|||
"github.com/libp2p/go-libp2p-core/crypto"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
"github.com/meshplus/bitxhub-kit/crypto/asym/ecdsa"
|
||||
"github.com/meshplus/bitxhub-kit/fileutil"
|
||||
"github.com/meshplus/bitxhub/internal/repo"
|
||||
"github.com/meshplus/bitxhub/pkg/cert"
|
||||
"github.com/urfave/cli"
|
||||
|
@ -53,12 +50,25 @@ func keyCMD() cli.Command {
|
|||
},
|
||||
{
|
||||
Name: "pid",
|
||||
Usage: "Show pid from cert",
|
||||
Usage: "Show pid from private key",
|
||||
Action: getPid,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "path",
|
||||
Usage: "Private Key Path",
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "address",
|
||||
Usage: "Show address from private",
|
||||
Action: getAddress,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "path",
|
||||
Usage: "Specific private key path",
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -85,7 +95,7 @@ func generateKey(ctx *cli.Context) error {
|
|||
return fmt.Errorf("create account error: %s", err)
|
||||
}
|
||||
|
||||
out, err := json.Marshal(act)
|
||||
out, err := act.Pretty()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -97,28 +107,12 @@ func generateKey(ctx *cli.Context) error {
|
|||
}
|
||||
|
||||
keyPath := filepath.Join(repoRoot, repo.KeyName)
|
||||
ok := fileutil.Exist(keyPath)
|
||||
if ok {
|
||||
fmt.Println("Key file already exists")
|
||||
fmt.Println("Recreate would overwrite your key, Y/N?")
|
||||
input := bufio.NewScanner(os.Stdin)
|
||||
input.Scan()
|
||||
if input.Text() == "Y" || input.Text() == "y" {
|
||||
err := ioutil.WriteFile(keyPath, out, os.ModePerm)
|
||||
if err != nil {
|
||||
return fmt.Errorf("write key file: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(keyPath, out, os.ModePerm)
|
||||
err = ioutil.WriteFile(keyPath, []byte(out), os.ModePerm)
|
||||
if err != nil {
|
||||
return fmt.Errorf("write key file: %w", err)
|
||||
}
|
||||
} else {
|
||||
fmt.Println(string(out))
|
||||
fmt.Println(out)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -167,3 +161,28 @@ func getPid(ctx *cli.Context) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getAddress(ctx *cli.Context) error {
|
||||
privPath := ctx.String("path")
|
||||
|
||||
data, err := ioutil.ReadFile(privPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("read private key: %w", err)
|
||||
}
|
||||
|
||||
stdPriv, err := cert.ParsePrivateKey(data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
privKey := &ecdsa.PrivateKey{K: stdPriv}
|
||||
|
||||
act, err := key.NewWithPrivateKey(privKey, "bitxhub")
|
||||
if err != nil {
|
||||
return fmt.Errorf("create account error: %s", err)
|
||||
}
|
||||
|
||||
fmt.Println(act.Address)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
# Config
|
||||
|
||||
BitXHub包括bitxhub.toml、network.tom和order.toml三个配置文件。
|
|
@ -14,14 +14,14 @@ solo = false
|
|||
allowed_origins = ["*"]
|
||||
|
||||
[log]
|
||||
level = "debug"
|
||||
level = "info"
|
||||
dir = "logs"
|
||||
filename = "bitxhub.log"
|
||||
report_caller = true
|
||||
report_caller = false
|
||||
[log.module]
|
||||
p2p = "debug"
|
||||
consensus = "debug"
|
||||
executor = "debug"
|
||||
p2p = "info"
|
||||
consensus = "info"
|
||||
executor = "info"
|
||||
router = "info"
|
||||
api = "info"
|
||||
coreapi = "info"
|
||||
|
|
|
@ -46,7 +46,7 @@ func New(logger logrus.FieldLogger, repo *repo.Repo, ledger ledger.Ledger, peerM
|
|||
}
|
||||
|
||||
func (router *InterchainRouter) Start() error {
|
||||
router.logger.Infof("router module started")
|
||||
router.logger.Infof("Router module started")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ func (router *InterchainRouter) Start() error {
|
|||
func (router *InterchainRouter) Stop() error {
|
||||
router.cancel()
|
||||
|
||||
router.logger.Infof("router module stopped")
|
||||
router.logger.Infof("Router module stopped")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
CURRENT_PATH=$(pwd)
|
||||
BUILD_PATH=${CURRENT_PATH}/build
|
||||
N=$1
|
||||
|
||||
function splitWindow() {
|
||||
tmux splitw -v -p 50
|
||||
tmux splitw -h -p 50
|
||||
tmux selectp -t 0
|
||||
tmux splitw -h -p 50
|
||||
}
|
||||
|
||||
function start() {
|
||||
cd ${CURRENT_PATH}
|
||||
rm -rf build
|
||||
tar -xf build.tar.gz
|
||||
pkill -9 bitxhub
|
||||
tmux kill-session -t bitxhub
|
||||
tmux new -d -s bitxhub
|
||||
|
||||
cd build
|
||||
for ((i=0;i<N/4;i=i+1)); do
|
||||
splitWindow
|
||||
tmux new-window
|
||||
done
|
||||
splitWindow
|
||||
for ((i = 0;i < N;i = i + 1)); do
|
||||
tmux selectw -t $(($i / 4))
|
||||
tmux selectp -t $(($i % 4))
|
||||
cp bitxhub ./node$(($i + 1))/
|
||||
mkdir ./node$(($i + 1))/plugins
|
||||
cp *.so ./node$(($i + 1))/plugins/
|
||||
tmux send-keys "cd ${BUILD_PATH} && ./node$(($i + 1))/bitxhub --repo=${BUILD_PATH}/node$(($i + 1)) start" C-m
|
||||
done
|
||||
tmux selectw -t 0
|
||||
}
|
||||
|
||||
start
|
|
@ -1,26 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
CURRENT_PATH=$(pwd)
|
||||
PROJECT_PATH=$(dirname "${CURRENT_PATH}")
|
||||
BUILD_PATH=${CURRENT_PATH}/build
|
||||
N=$1
|
||||
|
||||
function build_config() {
|
||||
bash config.sh "${N}"
|
||||
}
|
||||
|
||||
function build_plugins() {
|
||||
## build plugin(make plugin type=<rbft> or <raft>)
|
||||
cd "${PROJECT_PATH}"/internal/plugins
|
||||
make raft
|
||||
|
||||
for ((i = 1; i < N + 1; i = i + 1)); do
|
||||
mkdir -p "${BUILD_PATH}"/node${i}
|
||||
cp -rf "${PROJECT_PATH}"/internal/plugins/build "${BUILD_PATH}"/node${i}/plugins
|
||||
done
|
||||
}
|
||||
|
||||
build_config
|
||||
build_plugins
|
|
@ -1,22 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
CURRENT_PATH=$(pwd)
|
||||
PROJECT_PATH=$(dirname "${CURRENT_PATH}")
|
||||
BUILD_PATH=${CURRENT_PATH}/build
|
||||
CERT_PATH=${CURRENT_PATH}/cert
|
||||
N=$1
|
||||
|
||||
mkdir -p "${CERT_PATH}"
|
||||
cd "${CERT_PATH}"
|
||||
|
||||
## Generate ca private key and cert
|
||||
premo cert ca
|
||||
|
||||
for ((i = 1; i < N + 1; i = i + 1)); do
|
||||
mkdir -p "${CERT_PATH}"/node${i}
|
||||
cd "${CERT_PATH}"/node${i}
|
||||
premo cert issue --name agency --priv ../ca.priv --cert ../ca.cert --org=Hyperchain
|
||||
premo cert issue --name node --priv ./agency.priv --cert ./agency.cert --org=Agency${i}
|
||||
done
|
|
@ -4,14 +4,65 @@ set -e
|
|||
|
||||
CURRENT_PATH=$(pwd)
|
||||
PROJECT_PATH=$(dirname "${CURRENT_PATH}")
|
||||
CONFIG_PATH=${PROJECT_PATH}/config
|
||||
BUILD_PATH=${CURRENT_PATH}/build
|
||||
N=$1
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
N=4
|
||||
|
||||
function print_blue() {
|
||||
printf "${BLUE}%s${NC}\n" "$1"
|
||||
}
|
||||
|
||||
# The sed commend with system judging
|
||||
# Examples:
|
||||
# sed -i 's/a/b/g' bob.txt => x_replace 's/a/b/g' bob.txt
|
||||
function x_replace() {
|
||||
system=$(uname)
|
||||
|
||||
if [ "${system}" = "Linux" ]; then
|
||||
sed -i "$@"
|
||||
else
|
||||
sed -i '' "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
function prepare() {
|
||||
bash build.sh "${N}"
|
||||
print_blue "===> Generating $N nodes configuration"
|
||||
rm -rf "${BUILD_PATH}"
|
||||
mkdir "${BUILD_PATH}"
|
||||
for ((i = 1; i < N + 1; i = i + 1)); do
|
||||
root=${BUILD_PATH}/node${i}
|
||||
mkdir -p "${root}"
|
||||
|
||||
cp -rf "${CURRENT_PATH}"/certs/node${i}/certs "${root}"
|
||||
cp -rf "${CONFIG_PATH}"/* "${root}"
|
||||
|
||||
echo " #!/usr/bin/env bash" >"${root}"/start.sh
|
||||
echo "./bitxhub --root \$(pwd)" start >>"${root}"/start.sh
|
||||
|
||||
bitxhubConfig=${root}/bitxhub.toml
|
||||
networkConfig=${root}/network.toml
|
||||
x_replace "s/60011/6001${i}/g" "${bitxhubConfig}"
|
||||
x_replace "s/9091/909${i}/g" "${bitxhubConfig}"
|
||||
x_replace "s/53121/5312${i}/g" "${bitxhubConfig}"
|
||||
x_replace "s/9091/909${i}/g" "${root}"/api
|
||||
x_replace "1s/1/${i}/" "${networkConfig}"
|
||||
done
|
||||
|
||||
print_blue "===> Building plugin"
|
||||
cd "${PROJECT_PATH}"/internal/plugins
|
||||
make raft
|
||||
|
||||
for ((i = 1; i < N + 1; i = i + 1)); do
|
||||
cp -rf "${PROJECT_PATH}"/internal/plugins/build "${BUILD_PATH}"/node${i}/plugins
|
||||
done
|
||||
}
|
||||
|
||||
function compile() {
|
||||
print_blue "===> Compiling bitxhub"
|
||||
cd "${PROJECT_PATH}"
|
||||
make install
|
||||
}
|
||||
|
@ -24,6 +75,7 @@ function splitWindow() {
|
|||
}
|
||||
|
||||
function start() {
|
||||
print_blue "===> Staring cluster"
|
||||
#osascript ${PROJECT_PATH}/scripts/split.scpt ${N} ${DUMP_PATH}/cluster/node
|
||||
tmux new -d -s bitxhub || (tmux kill-session -t bitxhub && tmux new -d -s bitxhub)
|
||||
|
||||
|
|
|
@ -2,63 +2,97 @@
|
|||
|
||||
set -e
|
||||
|
||||
source x.sh
|
||||
|
||||
CURRENT_PATH=$(pwd)
|
||||
PROJECT_PATH=$(dirname "${CURRENT_PATH}")
|
||||
BUILD_PATH=${CURRENT_PATH}/build
|
||||
CONFIG_PATH=${PROJECT_PATH}/config
|
||||
BUILD_PATH=${CURRENT_PATH}/build
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
N=$1
|
||||
|
||||
function print_blue() {
|
||||
printf "${BLUE}%s${NC}\n" "$1"
|
||||
}
|
||||
|
||||
function print_red() {
|
||||
printf "${RED}%s${NC}\n" "$1"
|
||||
}
|
||||
|
||||
# The sed commend with system judging
|
||||
# Examples:
|
||||
# sed -i 's/a/b/g' bob.txt => x_replace 's/a/b/g' bob.txt
|
||||
function x_replace() {
|
||||
system=$(uname)
|
||||
|
||||
if [ "${system}" = "Linux" ]; then
|
||||
sed -i "$@"
|
||||
else
|
||||
sed -i '' "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
function prepare() {
|
||||
cd "${PROJECT_PATH}"
|
||||
make build
|
||||
|
||||
rm -rf "${BUILD_PATH}"
|
||||
mkdir "${BUILD_PATH}"
|
||||
mkdir "${BUILD_PATH}"/certs
|
||||
|
||||
cd "${PROJECT_PATH}"/internal/plugins
|
||||
make raft
|
||||
}
|
||||
|
||||
function generate_certs() {
|
||||
for ((i = 1; i < N + 1; i = i + 1)); do
|
||||
if [[ $i -le 4 ]]; then
|
||||
cp -rf "${CURRENT_PATH}"/certs/node${i} "${BUILD_PATH}"/certs
|
||||
else
|
||||
certs_path=${BUILD_PATH}/certs/node${i}/certs
|
||||
mkdir -p "${certs_path}"
|
||||
cp "${CURRENT_PATH}"/certs/ca.cert "${CURRENT_PATH}"/certs/agency.cert "${certs_path}"
|
||||
premo cert priv --name node --target "${certs_path}"
|
||||
premo cert csr --key "${certs_path}"/node.priv --org Node${i} --target "${certs_path}"
|
||||
premo cert issue --csr "${certs_path}"/node.csr \
|
||||
--key "${CURRENT_PATH}"/certs/ca.priv \
|
||||
--cert "${CURRENT_PATH}"/certs/ca.cert \
|
||||
--target "${certs_path}"
|
||||
|
||||
premo key convert --path "${certs_path}"/node.priv --target "${BUILD_PATH}"/certs/node${i}
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Generate config
|
||||
function generate() {
|
||||
cd "${BUILD_PATH}"
|
||||
cp "${PROJECT_PATH}"/bin/bitxhub "${BUILD_PATH}"
|
||||
cp -rf "${PROJECT_PATH}"/internal/plugins/build/raft.so "${BUILD_PATH}"
|
||||
|
||||
bitxhub cert ca
|
||||
bitxhub cert priv --name agency
|
||||
bitxhub cert csr --key ./agency.priv --org Agency
|
||||
bitxhub cert issue --key ./ca.priv --cert ./ca.cert --csr ./agency.csr --is_ca true
|
||||
rm agency.csr
|
||||
|
||||
for ((i = 1; i < N + 1; i = i + 1)); do
|
||||
root=${BUILD_PATH}/node${i}
|
||||
mkdir -p "${root}"
|
||||
cp -rf "${BUILD_PATH}"/certs/node${i}/* "${root}"
|
||||
cp -rf "${CONFIG_PATH}"/* "${root}"
|
||||
repo=${BUILD_PATH}/node${i}
|
||||
mkdir -p "${repo}"
|
||||
bitxhub --repo="${repo}" init
|
||||
|
||||
echo "#!/usr/bin/env bash" >"${root}"/start.sh
|
||||
echo "./bitxhub --root \$(pwd)" start >>"${root}"/start.sh
|
||||
mkdir -p "${repo}"/plugins
|
||||
mkdir -p "${repo}"/certs
|
||||
|
||||
bitxhubConfig=${root}/bitxhub.toml
|
||||
networkConfig=${root}/network.toml
|
||||
x_replace "s/60011/6001${i}/g" "${bitxhubConfig}"
|
||||
x_replace "s/60011/6001${i}/g" "${bitxhubConfig}"
|
||||
x_replace "s/9091/909${i}/g" "${bitxhubConfig}"
|
||||
x_replace "s/53121/5312${i}/g" "${bitxhubConfig}"
|
||||
x_replace "s/9091/909${i}/g" "${root}"/api
|
||||
x_replace "1s/1/${i}/" "${networkConfig}"
|
||||
cd "${repo}"/certs
|
||||
bitxhub cert priv --name node
|
||||
bitxhub cert csr --key ./node.priv --org Node${i}
|
||||
bitxhub cert issue --key "${BUILD_PATH}"/agency.priv --cert "${BUILD_PATH}"/agency.cert --csr ./node.csr
|
||||
cp "${BUILD_PATH}"/ca.cert "${repo}"/certs
|
||||
cp "${BUILD_PATH}"/agency.cert "${repo}"/certs
|
||||
rm "${repo}"/certs/node.csr
|
||||
|
||||
id=$(bitxhub --repo="${repo}" key pid --path "${repo}"/certs/node.priv)
|
||||
addr=$(bitxhub --repo="${repo}" key address --path "${repo}"/certs/node.priv)
|
||||
|
||||
echo "${id}" >>"${BUILD_PATH}"/pids
|
||||
echo "${addr}" >>"${BUILD_PATH}"/addresses
|
||||
|
||||
echo "#!/usr/bin/env bash" >"${repo}"/start.sh
|
||||
echo "./bitxhub --repo \$(pwd)" start >>"${repo}"/start.sh
|
||||
done
|
||||
}
|
||||
|
||||
print_green "Generating $1 nodes configuration..."
|
||||
function printHelp() {
|
||||
print_blue "Usage: "
|
||||
echo " config.sh <number>"
|
||||
echo " <number> - node number"
|
||||
echo " config.sh -h (print this message)"
|
||||
}
|
||||
|
||||
if [ ! $1 ]; then
|
||||
printHelp
|
||||
exit 1
|
||||
fi
|
||||
|
||||
prepare
|
||||
generate_certs
|
||||
generate
|
||||
|
|
|
@ -1,87 +0,0 @@
|
|||
set -e
|
||||
|
||||
source x.sh
|
||||
|
||||
CURRENT_PATH=$(pwd)
|
||||
PROJECT_PATH=$(dirname "${CURRENT_PATH}")
|
||||
BUILD_PATH=${CURRENT_PATH}/build
|
||||
|
||||
USERNAME=hyperchain
|
||||
SERVER_BUILD_PATH="/home/hyperchain/bitxhub"
|
||||
N=$1
|
||||
IP=$2
|
||||
RECOMPILE=$3
|
||||
|
||||
if [ "$#" -ne 3 ]; then
|
||||
echo "Illegal number of parameters"
|
||||
exit
|
||||
fi
|
||||
|
||||
while getopts "h?n:r:" opt; do
|
||||
case "$opt" in
|
||||
h | \?)
|
||||
help
|
||||
exit 0
|
||||
;;
|
||||
n)
|
||||
N=$OPTARG
|
||||
;;
|
||||
r)
|
||||
RECOMPILE=$OPTARG
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
function build() {
|
||||
bash config.sh "$N"
|
||||
}
|
||||
|
||||
function compile() {
|
||||
if [[ $RECOMPILE == true ]]; then
|
||||
cd "${PROJECT_PATH}"
|
||||
make build-linux
|
||||
else
|
||||
echo "Do not need compile"
|
||||
fi
|
||||
}
|
||||
|
||||
function prepare() {
|
||||
cd "${CURRENT_PATH}"
|
||||
cp ../bin/bitxhub_linux-amd64 "${BUILD_PATH}"/bitxhub
|
||||
cp ../internal/plugins/build/*.so "${BUILD_PATH}"/
|
||||
tar cf build.tar.gz build
|
||||
}
|
||||
|
||||
function deploy() {
|
||||
cd "${CURRENT_PATH}"
|
||||
#ssh-copy-id -i ~/.ssh/id_rsa.pub hyperchain@${IP}
|
||||
scp build.tar.gz ${USERNAME}@"${IP}":${SERVER_BUILD_PATH}
|
||||
scp boot_bitxhub.sh ${USERNAME}@"${IP}":${SERVER_BUILD_PATH}
|
||||
|
||||
ssh -t ${USERNAME}@"${IP}" '
|
||||
cd '${SERVER_BUILD_PATH}'
|
||||
bash boot_bitxhub.sh 4
|
||||
tmux attach-session -t bitxhub
|
||||
'
|
||||
}
|
||||
|
||||
# help prompt message
|
||||
function help() {
|
||||
echo "deploy.sh helper:"
|
||||
echo " -h, --help: show the help for this bash script"
|
||||
echo " -n, --number: bitxhub node to be started"
|
||||
echo " -r, --recompile: need compile or not"
|
||||
echo "---------------------------------------------------"
|
||||
echo "Example for deploy 4 node in server:"
|
||||
echo "./deploy.sh -n 4 -r 1"
|
||||
}
|
||||
|
||||
print_blue "1. Generate config"
|
||||
build
|
||||
|
||||
print_blue "2. Compile bitxhub"
|
||||
compile
|
||||
prepare
|
||||
|
||||
print_blue "3. Deploy bitxhub"
|
||||
deploy
|
|
@ -1,20 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
# integration test script
|
||||
CURRENT_PATH=$(pwd)
|
||||
PROJECT_PATH=$(dirname "${CURRENT_PATH}")
|
||||
BUILD_PATH=${CURRENT_PATH}/build
|
||||
N=$1
|
||||
|
||||
sh build.sh "$N"
|
||||
|
||||
cd "${PROJECT_PATH}"
|
||||
make install
|
||||
|
||||
bitxhub version
|
||||
for ((i = 1; i < N + 1; i = i + 1)); do
|
||||
echo "Start node${i}"
|
||||
nohup bitxhub --repo="${BUILD_PATH}"/node${i} start &
|
||||
done
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
set -e
|
||||
|
||||
source x.sh
|
||||
|
||||
CURRENT_PATH=$(pwd)
|
||||
PROJECT_PATH=$(dirname "${CURRENT_PATH}")
|
||||
BUILD_PATH=${CURRENT_PATH}/build_solo
|
||||
|
@ -12,11 +14,12 @@ function prepare() {
|
|||
}
|
||||
|
||||
function config() {
|
||||
mkdir -p ${BUILD_PATH}/certs
|
||||
mkdir -p "${BUILD_PATH}"/certs
|
||||
cp -r "${CURRENT_PATH}"/certs/node1/certs/* "${BUILD_PATH}"/certs
|
||||
}
|
||||
|
||||
function compile() {
|
||||
print_blue "===> Compileing bitxhub"
|
||||
cd "${PROJECT_PATH}"
|
||||
make install
|
||||
|
||||
|
@ -26,7 +29,11 @@ function compile() {
|
|||
}
|
||||
|
||||
function start() {
|
||||
print_blue "===> Start solo bitxhub"
|
||||
bitxhub --repo="${BUILD_PATH}" init
|
||||
bitxhubConfig=${BUILD_PATH}/bitxhub.toml
|
||||
x_replace "s/solo = false/solo = true/g" "${bitxhubConfig}"
|
||||
x_replace "s/raft.so/solo.so/g" "${bitxhubConfig}"
|
||||
mkdir -p "${BUILD_PATH}"/plugins
|
||||
cp "${PROJECT_PATH}"/internal/plugins/build/solo.so "${BUILD_PATH}"/plugins/
|
||||
bitxhub --repo="${BUILD_PATH}" start
|
||||
|
|
Loading…
Reference in New Issue