Skip to content

Commit

Permalink
Rework configuration tutorial with docker
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya Bogdanov committed Feb 26, 2018
1 parent a3a1e39 commit fa7a3f8
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 238 deletions.
176 changes: 72 additions & 104 deletions services/configuration/doc/testnet-api-tutorial.md
@@ -1,9 +1,35 @@
# Configuration service tutorial

## Build instructions
## Running testnet

### Using Docker

<!-- spell-checker:ignore vitvakatu -->

Simply run the following command to configure and launch testnet with 4 nodes:

```bash
docker run -p 8000-8007:8000-8007 vitvakatu/exonum-configuration-example 4
```

Docker will automatically pull image from the repository and run 4 nodes with
public endpoints at `127.0.0.1:8000`, ..., `127.0.0.1:8003` and
private ones at `127.0.0.1:8004`, ..., `127.0.0.1:8007`.

To build an [example binary](examples/configuration.rs) of exonum blockchain
with the single configuration service mounted, run:
You can also use helper [script](../docker/example-start.sh):

```bash
./docker/example-start.sh <number of nodes>
```

To stop docker container, use `docker stop <container id>` command.

### Manually

#### Build example binary

To build an [example binary](../examples/configuration.rs) of exonum
blockchain with the single configuration service mounted, run:

```bash
cargo install --example configuration
Expand All @@ -12,106 +38,48 @@ cargo install --example configuration
`exonum` crate system dependencies and rust toolchain configuration -
[exonum install instructions](https://github.com/exonum/exonum/blob/master/INSTALL.md).

## Running testnet
#### Generate testnet directory and config

`4` is a required indexed parameter and stands for the number of nodes in
testnet:

```bash
mkdir -p testnet/configuration_service
cd testnet/configuration_service
configuration generate-testnet --start 5400 4 --output_dir .
cd ..
```

This should create the following config for testnet:

```bash
$ tree configuration_service/
configuration_service/
└── validators
├── 0.toml
├── 1.toml
├── 2.toml
└── 3.toml
```

#### Run `4` nodes

<!-- markdownlint-disable MD013 -->

```bash
configuration run --node-config configuration_service/validators/0.toml --db-path configuration_service/db/0 --public-api-address 127.0.0.1:8000 --private-api-address 127.0.0.1:8010
...
configuration run --node-config configuration_service/validators/3.toml --db-path configuration_service/db/3 --public-api-address 127.0.0.1:8003 --private-api-address 127.0.0.1:8013
```

<!-- markdownlint-enable MD013 -->

##### Parameters

- Generate testnet dir and testnet config.

- `4` is a required indexed parameter and stands for the number of nodes in
testnet:

```bash
mkdir -p testnet/configuration_service
cd testnet/configuration_service
configuration generate-testnet --start 5400 4 --output_dir .
cd ..
```

- This should create following config for testnet:

```bash
$ tree configuration_service/
configuration_service/
└── validators
├── 0.toml
├── 1.toml
├── 2.toml
└── 3.toml
```

- Run `4` nodes:

- manually for the each node's process:

<!-- markdownlint-disable MD013 -->
```bash
configuration run --node-config configuration_service/validators/0.toml --db-path configuration_service/db/0 --public-api-address 127.0.0.1:8000 --private-api-address 127.0.0.1:8010
...
configuration run --node-config configuration_service/validators/3.toml --db-path configuration_service/db/3 --public-api-address 127.0.0.1:8003 --private-api-address 127.0.0.1:8013
```
<!-- markdownlint-enable MD013 -->

- parameters
- `--public-api-address` is for Exonum [public http api endpoints](#public-endpoints)
- `--private-api-address` is for Exonum [private http api endpoints](#private-endpoints)
- `--node-config` path to the node config
- `--db-path` path to the database

- automatically via the [supervisord](http://supervisord.org/) utility.

1. set the `TESTNET_DESTDIR` environment variable to the `testnet` dir
created above:

```bash
$ pwd
/Users/user/Exonum/testnet
$ export TESTNET_DESTDIR=/Users/user/Exonum/testnet
```

1. run [helper script](../testnet/testnetctl.sh) for initializing
`supervisor` and `configuration_service` process group
[config](../testnet/supervisord) to `$TESTNET_DESTDIR` directory.

```bash
./testnet/testnetctl.sh enable
```

1. go to `$TESTNET_DESTDIR`. It contains new `etc`, `run`, `log` folders.

```bash
$ cd $TESTNET_DESTDIR
$ tree .
.
├── configuration_service
│ └── validators
│ ├── 0.toml
│ ├── 1.toml
│ ├── 2.toml
│ └── 3.toml
├── etc
│ ├── conf.d
│ │ └── configuration_service.conf
│ └── supervisord.conf
├── log
│ ├── supervisor
│ │ ├── configuration_service_00-stderr---supervisor-rMqmIy.log
│ │ ... ...
│ │ └── configuration_service_03-stdout---supervisor-s29Fd_.log
│ └── supervisord.log
└── run
└── supervisord.pid

7 directories, 16 files
```

1. launch `configuration_service` process group.

```bash
$ supervisorctl start configuration_service:*
configuration_service:configuration_service_01: started
configuration_service:configuration_service_00: started
configuration_service:configuration_service_03: started
configuration_service:configuration_service_02: started
```
- `--public-api-address` is for Exonum [public http api endpoints](#public-endpoints)
- `--private-api-address` is for Exonum [private http api endpoints](#private-endpoints)
- `--node-config` path to the node config
- `--db-path` path to the database

## Global variable service http api

Expand Down Expand Up @@ -204,7 +172,7 @@ endpoint.

1. no vote from the same node public key has been submitted previously.

[Examples](response-samples.md#private-response-samples)
[Examples](response-samples.md#private-endpoints-response-samples)

<!-- markdownlint-disable MD013 MD033 -->
| Endpoint | HTTP method | Description | Response template |
Expand All @@ -213,4 +181,4 @@ endpoint.
| `/api/services/configuration/v1/configs/<config-hash-vote-for>/postvote` | POST | Vote for a configuration having specific hash | {<br> &emsp;"tx\_hash": **transaction-hash**<br> } |
<!-- markdownlint-enable MD013 MD033 -->

[exonum config]: http://exonum.com/doc/crates/exonum/blockchain/config/struct.StoredConfiguration.html
[exonum config]: https://docs.rs/exonum/0.5.1/exonum/blockchain/config/struct.StoredConfiguration.html
12 changes: 12 additions & 0 deletions services/configuration/docker/Dockerfile
@@ -0,0 +1,12 @@
FROM rust:1.23.0

WORKDIR /usr/src
RUN git clone https://github.com/exonum/exonum \
&& cd exonum/services/configuration \
&& cargo install --example configuration \
&& cd /usr/src \
&& rm -rf exonum
WORKDIR /exonum/configuration
COPY launch.sh .

ENTRYPOINT ["./launch.sh"]
10 changes: 10 additions & 0 deletions services/configuration/docker/example-start.sh
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

# Usage:
# example-start.sh <number of nodes>

node_count=$1
port_start=8000
port_end=$((port_start + (2 * node_count) - 1))

docker run -p ${port_start}-${port_end}:${port_start}-${port_end} vitvakatu/exonum-configuration-example:latest $node_count
20 changes: 20 additions & 0 deletions services/configuration/docker/launch.sh
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

node_count=$1

configuration generate-testnet --start 5400 $node_count --output_dir .

for i in $(seq 0 $((node_count - 1)))
do
port=$((8000 + i))
private_port=$((port + node_count))
configuration run --node-config validators/$i.toml --db-path db/$i --public-api-address 0.0.0.0:${port} --private-api-address 0.0.0.0:${private_port} &
echo "new node with ports: $port (public) and $private_port (private)"
done

echo "$node_count nodes configured and launched"

while :
do
sleep 300
done

This file was deleted.

20 changes: 0 additions & 20 deletions services/configuration/testnet/supervisord/etc/supervisord.conf

This file was deleted.

105 changes: 0 additions & 105 deletions services/configuration/testnet/testnetctl.sh

This file was deleted.

0 comments on commit fa7a3f8

Please sign in to comment.