Skip to content

Commit

Permalink
Merge pull request #232 from ayuryshev/feature/Automate-testing-of-ch…
Browse files Browse the repository at this point in the history
…at-application-218

Feature/automate testing of chat application 218
  • Loading branch information
志宇 authored Mar 20, 2019
2 parents aa9a29c + 5c2ace9 commit 7ba6eeb
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ pkg/node/foo/
/skywire-cli
/therealssh-cli
/node
PK
28 changes: 13 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ DOCKER_OPTS?=GO111MODULE=on GOOS=linux # go options for compiling for docker con
build: dep host-apps bin

clean:
rm -rf ./apps
rm -f ./skywire-node ./skywire-cli ./manager-node ./thereallssh-cli
-rm -rf ./apps
-rm -f ./skywire-node ./skywire-cli ./manager-node ./thereallssh-cli

install:
${OPTS} go install ./cmd/skywire-node ./cmd/skywire-cli ./cmd/manager-node ./cmd/therealssh-cli
Expand Down Expand Up @@ -55,8 +55,7 @@ bin:
${OPTS} go build -o ./manager-node ./cmd/manager-node
${OPTS} go build -o ./therealssh-cli ./cmd/therealssh-cli

# Node

# Dockerized skywire-node
docker-image:
docker image build --tag=skywire-runner --rm - < skywire-runner.Dockerfile

Expand All @@ -78,21 +77,20 @@ docker-apps:
docker-bin:
${DOCKER_OPTS} go build -o ./node/skywire-node ./cmd/skywire-node


docker-volume: docker-apps docker-bin bin
./skywire-cli config ./node/skywire.json
cat ./node/skywire.json|grep static_public_key |cut -d ':' -f2 |tr -d '"'','' ' > ./node/PK
cat ./node/PK

node: docker-clean docker-image docker-network docker-volume
docker run -d -v $(shell pwd)/node:/sky --network=${DOCKER_NETWORK} --name=${DOCKER_NODE} ${DOCKER_IMAGE} bash -c "cd /sky && ./skywire-node"
docker-run: docker-clean docker-image docker-network docker-volume
docker run -it -v $(shell pwd)/node:/sky --network=${DOCKER_NETWORK} \
--name=${DOCKER_NODE} ${DOCKER_IMAGE} bash -c "cd /sky && ./skywire-node"

run:
docker-stop:
-docker container stop ${DOCKER_NODE}

# skywire-node on host
run: stop build
./skywire-node

node-stop:
-docker container stop ${DOCKER_NODE}
stop:
-bash -c "kill $$(ps aux |grep '[s]kywire-node' |awk '{print $$2}')"

refresh-node: node-stop docker-bin
# cp ./skywire-node ./node
docker container start ${DOCKER_NODE}
48 changes: 37 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ $ git checkout mainnet
$ make # installs all dependencies, build binaries and apps
```

#### Note: Environment variable OPTS
**Note: Environment variable OPTS**

Build can be customized with environment variable `OPTS` with default value `GO111MODULE=on`

Expand All @@ -54,13 +54,13 @@ $ make
$ OPTS="GSO111MODULE=on GOOS=linux GOARCH=arm" make
```

# Install skywire-node, skywire-cli, manager-node and therealssh-cli
**Install skywire-node, skywire-cli, manager-node and therealssh-cli**

```bash
$ make install # compiles and installs all binaries
```

# Generate default json config
**Generate default json config**

```bash
skywire-cli config
Expand All @@ -78,7 +78,7 @@ $ skywire-node skywire.json
### Run `skywire-node` in docker container

```bash
make node
make docker-run
```

### Run `skywire-cli`
Expand Down Expand Up @@ -181,7 +181,7 @@ There are two make goals for running in development environment dockerized `skyw
### Run dockerized `skywire-node`

```bash
$ make node
$ make docker-run
```

This will:
Expand Down Expand Up @@ -249,7 +249,7 @@ Other images can be used.
E.g.

```bash
DOCKER_IMAGE=golang make node #buildpack-deps:stretch-scm is OK too
DOCKER_IMAGE=golang make docker-run #buildpack-deps:stretch-scm is OK too
```

#### 2.DOCKER_NETWORK
Expand All @@ -272,14 +272,11 @@ Default value: "GO111MODULE=on GOOS=linux"

### Dockerized `skywire-node` recipes

#### 1. Get Public Key of node
#### 1. Get Public Key of docker-node

```bash
$ cat ./node/skywire.json|grep static_public_key |cut -d ':' -f2 |tr -d '"'','' '
# 029be6fa68c13e9222553035cc1636d98fb36a888aa569d9ce8aa58caa2c651b45
# or just:
$ cat ./node/PK # this file is created during `make docker-volume`
# 029be6fa68c13e9222553035cc1636d98fb36a888aa569d9ce8aa58caa2c651b45
```

#### 2. Get an IP of node
Expand All @@ -295,7 +292,7 @@ $ docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' S
$ firefox http://$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' SKY01):8000
```

#### 4. Create new dockerize `skywire-nodes`
#### 4. Create new dockerized `skywire-nodes`

In case you need more dockerized nodes or maybe it's needed to customize node
let's look how to create new node.
Expand Down Expand Up @@ -351,3 +348,32 @@ Instead of skywire-runner you can use:

- `golang`, `buildpack-deps:stretch-scm` "as is"
- and `debian`, `ubuntu` - after `apt-get install ca-certificates` in them. Look in `skywire-runner.Dockerfile` for example

#### 5. Env-vars for develoment-/testing- purposes

```bash
export SW_NODE_A=127.0.0.1
export SW_NODE_A_PK=$(cat ./skywire.json|grep static_public_key |cut -d ':' -f2 |tr -d '"'','' ')
export SW_NODE_B=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' SKY01)
export SW_NODE_B_PK=$(cat ./node/skywire.json|grep static_public_key |cut -d ':' -f2 |tr -d '"'','' ')
```

#### 6. "Hello-Mike-Hello-Joe" test

Idea of test from Erlang classics: https://youtu.be/uKfKtXYLG78?t=120

```bash
# Setup: run skywire-nodes on host and in docker
$ make run
$ make docker-run
# Open in browser chat application
$ firefox http://$SW_NODE_B:8000 &
# add transport
$ ./skywire-cli add-transport $SW_NODE_B_PK
# "Hello Mike!" - "Hello Joe!" - "System is working!"
$ curl --data {'"recipient":"'$SW_NODE_A_PK'", "message":"Hello Mike!"}' -X POST http://$SW_NODE_B:8000/message
$ curl --data {'"recipient":"'$SW_NODE_B_PK'", "message":"Hello Joe!"}' -X POST http://$SW_NODE_A:8000/message
$ curl --data {'"recipient":"'$SW_NODE_A_PK'", "message":"System is working!"}' -X POST http://$SW_NODE_B:8000/message
# Teardown
$ make stop && make docker-stop
```

0 comments on commit 7ba6eeb

Please sign in to comment.