From f361bca0ff5e8ed6ff7d845c067860bfe6a9f45b Mon Sep 17 00:00:00 2001 From: Evan Lin Date: Thu, 11 Jan 2018 14:34:30 +1300 Subject: [PATCH 1/2] improved docker and implemented reconnect to node on error --- Dockerfile | 45 +++++++++++++++++--------------- README.md | 47 +++++++++++++++++++++++++++++----- cmd/bbscli/bbscli.go | 13 +++++++++- src/store/cxo/manager.go | 20 +++++++++++++-- static/dist/ngsw-manifest.json | 2 +- 5 files changed, 96 insertions(+), 31 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8418b296..3c2627ce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,17 +13,23 @@ COPY . /bbs # `unsafe` flag used as work around to prevent infinite loop in Docker # see https://github.com/nodejs/node-gyp/issues/1236 -RUN npm install -g --unsafe @angular/cli && \ - cd /bbs/static && \ - yarn && \ - npm run build +RUN cd /bbs/static && \ + rm -rf package-lock.json && \ + npm install -g --unsafe && \ + npm run build --prod ## Skycoin BBS Image FROM alpine:3.7 +ENV DATA_DIR=/data \ + MESSENGER_ADDR=35.227.102.45:8005 \ + RPC_PORT=8996 \ + CXO_PORT=8998 \ + WEB_PORT=8080 + RUN adduser -D skycoin -RUN mkdir /data -RUN chown skycoin: /data +RUN mkdir $DATA_DIR +RUN chown skycoin: $DATA_DIR USER skycoin @@ -32,19 +38,18 @@ COPY --from=build-go /go/bin/* /usr/bin/ COPY --from=build-node /bbs/static/dist /usr/local/bbs/static # volumes -VOLUME /data +VOLUME $DATA_DIR WORKDIR / -EXPOSE 8080 8998 - -CMD [ \ - "bbsnode", \ - "--public=true", \ - "--memory=false", \ - "--config-dir=/data", \ - "--cxo-port=8998", \ - "--enforced-messenger-addresses=35.227.102.45:8005", \ - "--enforced-subscriptions=03588a2c8085e37ece47aec50e1e856e70f893f7f802cb4f92d52c81c4c3212742", \ - "--web-port=8080", \ - "--web-gui-dir=/usr/local/bbs/static" \ -] \ No newline at end of file +EXPOSE $RPC_PORT $CXO_PORT $WEB_PORT + +CMD bbsnode \ + --public=true \ + --memory=false \ + --config-dir=$DATA_DIR \ + --rpc=true \ + --rpc-port=$RPC_PORT \ + --cxo-port=$CXO_PORT \ + --enforced-messenger-addresses=$MESSENGER_ADDR \ + --web-port=$WEB_PORT \ + --web-gui-dir=/usr/local/bbs/static \ No newline at end of file diff --git a/README.md b/README.md index bf3ad84e..0922c590 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Skycoin BBS uses the [Skycoin CX Object System](https://github.com/skycoin/cxo) [![Skycoin BBS Showcase 4 - YouTube](https://i.ytimg.com/vi/6ZqwgefYauU/0.jpg)](https://youtu.be/6ZqwgefYauU) -## Installation +## Install ### Go 1.9+ Installation and Setup @@ -46,7 +46,7 @@ but it must be cloned to this path: `$GOPATH/src/github.com/skycoin/bbs`. Building instructions for static files can be found in [static/README.md](./static/README.md). -## Running BBS Node +## Run ```bash $ bbsnode @@ -62,14 +62,47 @@ The script [`run.sh`](./run.sh) is provided as a convenient to run BBS, serving $ ./run.sh ``` -## Using Skycoin BBS +## Docker -There are currently two ways of interacting with Skycoin BBS. -* **Web interface thin client -** By default, the flag `-web-gui` is enabled. Hence, when BBS is launched, the web gui will be served at a port specified by `-web-port`. One can only submit and view content via the thin client. +Pull docker image. -* **Restful json api -** This is ideal for viewing/submitting content without a graphical user interface. Documentation for the api is provided as a [Postman](https://www.getpostman.com/) Collection located at [doc/bbs_postman_collection.json](doc/postman_collection.json) which can be viewed online at: [https://documenter.getpostman.com/view/985347/skycoin-bbs-v05/719YYTS](https://documenter.getpostman.com/view/985347/skycoin-bbs-v05/719YYTS). A brief written documentation is provided at [doc/api_explnation.md](./doc/api_explanantion.md). +```bash +$ docker pull skycoin/bbs +``` + +Create a docker volume. + +```bash +$ docker volume create bbs-data +``` + +Run Skycoin BBS. + +```bash +$ docker run -p 8080:8080 -p 8998:8998 -p 8996:8996 -v bbs0:/data skycoin/bbs +``` + +List network interfaces. + +```bash +$ ifconfig +``` + +Use CLI. + +```bash +# help menu +$ docker run skycoin/bbs bbscli -h + +# interact with bbs node +$ docker run skycoin/bbs bbscli -a 172.17.0.1:8996 messengers discover +``` + +## Command-line interface + +The Command-line interface is for administration control over the BBS node. -* **Command-line interface -** This is for administration tools. Detailed instructions are located at [cmd/bbscli/README.md](./cmd/bbscli/README.md). +Detailed instructions are located at [cmd/bbscli/README.md](./cmd/bbscli/README.md). ## Documentation diff --git a/cmd/bbscli/bbscli.go b/cmd/bbscli/bbscli.go index e74a36fe..d424cf1c 100644 --- a/cmd/bbscli/bbscli.go +++ b/cmd/bbscli/bbscli.go @@ -16,10 +16,15 @@ const ( var ( Port = 8996 + Address = "" ) func address() string { - return "[::]:" + strconv.Itoa(Port) + if Address != "" { + return Address + } else { + return "[::]:" + strconv.Itoa(Port) + } } func call(method string, in interface{}) error { @@ -46,6 +51,12 @@ func main() { Value: Port, Destination: &Port, }, + cli.StringFlag{ + Name: "address, a", + Usage: "rpc address of the bbs node, over-rides 'port, p' flag", + Value: Address, + Destination: &Address, + }, } app.Commands = cli.Commands{ { diff --git a/src/store/cxo/manager.go b/src/store/cxo/manager.go index 4ece9328..c439c16d 100644 --- a/src/store/cxo/manager.go +++ b/src/store/cxo/manager.go @@ -23,6 +23,7 @@ import ( "strings" "sync" "time" + "github.com/skycoin/cxo/node/gnet" ) const ( @@ -178,14 +179,29 @@ func (m *Manager) prepareNode() error { for _, pk := range m.node.Feeds() { c.Subscribe(pk) } + m.file.SetConnectionStatus(c.Address(), true) + m.l.Printf("Connected to '%s'", c.Address()) } c.OnCloseConnection = func(c *node.Conn) { m.file.SetConnectionStatus(c.Address(), false) + m.l.Printf("Disconnected from '%s'", c.Address()) + go func() { - time.Sleep(time.Second * 2) - m.node.Connect(c.Address()) + for { + time.Sleep(time.Second * 2) + switch c, e := m.node.Connect(c.Address()); e { + case nil, gnet.ErrAlreadyListen: + return + default: + if c == nil { + m.l.Printf("Reconnecting due to error: '%s'", e.Error()) + } else { + m.l.Printf("Reconnecting to `%s` due to error: '%s'", c.Address(), e.Error()) + } + } + } }() } diff --git a/static/dist/ngsw-manifest.json b/static/dist/ngsw-manifest.json index e29a89d2..53398e5b 100644 --- a/static/dist/ngsw-manifest.json +++ b/static/dist/ngsw-manifest.json @@ -14,8 +14,8 @@ "/scripts.2ada44d001a2fa97ca64.bundle.js": "5101a13dcce062b23a11302fa35a1f696a16e3c4", "/styles.2d4560bcefdd3da68b61.bundle.css": "be6010d0d73dff3dc1b8372d5b423d8a3bc6343c", "/favicon.ico": "63f338aec4bb5adb37a6fb1b311c65835912c22f", - "/assets/dust.png": "d0cd217d6531d84d578cd3a078957748359684fc", "/assets/logo.svg": "c84d898508bcca59b2113a54eb3ec4229acae416", + "/assets/dust.png": "d0cd217d6531d84d578cd3a078957748359684fc", "/assets/nodes.svg": "15c1bf6a8e8668683fa85bd75057bfaecffd1939", "/index.html": "1312c017c1c98b525e394010cdefa42e3720ff71" }, From 318789d1beaaa99dee1d0a4f6e238554816fb710 Mon Sep 17 00:00:00 2001 From: Evan Lin Date: Thu, 11 Jan 2018 14:44:37 +1300 Subject: [PATCH 2/2] bumped version to 5.2 --- cmd/bbscli/bbscli.go | 2 +- cmd/bbsnode/bbsnode.go | 2 +- pkg/build.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/bbscli/bbscli.go b/cmd/bbscli/bbscli.go index d424cf1c..4a222add 100644 --- a/cmd/bbscli/bbscli.go +++ b/cmd/bbscli/bbscli.go @@ -11,7 +11,7 @@ import ( ) const ( - Version = "5.1" + Version = "5.2" ) var ( diff --git a/cmd/bbsnode/bbsnode.go b/cmd/bbsnode/bbsnode.go index d5d03ea6..c037fe29 100644 --- a/cmd/bbsnode/bbsnode.go +++ b/cmd/bbsnode/bbsnode.go @@ -20,7 +20,7 @@ import ( ) const ( - Version = "5.1" + Version = "5.2" defaultConfigSubDir = ".skybbs" defaultStaticSubDir = "static/dist" diff --git a/pkg/build.sh b/pkg/build.sh index 86b9d829..d87a2c0e 100755 --- a/pkg/build.sh +++ b/pkg/build.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -VERSION=5.1 +VERSION=5.2 GOARCH=amd64 NAME=skycoin_bbs