diff --git a/README.md b/README.md index 6ebed35f7c4cbb3f6d10e54cd3b4f8d313585f6a..0ec67df7fdb8238edb64dbd49b992c868fb325c4 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Eris DB is Eris' blockchain client. It includes a permissions layer, an implemen ## Background -See the [eris-db documentation](https://erisindustries.com/components/erisdb/) for more information. +See the [eris-db documentation](https://monax.io/docs/documentation/db/) for more information. ## Installation @@ -28,98 +28,22 @@ See the [eris-db documentation](https://erisindustries.com/components/erisdb/) f 1. [Install go](https://golang.org/doc/install) 2. Ensure you have `gmp` installed (`sudo apt-get install libgmp3-dev || brew install gmp`) -3. `go get github.com/eris-ltd/eris-db/cmd/erisdb` +3. `go get github.com/eris-ltd/eris-db/cmd/eris-db` -To run `erisdb`, just type `$ erisdb /path/to/working/folder` +To run `eris-db`, just type `$ eris-db serve --work-dir <path to chain directory>` This will start the node using the provided folder as working dir. If the path is omitted it defaults to `~/.erisdb` ## Usage -Once the server has started, it will begin syncing up with the network. At that point you may begin using it. The preferred way is through our [javascript api](https://github.com/eris-ltd/eris-db.js), but it is possible to connect directly via HTTP or websocket. The JSON-RPC and web-api reference can be found [here](api) +Once the server has started, it will begin syncing up with the network. At that point you may begin using it. The preferred way is through our [javascript api](https://github.com/eris-ltd/eris-db.js), but it is possible to connect directly via HTTP or websocket. The JSON-RPC and web-api reference can be found [here](docs/api.md) -### Configuration Files +## Configuration -Three files are currently required: -``` -config.toml -genesis.json -priv_validator.json -``` -while `server_conf.toml` is optional +See commented template config at [server_config.toml](server_config.toml) -### Security - -**NOTE**: **CORS** and **TLS** are not yet fully implemented, and cannot be used. CORS is implemented through [gin middleware](https://github.com/tommy351/gin-cors), and TLS through the standard Go http package via the [graceful library](https://github.com/tylerb/graceful). - -### server_conf.toml (example) - -``` -[bind] -address="0.0.0.0" -port=1337 -[TLS] -tls=false -cert_path="" -key_path="" -[CORS] -enable=false -allow_origins=[] -allow_credentials=false -allow_methods=[] -allow_headers=[] -expose_headers=[] -max_age=0 -[HTTP] -json_rpc_endpoint="/rpc" -[web_socket] -websocket_endpoint="/socketrpc" -max_websocket_sessions=50 -read_buffer_size = 4096 -write_buffer_size = 4096 -[logging] -console_log_level="info" -file_log_level="warn" -log_file="" -``` - -#### Bind - -- `address` is the address. -- `port` is the port number - -#### TLS - -- `tls` is used to enable/disable TLS -- `cert_path` is the absolute path to the certificate file. -- `key_path` is the absolute path to the key file. - -#### CORS - -- `enable` is whether or not the CORS middleware should be added at all. **Not implemented:** see above. - -#### HTTP - -- `json_rpc_endpoint` is the name of the endpoint used for JSON-RPC (2.0) over HTTP. - -#### web_socket - -- `websocket_endpoint` is the name of the endpoint that is used to establish a websocket connection. -- `max_websocket_connections` is the maximum number of websocket connections that is allowed at the same time. -- `read_buffer_size` is the size of the read buffer for each socket in bytes. -- `read_buffer_size` is the size of the write buffer for each socket in bytes. - -#### logging - -- `console_log_level` is the logging level used for the console. -- `file_log_level` is the logging level used for the log file. -- `log_file` is the path to the log file. Leaving this empty means file logging will not be used. - -The possible log levels are these: `crit`, `error`, `warn`, `info`, `debug`. - -The server log level will override the log level set in the Tendermint `config.toml`. ## Contribute @@ -127,4 +51,4 @@ See the [eris platform contributing file here](https://github.com/eris-ltd/codin ## License -[GPL-3](LICENSE) +[GPL-3](license.md) diff --git a/circle.yml b/circle.yml index 6e02174f21c2c243fb7ad974a265090e5f51a1ba..181f21495b9f967be4192216c515cbe10a52d8ff 100644 --- a/circle.yml +++ b/circle.yml @@ -43,9 +43,11 @@ deployment: - tests/build_tool.sh - docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS quay.io - docker push quay.io/eris/erisdb + - docs/build.sh master develop: branch: develop commands: - tests/build_tool.sh - docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS quay.io - docker push quay.io/eris/erisdb + - docs/build.sh diff --git a/cmd/serve.go b/cmd/serve.go index 6d3f82d556b53a9d463c157bc9eb0063c9f4c453..eccf3388ab0c14bc167c8211ce3a9e82208a39f4 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -26,19 +26,31 @@ import ( log "github.com/eris-ltd/eris-logger" + "fmt" + core "github.com/eris-ltd/eris-db/core" util "github.com/eris-ltd/eris-db/util" ) +const ( + DefaultConfigBasename = "config" + DefaultConfigType = "toml" +) + +var DefaultConfigFilename = fmt.Sprintf("%s.%s", + DefaultConfigBasename, + DefaultConfigType) + var ServeCmd = &cobra.Command{ Use: "serve", Short: "Eris-DB serve starts an eris-db node with client API enabled by default.", Long: `Eris-DB serve starts an eris-db node with client API enabled by default. The Eris-DB node is modularly configured for the consensus engine and application manager. The client API can be disabled.`, - Example: `$ eris-db serve -- will start the Eris-DB node based on the configuration file "server_config.toml" in the current working directory -$ eris-db serve --work-dir <path-to-working-directory> -- will start the Eris-DB node based on the configuration file "server_config.toml" in the provided working directory + Example: fmt.Sprintf(`$ eris-db serve -- will start the Eris-DB node based on the configuration file "%s" in the current working directory +$ eris-db serve --work-dir <path-to-working-directory> -- will start the Eris-DB node based on the configuration file "%s" in the provided working directory $ eris-db serve --chain-id <CHAIN_ID> -- will overrule the configuration entry assert_chain_id`, + DefaultConfigFilename, DefaultConfigFilename), PreRun: func(cmd *cobra.Command, args []string) { // if WorkDir was not set by a flag or by $ERIS_DB_WORKDIR // NOTE [ben]: we can consider an `Explicit` flag that eliminates @@ -83,10 +95,11 @@ func addServeFlags() { func Serve(cmd *cobra.Command, args []string) { // load configuration from a single location to avoid a wrong configuration // file is loaded. - if err := do.ReadConfig(do.WorkDir, "config", "toml"); err != nil { + err := do.ReadConfig(do.WorkDir, DefaultConfigBasename, DefaultConfigType) + if err != nil { log.WithFields(log.Fields{ "directory": do.WorkDir, - "file": "config.toml", + "file": DefaultConfigFilename, }).Fatalf("Fatal error reading configuration") os.Exit(1) } diff --git a/CHANGELOG.md b/docs/CHANGELOG.md similarity index 100% rename from CHANGELOG.md rename to docs/CHANGELOG.md diff --git a/docs/build.sh b/docs/build.sh new file mode 100755 index 0000000000000000000000000000000000000000..9433af843543a478bd51ae3337ec70d7f9b90aba --- /dev/null +++ b/docs/build.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash + +# ------------------------------------------------------------------- +# Set vars (change if used in another repo) + +base_name=eris-pm +user_name=eris-ltd +docs_site=monax.io +docs_name=./docs/documentation +slim_name=pm + +# ------------------------------------------------------------------- +# Set vars (usually shouldn't be changed) + +if [ "$CIRCLE_BRANCH" ] +then + repo=`pwd` +else + repo=$GOPATH/src/github.com/$user_name/$base_name +fi +release_min=$(cat $repo/version/version.go | tail -n 1 | cut -d \ -f 4 | tr -d '"') +start=`pwd` + +# ------------------------------------------------------------------- +# Build + +cd $repo +rm -rf $docs_name +go run ./docs/generator.go + +if [[ "$1" == "master" ]] +then + mkdir -p $docs_name/$slim_name/latest + rsync -av $docs_name/$slim_name/$release_min/ $docs_name/$slim_name/latest/ + find $docs_name/latest -type f -name "*.md" -exec sed -i "s/$release_min/latest/g" {} + +fi + +tmp_dir=`mktemp -d 2>/dev/null || mktemp -d -t 'tmp_dir'` +git clone git@github.com:$user_name/$docs_site.git $tmp_dir/$docs_site + +rsync -av $docs_name $tmp_dir/$docs_site/content/docs/ + +# ------------------------------------------------------------------ +# Commit and push if there are changes + +cd $tmp_dir/$docs_site +if [ -z "$(git status --porcelain)" ]; then + echo "All Good!" +else + git add -A :/ && + git commit -m "$base_name build number $CIRCLE_BUILD_NUM doc generation" && + git push origin master +fi + +# ------------------------------------------------------------------ +# Cleanup + +rm -rf $tmp_dir +cd $start \ No newline at end of file diff --git a/docs/generator.go b/docs/generator.go new file mode 100644 index 0000000000000000000000000000000000000000..6f3e88e18405a103f6360e3c1f125de9b589c265 --- /dev/null +++ b/docs/generator.go @@ -0,0 +1,114 @@ +package main + +import ( + "fmt" + "os" + "strings" + "text/template" + + "github.com/eris-ltd/common/go/docs" + commands "github.com/eris-ltd/eris-db/cmd" + + "github.com/eris-ltd/eris-db/version" + "github.com/spf13/cobra" +) + +// Repository maintainers should customize the next two lines. +var Description = "Blockchain Client" // should match the docs site name +var RenderDir = fmt.Sprintf("./docs/documentation/db/%s/", version.VERSION) // should be the "shortversion..." + +// The below variables should be updated only if necessary. +var Specs = []*docs.Entry{} +var Examples = []*docs.Entry{} +var SpecsDir = "./docs/specs" +var ExamplesDir = "./docs/examples" + +type Cmd struct { + Command *cobra.Command + Entry *docs.Entry + Description string +} + +func RenderFiles(cmdRaw *cobra.Command, tmpl *template.Template) error { + this_entry := &docs.Entry{ + Title: cmdRaw.CommandPath(), + Specifications: Specs, + Examples: Examples, + BaseURL: strings.Replace(RenderDir, ".", "", 1), + Template: tmpl, + FileName: docs.GenerateFileName(RenderDir, cmdRaw.CommandPath()), + } + + cmd := &Cmd{ + Command: cmdRaw, + Entry: this_entry, + Description: Description, + } + + for _, command := range cmd.Command.Commands() { + RenderFiles(command, tmpl) + } + + if !cmd.Command.HasParent() { + entries := append(cmd.Entry.Specifications, cmd.Entry.Examples...) + for _, entry := range entries { + entry.Specifications = cmd.Entry.Specifications + entry.Examples = cmd.Entry.Examples + entry.CmdEntryPoint = cmd.Entry.Title + entry.BaseURL = cmd.Entry.BaseURL + if err := docs.RenderEntry(entry); err != nil { + return err + } + } + } + + outFile, err := os.Create(cmd.Entry.FileName) + if err != nil { + return err + } + defer outFile.Close() + + err = cmd.Entry.Template.Execute(outFile, cmd) + if err != nil { + return err + } + + return nil +} + +func main() { + // Repository maintainers should populate the top level command object. + // pm := commands.EPMCmd + // commands.InitEPM() + // commands.AddGlobalFlags() + + // Make the proper directory. + var err error + if _, err = os.Stat(RenderDir); os.IsNotExist(err) { + err = os.MkdirAll(RenderDir, 0755) + if err != nil { + panic(err) + } + } + + // Generate specs and examples files. + Specs, err = docs.GenerateEntries(SpecsDir, (RenderDir + "specifications/"), Description) + if err != nil { + panic(err) + } + Examples, err = docs.GenerateEntries(ExamplesDir, (RenderDir + "examples/"), Description) + if err != nil { + panic(err) + } + + // Get template from docs generator. + tmpl, err := docs.GenerateCommandsTemplate() + if err != nil { + panic(err) + } + + // Render the templates. + if err = RenderFiles(commands.ErisDbCmd, tmpl); err != nil { + panic(err) + } +} diff --git a/api.md b/docs/specs/api.md similarity index 100% rename from api.md rename to docs/specs/api.md diff --git a/glide.lock b/glide.lock index 8014bc99f9a0ae8a20de92413fb8fbcbe023c1ae..04962b493df9f9c4e67b0904de39b88fc0e04fc2 100644 --- a/glide.lock +++ b/glide.lock @@ -222,4 +222,6 @@ imports: version: ecde8c8f16df93a994dda8936c8f60f0c26c28ab - name: gopkg.in/yaml.v2 version: a83829b6f1293c91addabc89d0571c246397bbf4 +- name: github.com/eris-ltd/common + version: 87c464f03bbc41e25a4abb27bf897931fc50be3e devImports: [] diff --git a/glide.yaml b/glide.yaml index 3d3d1d0d7166243a3d7d130aca7e32b3c4a38d04..ca8e52b5c438cf55e2cb5a85ca74617f8d53c485 100644 --- a/glide.yaml +++ b/glide.yaml @@ -16,4 +16,4 @@ import: - package: gopkg.in/fatih/set.v0 - package: gopkg.in/tylerb/graceful.v1 - package: golang.org/x/net/http2 - version: master +- package: github.com/eris-ltd/common