Skip to content

Commit

Permalink
Merge pull request #203 from dedis/albert
Browse files Browse the repository at this point in the history
Script to run the whole system in 1 command
  • Loading branch information
pierluca authored Nov 23, 2022
2 parents 563b903 + 217fa60 commit 9891200
Show file tree
Hide file tree
Showing 6 changed files with 458 additions and 393 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/go_scenario_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,8 @@ jobs:
- name: Install memcoin
run: make build

- name: Start 3 nodes
run: |
./memcoin --config /tmp/node1 start --postinstall --promaddr :9100 --proxyaddr :9080 --proxykey adbacd10fdb9822c71025d6d00092b8a4abb5ebcb673d28d863f7c7c5adaddf3 --listen tcp://0.0.0.0:2001 --public //localhost:2001 --routing tree &
./memcoin --config /tmp/node2 start --postinstall --promaddr :9101 --proxyaddr :9081 --proxykey adbacd10fdb9822c71025d6d00092b8a4abb5ebcb673d28d863f7c7c5adaddf3 --listen tcp://0.0.0.0:2002 --public //localhost:2002 --routing tree &
./memcoin --config /tmp/node3 start --postinstall --promaddr :9102 --proxyaddr :9082 --proxykey adbacd10fdb9822c71025d6d00092b8a4abb5ebcb673d28d863f7c7c5adaddf3 --listen tcp://0.0.0.0:2003 --public //localhost:2003 --routing tree &
- name: Run the setup
run: ./setupnNode.sh -n 3 -d false
- name: Start and setup 3 nodes
run: ./runSystems.sh -n 3 --docker false --backend false --frontend false --attach false

- name: Run the scenario Test
run: go test -timeout 7m -run TestScenario ./integration/...
137 changes: 80 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,27 @@ results.
<a href="https://www.epfl.ch/labs/dedis/wp-content/uploads/2022/07/report-2022-1-capucine-badr-d-voting-frontend.pdf">Report</a>,
<a href="https://www.epfl.ch/labs/dedis/wp-content/uploads/2022/07/presentation-2022-1-capucine-badr-d-voting-frontend.pdf">Presentation</a>
</td>
</tr>
<tr>
<td>Fall 2022</td>
<td>Students: Amine Benaziz, Albert Troussard<br>Supervisor: Noémien Kocher, Pierluca Borso<br>Assistant: Emilien Duc</td></td>
<td></td>
<td>
</td>
</tr>
<tr>
<td>Fall 2022</td>
<td>Students: Ahmed Elalamy, Ghita Tagemouati, Khadija Tagemouati<br>Supervisor: Noémien Kocher</td></td>
<td></td>
<td>
</td>
</tr>
<tr>
<td>Fall 2022</td>
<td>Students: Chen Chang Lew<br>Supervisor: Noémien Kocher, Pierluca Borso</td></td>
<td></td>
<td>
</td>
</tr>
</table>

Expand All @@ -375,85 +396,70 @@ added to you path (like with `export PATH=$PATH:/Users/david/go/bin`).

3: [Install tmux](https://github.com/tmux/tmux/wiki/Installing)

# Setup a simple system with 3 nodes

If you are using Windows and cannot use tmux, you need to do the actions of the
scripts in point _1_ and _2_ manually: open 3 terminal sessions and run the
commands from the section _Run the nodes_ below (1 command LLVL=info memcoin etc.
per terminal and then launch the setup script in another terminal). You can then
follow the instructions below starting from point _3_.
# Setup a simple system with 5 nodes (Linux and MacOS)

1: Run 3 nodes
If you are using Windows and cannot use tmux, you need to follow the instructions in [this](#Setup-a-simple-system-with-5-nodes-(Windows))
section.

1: Only for the first time
```sh
./runNode.sh -n 3
cd web/backend
npm install
cp config.env.template config.env
cd ../frontend
npm install
cd ../..
```

This will run 4 terminal sessions. You can navigate by hitting
<kbd>CTRL</kbd>+<kbd>B</kbd> and then <kbd>S</kbd>. Use the arrows to select a
window.
2: Then run the following script to start and setup the nodes and the web server:

2: Launch the setup

From the first terminal sessions, run:

```sh
./setupnNode.sh -n 3
./runSystems.sh -n 5
```

3: Launch the web backend
This will run 8 terminal sessions. You can navigate by hitting
<kbd>CTRL</kbd>+<kbd>B</kbd> and then <kbd>S</kbd>. Use the arrows to select a
window.

From a new terminal session, run:

```sh
cd web/backend
# if this is the first time, run `npm install` and `cp config.env.template config.env` first
npm start
```
3: Stop nodes
If you want to stop the system, you can use the following command:

4: Launch the web frontend
(If you forgot, this will be done automatically when you start a new system)

From a new terminal session, run:

```sh
cd web/frontend
# if this is the first time, run `npm install` first
REACT_APP_PROXY=http://localhost:9081 REACT_APP_NOMOCK=on npm start
```

Note that you need to be on EPFL's network to login with Tequila. Additionally,
once logged with Tequila, update the redirect URL and replace
`dvoting-dev.dedis.ch` with `localhost`. Once logged, you can create an
form.

5: Stop nodes

```sh
./kill_test.sh
```

6: Troubleshoot
4: Troubleshoot

If while running

```sh
npm start
./runSystems.sh -n 5
```

in the web backend folder, you get this error:
You get this error:

```sh
Error: listen EADDRINUSE: address already in use :::5000
```

then run this instead:
then in the file runSystems.sh, replace the line:

```sh
PORT=4000 npm start
tmux send-keys -t $s:{end} "cd web/backend && npm start" C-m
```
with
```sh
tmux send-keys -t $s:{end} "cd web/backend && PORT=4000 npm start" C-m
#or any other available port
```

and in the web/frontend/src/setupProxy.js file, change :
And in the web/frontend/src/setupProxy.js file, change :

```sh
target: 'http://localhost:5000',
Expand All @@ -465,7 +471,7 @@ with
target: 'http://localhost:4000',
```

# Run the nodes
# Setup a simple system with 3 nodes (Windows)

In three different terminal sessions, from the root folder:

Expand Down Expand Up @@ -502,24 +508,36 @@ remove the old state:
rm -rf /tmp/node{1,2,3}
```

# Testing
3: Launch the web backend

From a new terminal session, run:

```sh
cd web/backend
# if this is the first time, run `npm install` and `cp config.env.template config.env` first
npm start
```

## Automate the previous setup using `tmux`
4: Launch the web frontend

If you have `tmux` installed, you can start a `tmux` session that will
execute the above setup by running in the project root `./runNode.sh -n 3`.
This command takes as argument the number of nodes.
Once the session is started, you can move around the panes with
`Ctrl+B` followed by arrow keys or by `N`. You can also have an overview of the
windows with `Ctrl+B` followed by `S`.
From a new terminal session, run:

To end the session, run `./kill_test.sh`,
which will kill each window then the `tmux` session (which you can do manually
with `Ctrl+D`), then delete the node data (i.e. the files `/tmp/node{1,2,3}`).
```sh
cd web/frontend
# if this is the first time, run `npm install` first
REACT_APP_PROXY=http://localhost:9081 REACT_APP_NOMOCK=on npm start
```

Note that you need to be on EPFL's network to login with Tequila. Additionally,
once logged with Tequila, update the redirect URL and replace
`dvoting-dev.dedis.ch` with `localhost`. Once logged, you can create an
form.

# Testing

## Run the scenario test

If nodes are running and `setup.sh` or `./setupnNode.sh -n 3` has been called,
If nodes are running and `setup.sh` or `./runSystem.sh -n 3 --backend false --frontend false` (for this test you don't want the user interface so the web components are not needed) has been called,
you can run a test scenario:

```sh
Expand All @@ -540,7 +558,10 @@ Public key: `adbacd10fdb9822c71025d6d00092b8a4abb5ebcb673d28d863f7c7c5adaddf3`

Secret key: `28912721dfd507e198b31602fb67824856eb5a674c021d49fdccbe52f0234409`

## Run the scenario test with docker
<!---
Currently not working
## Run the scenario test with docker
Use the following commands to launch and set up nodes, and start the scenario
test with user defined number of nodes.
Expand Down Expand Up @@ -571,6 +592,8 @@ N.B. run following commands to get help
./autotest.sh -h
```
-->

# Use the frontend

See README in `web/`.
Expand Down
50 changes: 50 additions & 0 deletions kill_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,55 @@

# This script kills the tmux session started in start_test.sh and
# removes all the data pertaining to the test.
FRONTEND=true
BACKEND=true

while [[ $# -gt 0 ]]; do
case $1 in
-h | --help)
echo "This script is creating n dela voting nodes"
echo "Options:"
echo "-h | --help program help (this file)"
echo "-f | --frontend kill the frontend true/false, by default true"
echo "-b | --backend kill the backend true/false, by default true"
exit 0
;;
-f | --frontend)
FRONTEND="$2"
shift # past argument
shift # past value
;;
-b | --backend)
BACKEND="$2"
shift # past argument
shift # past value
;;
-* | --*)
echo "Unknown option $1"
exit 1
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
shift # past argument
;;
esac
done

set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters

set -o errexit

command -v tmux >/dev/null 2>&1 || {
echo >&2 "tmux is not on your PATH!"
exit 1
}

if [ "$FRONTEND" = true ]; then
tmux send-keys -t $s:{end} C-c
tmux kill-window -t $s:{end}
fi
if [ "$BACKEND" = true ]; then
tmux send-keys -t $s:{end} C-c
fi

rm -rf /tmp/node* && tmux kill-session -t d-voting-test
Loading

0 comments on commit 9891200

Please sign in to comment.