Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gokmen committed Oct 31, 2017
0 parents commit 1b5bff6
Show file tree
Hide file tree
Showing 27 changed files with 6,310 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"presets": [
["env", {
"targets": {
"node": "current"
}
}
],
],
"plugins": ["transform-decorators-legacy"]
}
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nodes
.git
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_STORE
node_modules
dist
lib
11 changes: 11 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*.log
/.*/
/coverage/
/docs/
/nodes/
/examples/
/test/
/.gitignore
/.npmignore
/.travis.yml
/src
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
language: node_js

script:
- npm run test

node_js:
- stable
- 6
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM mhart/alpine-node:base-8

WORKDIR .
ADD . .

EXPOSE 3210

CMD ["npm", "start"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Rope

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
126 changes: 126 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
![](https://raw.githubusercontent.com/ropelive/press/master/banners/rope-server-js.png)

[![Build Status](https://travis-ci.org/ropelive/server.svg?branch=master)](https://travis-ci.org/ropelive/server)
[![NPM version](https://img.shields.io/npm/v/@rope/server.svg?style=flat-square)](https://www.npmjs.com/package/@rope/server)

Rope is a public Kite registry with proxy support between kites. Also
introduces bi-directional communication between Kites.

Getting Started
---------------

Before starting make sure to call `npm install` and
`go get github.com/koding/kite` if you want to try go example.
Then to start Rope server;

```
$ npm start
```

This will start the server on `0.0.0.0:3210` which then you can run one of
the node examples (in another terminal session);

```
$ node nodes/js/rope-node.js
```

will create a Rope Node with Node.js, same file also supports browsers which
you can try it out with;

```
$ open nodes/js/index.html
```

will load the `kite.js` bundle and then runs the `rope-node.js` which will
create another Rope Node in the browser this time.

To try another Rope Node in Go this time;

```
$ go run nodes/go/rope-node.go
```

Once ready, you can start playing with nodes by calling `run` over
`Rope Server`. The best way to do that for now opening Dev Console in your
choice of Browser after loading the `nodes/js/index.html`. Which will connect
to `Rope Server`, identifies itself and will get a list of Kites registered
before which you can access from `publicKites` global variable. There will be
another public variable called `kite` which will allow you to interact with
`Rope Server`. And for an example of usage of `run` over `Rope Server` would
be (in Dev Console of nodes/js/index.html);

## `kite.ping`

```
> kite.tell('run', {
kiteId: publicKites[0].id,
method: "kite.ping"
}).then(console.log.bind(console))
pong
```
will ping the first public kite which will end with a simple `pong`


## `kite.systemInfo`

```
> kite.tell('run', {
kiteId: publicKites[0].id,
method: "kite.systemInfo"
}).then(console.log.bind(console))
{
diskTotal: 975902848,
diskUsage: 328007624,
homeDir: "/Users/rope",
memoryUsage: 12602589184,
state: "RUNNING",
totalMemoryLimit: 17179869184,
uname: "darwin",
}
```
will return the system info from first public kite.


## `kite.prompt`

```
> kite.tell('run', {
kiteId: publicKites[0].id,
method: "kite.prompt",
args: ["Your Name? "]
}).then(console.log.bind(console))
# on the terminal of first public kite you will see the prompt "Your Name? "
$ go run nodes/go/rope-node.go
2017-07-06 01:24:30 [dope] INFO New listening: 0.0.0.0:49558
2017-07-06 01:24:30 [dope] INFO Serving...
2017-07-06 01:24:30 [dope] INFO Identify requested!
2017-07-06 01:24:30 [dope] INFO Identified as
8542b5e3-fc67-4c6b-a368-968c12d69357 now!
Your Name? Gokmen
# once provided it will return the result to the browser console.
Gokmen
```

## `square`

```
> kite.tell('run', {
kiteId: publicKites[0].id,
method: "square",
args: [5]
}).then(console.log.bind(console))
25
```
you can check it out the implementations under `nodes/{go, js}`

# License

MIT (c) 2017 Rope
65 changes: 65 additions & 0 deletions koding.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# This will create two servers on provided AWS account
# One for the rope server itself which will be running on `secure`.{cfdomain}
# Other for webserver which runs on `{cfdomain}`

provider:
aws:
access_key: '${var.aws_access_key}'
secret_key: '${var.aws_secret_key}'
cloudflare:
email: '${var.custom_cfemail}'
token: '${var.custom_cftoken}'

resource:
aws_instance:
rope-server:
instance_type: 't2.nano'
tags:
Name: 'rope-server'
user_data: |-
# Install docker first:
curl --silent --location https://get.docker.com/ | sh
# Then run rope on 80
docker run --restart=always -d -p80:8080 --name rope gokmen/rope
rope-webserver:
instance_type: 't2.nano'
tags:
Name: 'rope-webserver'
user_data: |-
# Install docker first:
curl --silent --location https://get.docker.com/ | sh
# Run sample nodes in Node.js and Go
docker run --restart=always -d --name rope-node-go gokmen/rope-node-go
docker run --restart=always -d --name rope-node-js gokmen/rope-node-js
# Run rope-home to serve rope homepage
docker run --restart=always -p80:80 -d --name rope-home gokmen/rope-home
aws_eip:
rope-server:
instance: "${aws_instance.rope-server.id}"
rope-webserver:
instance: "${aws_instance.rope-webserver.id}"

cloudflare_record:
ropeweb:
domain: "${var.custom_cfdomain}"
name: "${var.custom_cfdomain}"
value: "${aws_eip.rope-webserver.public_ip}"
type: "A"
ttl: 3600
ropewww:
domain: "${var.custom_cfdomain}"
name: "www"
value: "${aws_eip.rope-webserver.public_ip}"
type: "A"
ttl: 3600
rope:
domain: "${var.custom_cfdomain}"
name: "secure"
value: "${aws_eip.rope-server.public_ip}"
type: "A"
ttl: 3600
8 changes: 8 additions & 0 deletions nodes/go/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM scratch
FROM centurylink/ca-certs

ADD rope-node /

# needs to be exposed over a tunnel
# ENV ROPEHOST http://0.0.0.0:3210
CMD ["/rope-node"]
12 changes: 12 additions & 0 deletions nodes/go/Dockerfile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM golang:latest

RUN mkdir -p /go/src/rope-node
ADD . /go/src/rope-node/
WORKDIR /go/src/rope-node

RUN go get
RUN go build

# needs to be exposed over a tunnel
# ENV ROPEHOST http://0.0.0.0:3210
ENTRYPOINT ["/go/bin/rope-node"]
25 changes: 25 additions & 0 deletions nodes/go/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
![](https://raw.githubusercontent.com/ropelive/press/master/banners/rope-node-go.png)

Rope-Node in Go
---------------

To static build rope-node again after changes;

$ CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o rope-node

Then rebuild the container;

$ docker build -t rope-go .

If you need to build it in a docker container you can use Dockerfile.build;

$ docker build -f Dockerfile.build -t rope-go .

And for running it;

$ docker run -it --rm rope-go

If you need to use a custom rope host;

$ docker run -e ROPEHOST=http://0.0.0.0:3210 -it --rm rope-go

63 changes: 63 additions & 0 deletions nodes/go/rope-node.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package main

import (
"github.com/koding/kite"
"os"
"runtime"
)

func main() {
r := kite.New("rope-node-go", "0.0.0")
r.Config.Environment = runtime.Version()

kiteURL := os.Getenv("ROPEHOST")
if kiteURL == "" {
kiteURL = "http://0.0.0.0:3210"
}
l := r.NewClient(kiteURL)
l.Reconnect = true

api := map[string]kite.HandlerFunc{
"square": func(req *kite.Request) (interface{}, error) {
number := req.Args.One().MustFloat64()
result := number * number
return result, nil
},
}

for method, f := range api {
r.HandleFunc(method, f)
}

r.HandleFunc("rope.identified", func(req *kite.Request) (interface{}, error) {
var args struct {
Id string `json:"id"`
}
req.Args.One().MustUnmarshal(&args)
r.Log.Info("Identified as %v now!", args.Id)
return nil, nil
})

r.HandleFunc("rope.identify", func(req *kite.Request) (interface{}, error) {
r.Log.Info("Identify requested!")
funcs := make([]string, 0, len(api))
for method := range api {
funcs = append(funcs, method)
}
return map[string]interface{}{
"kiteInfo": r.Kite(),
"api": funcs,
"signatures": map[string]interface{}{
"square": "Number, Function",
},
}, nil
})

connection, err := l.DialForever()
if err != nil {
r.Log.Fatal(err.Error())
}
<-connection

r.Run()
}
8 changes: 8 additions & 0 deletions nodes/js/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM mhart/alpine-node:base-8

WORKDIR .
ADD . .

# needs to be exposed over a tunnel
# ENV ROPEHOST http://0.0.0.0:3210
CMD ["node", "rope-node.js"]
8 changes: 8 additions & 0 deletions nodes/js/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
![](https://raw.githubusercontent.com/ropelive/press/master/banners/rope-node-js.png)

Rope-Node in JS
---------------

This implementation is hybrid for Node.js and modern browsers, you can try the `rope-node.js` file with `node.js` or you can open `index.html` with your choice of browser.

This only shows the implementation details of rope nodes, for up-to-date implementation of a rope node please take a look https://github.com/ropelive/node repository instead.
Loading

0 comments on commit 1b5bff6

Please sign in to comment.