Skip to content

Commit ed2ce3d

Browse files
Clean up scripts for local development (#146)
* get start_dev.sh script working * launch_chrome.sh: only create certificate if it doesn't already exist * add instructions for running locally without docker * update readme --------- Co-authored-by: Dario Lencina <[email protected]>
1 parent 67b36f1 commit ed2ce3d

File tree

3 files changed

+77
-53
lines changed

3 files changed

+77
-53
lines changed

README.md

+27-15
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ https://www.youtube.com/watch?v=kZ9isFw1TQ8
1818

1919
MVP of a teleconferencing system written in rust, both the backend and the UI.
2020

21-
# How to test?
21+
# How to try it out?
2222

2323
## Setup
24-
Technically you could test this with a single computer, but it is more fun if you use 2+.
24+
Technically you could run this with a single computer, but it is more fun if you use 2+.
2525

2626
## Steps
2727

@@ -41,18 +41,6 @@ Technically you could test this with a single computer, but it is more fun if yo
4141

4242
![Oct-24-2022 08-37-09](https://user-images.githubusercontent.com/1176339/197853024-171e0dcc-2098-4780-b3be-bfc3cb5adb43.gif)
4343

44-
# Compiling Cargo Workspace
45-
46-
## Ubuntu
47-
48-
Some system dependencies are required for the workspace to compile
49-
50-
```sh
51-
sudo apt-get update
52-
sudo apt-get install libglib2.0-dev libgtk-3-dev libsoup2.4 libjavascriptcoregtk-4.0-dev libwebkit2gtk-4.0-dev
53-
```
54-
55-
5644
## ▶️ YouTube Channel
5745
https://www.youtube.com/@securityunion
5846

@@ -71,7 +59,31 @@ Contains 3 sub-projects
7159
2. yew-ui: Yew frontend
7260
3. types: json serializable structures used to communicate the frontend and backend.
7361

74-
# Dockerized workflow
62+
# Local Development
63+
64+
## Without docker
65+
66+
### Prerequisites
67+
68+
1. Create a postgresql database that you can accessed without a password. The default database name is `actix-api-db`, i.e. the default connection string is `postgresql://$USER@localhost/actix-api-db`
69+
70+
2. Install [trurl](see https://github.com/curl/trurl) and [nats-server]((see https://docs.nats.io/running-a-nats-service/introduction/installation)
71+
72+
### Starting up the servers
73+
74+
1. Run the script `./start_dev.sh`.
75+
76+
It examines various environment variables to control the behavior; see the script itself for details.
77+
By default it runs using websockets rather than webtransport (`WEBTRANSPORT_ENABLED=0`) and without encryption (`E2EE_ENABLED=0`).
78+
79+
2. Connect your browser to `http://localhost:8081/meeting/<username>/<meeting-id>`
80+
81+
You can make multiple connections (with varying usernames) from multiple browser windows or tabs.
82+
83+
If you are using encryption (`E2EE_ENABLED=1`), you should lanuch Chrome with
84+
the necessary options for it to accept the local certificate by running `./launch_chrome.sh`
85+
86+
## Dockerized workflow
7587

7688
1. Install docker
7789
2. Run one of the supported make commands

launch_chrome.sh

+11-13
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,22 @@
33
set -e
44

55
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
6+
CERTSPATH="$SCRIPTPATH/actix-api/certs"
67

7-
# generate certificate
8+
if ! [ -f "$CERTSPATH/localhost.der" ] ; then
9+
echo "Generating certificate in $CERTSPATH"
10+
openssl req -x509 -newkey rsa:2048 -keyout "$CERTSPATH/localhost.key" -out "$CERTSPATH/localhost.pem" -days 365 -nodes -subj "/CN=127.0.0.1"
11+
openssl x509 -in "$CERTSPATH/localhost.pem" -outform der -out "$CERTSPATH/localhost.der"
12+
openssl rsa -in "$CERTSPATH/localhost.key" -outform DER -out "$CERTSPATH/localhost_key.der"
13+
fi
814

9-
openssl req -x509 -newkey rsa:2048 -keyout $SCRIPTPATH/actix-api/certs/localhost.key -out $SCRIPTPATH/actix-api/certs/localhost.pem -days 365 -nodes -subj "/CN=127.0.0.1"
10-
11-
openssl x509 -in $SCRIPTPATH/actix-api/certs/localhost.pem -outform der -out $SCRIPTPATH/actix-api/certs/localhost.der
12-
13-
openssl rsa -in $SCRIPTPATH/actix-api/certs/localhost.key -outform DER -out $SCRIPTPATH/actix-api/certs/localhost_key.der
14-
15-
SPKI=`openssl x509 -inform der -in $SCRIPTPATH/actix-api/certs/localhost.der -pubkey -noout | openssl pkey -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64`
16-
17-
echo "Got cert key $SPKI"
15+
SPKI=$(openssl x509 -inform der -in "$CERTSPATH/localhost.der" -pubkey -noout | openssl pkey -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64)
1816

1917
echo "Opening google chrome"
2018

21-
case `uname` in
22-
(*Linux*) google-chrome --origin-to-force-quic-on=127.0.0.1:4433 --ignore-certificate-errors-spki-list=$SPKI --enable-logging --v=1 ;;
23-
(*Darwin*) open -a "Google Chrome" --args --origin-to-force-quic-on=127.0.0.1:4433 --ignore-certificate-errors-spki-list=$SPKI --enable-logging --v=1 ;;
19+
case $(uname) in
20+
(*Linux*) google-chrome --origin-to-force-quic-on=127.0.0.1:4433 --ignore-certificate-errors-spki-list="$SPKI" --enable-logging --v=1 ;;
21+
(*Darwin*) open -a "Google Chrome" --args --origin-to-force-quic-on=127.0.0.1:4433 --ignore-certificate-errors-spki-list="$SPKI" --enable-logging --v=1 ;;
2422
esac
2523

2624
## Logs are stored to ~/Library/Application Support/Google/Chrome/chrome_debug.log

start_dev.sh

+39-25
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,54 @@
22

33
# WARNING!! use this script while running without docker.
44

5-
65
export TRUNK_SERVE_PORT=8081
76
export ACTIX_PORT=8086
7+
export LOGIN_URL=${LOGIN_URL:-http://localhost:${ACTIX_PORT:-8080}/login}
8+
export ACTIX_UI_BACKEND_URL=${ACTIX_UI_BACKEND_URL:-ws://localhost:${ACTIX_PORT:-8080}}
9+
export WEBTRANSPORT_HOST=${WEBTRANSPORT_HOST:-https://127.0.0.1:4433}
10+
export ENABLE_OAUTH=${ENABLE_OAUTH:-0}
11+
export WEBTRANSPORT_ENABLED=${WEBTRANSPORT_ENABLED:-0}
12+
export E2EE_ENABLED=${E2EE_ENABLED:-0}
13+
export NATS_URL=${NATS_URL:-0.0.0.0:4222}
14+
export HEALTH_LISTEN_URL=${HEALTH_LISTEN_URL:-0.0.0.0:5321}
15+
export LISTEN_URL=${LISTEN_URL:-0.0.0.0:4433}
16+
export DATABASE_URL=${DATABASE_URL:-postgresql://$USER@localhost/actix-api-db}
17+
18+
server_command="$( ((WEBTRANSPORT_ENABLED)) && echo webtransport_server || echo websocket_server )"
19+
20+
_kill() {
21+
kill -- -$$
22+
# the command spawned by cargo watch doesn't get killed with the process group, so kill it explicitly
23+
pkill -f "$server_command"
24+
}
825

9-
children=()
26+
trap _kill SIGINT SIGTERM SIGQUIT
1027

11-
_term() {
12-
echo "Caught SIGTERM"
13-
for child in "${children[@]}"; do
14-
kill -TERM "$child" 2>/dev/null
15-
done
16-
}
28+
if ! [ -x "$(command -v trurl)" ] ; then
29+
echo "please install trurl (see https://github.com/curl/trurl)"
30+
exit
31+
fi
1732

18-
_int() {
19-
echo "Caught SIGINT"
20-
for child in "${children[@]}"; do
21-
kill -TERM "$child" 2>/dev/null
22-
done
23-
}
33+
if ! [ -x "$(command -v nats-server)" ] ; then
34+
echo "please install nats-server (see https://docs.nats.io/running-a-nats-service/introduction/installation)"
35+
exit
36+
fi
37+
38+
if ! psql "$DATABASE_URL" -c 'SELECT 1' >/dev/null; then
39+
echo "please make sure postgresql is running with database defined for: $DATABASE_URL"
40+
exit
41+
fi
2442

25-
trap _term SIGTERM
26-
trap _int SIGINT
43+
nats-server --addr "$(trurl -g '{host}' "$NATS_URL")" --port "$(trurl -g '{port}' "$NATS_URL")" &
2744

28-
pushd actix-api;
29-
cargo watch -x "run" &
45+
pushd actix-api > /dev/null || exit
46+
cargo watch -x "run --bin $server_command" &
3047
ACTIX_PROC=$!
31-
children+=($ACTIX_PROC)
32-
popd;
48+
popd > /dev/null || exit
3349

34-
pushd yew-ui;
50+
pushd yew-ui > /dev/null || exit
3551
trunk serve &
36-
YEW_PROCESS=$!
37-
children+=($YEW_PROCESS)
38-
popd;
52+
popd > /dev/null || exit
3953

4054
wait $ACTIX_PROC
41-
echo "Done running actix and yew, bye"
55+
echo "Done running actix and yew, bye"

0 commit comments

Comments
 (0)