Skip to content

Commit db9a04e

Browse files
authored
Refactor dockefiles and add jupyter notebook (#3)
* change base images of mediasoup_sfu and webrtc_app * fix tslint errors in webrtc_app * add jupyter notebook docker container to the stack * add some data checks at the end of the cells in notebooks (thanks Chad for the suggestion!)
1 parent 064445f commit db9a04e

File tree

14 files changed

+365
-265
lines changed

14 files changed

+365
-265
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ In terminal, run:
1212
```
1313

1414
**MY_LOCAL_IP_ADDRESS** is the IP address of your local network interface connect to the internet.
15-
You can obtain it by typing `ifconfig` in macOs or Linux, or `ipconfig` in Windows.
15+
You can obtain it by typing `ifconfig` in MacOs or Linux, or `ipconfig` in Windows.
1616

1717

1818
When containers are running, in your browser go to http://localhost:9000 (open it in two, or three tabs).
@@ -21,6 +21,18 @@ To see the collected [reports](https://observertc.org/docs/overview/schemas/#rep
2121

2222
To see some SFU metrics calculated by the sfu-montior go to http://localhost:5959/metrics
2323

24+
## Using Multiple SFUs
25+
26+
Examples of monitoring cascaded SFU environment requires to run multiple, at least two SFUs.
27+
28+
```bash
29+
SFU_ANNOUNCED_IP={MY_LOCAL_IP_ADDRESS} docker-compose -f docker-compose-cascaded-sfus.yaml up
30+
```
31+
32+
In your browser tabs you go to http://localhost:9000/?sfuPort=5959, and http://localhost:9000/?sfuPort=7171.
33+
34+
35+
2436
## Dev mode
2537

2638
if you want to modify the [mediasoup-sfu](mediasoup-sfu/) or the [webrtc-app](my-webrtc-app/) locally,

docker-compose-cascaded-sfus.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
services:
2+
notebooks:
3+
restart: always
4+
build:
5+
context: ./my-notebooks
6+
dockerfile: Dockerfile
7+
ports:
8+
- 8888:8888
9+
volumes:
10+
- ./my-notebooks:/home/jovyan/work
11+
212
observer:
313
restart: always
414
image: observertc/observer:1.0.0-beta

docker-compose.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
services:
2+
notebooks:
3+
restart: always
4+
build:
5+
context: ./my-notebooks
6+
dockerfile: Dockerfile
7+
ports:
8+
- 8888:8888
9+
volumes:
10+
- ./my-notebooks:/home/jovyan/work
11+
212
observer:
313
restart: always
414
image: observertc/observer:1.0.0-beta
@@ -34,6 +44,7 @@ services:
3444
- mongodb
3545

3646
mediasoup_sfu:
47+
restart: always
3748
build:
3849
context: ./mediasoup-sfu
3950
dockerfile: Dockerfile
@@ -54,6 +65,7 @@ services:
5465
- OBSERVER_INTERNAL_ADDRESS=host.docker.internal:7080
5566
depends_on:
5667
- observer
68+
5769
webrtc-app:
5870
build:
5971
context: ./my-webrtc-app

mediasoup-sfu/Dockerfile

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,23 @@
1-
FROM ubuntu:20.04
2-
# FROM sitespeedio/node:ubuntu-20.04-nodejs-16.13.2
1+
FROM node:latest
32

43
USER root
54

65
ENV TZ=Europe/Helsinki
76

8-
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
9-
RUN apt-get update && apt-get -y --no-install-recommends install \
10-
sudo \
11-
vim \
12-
wget \
13-
build-essential \
14-
pkg-config \
15-
gdb
16-
17-
RUN echo "deb http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse" >> /etc/apt/sources.list && \
18-
echo "deb-src http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse" >> /etc/apt/sources.list && \
19-
echo "deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse" >> /etc/apt/sources.list && \
20-
echo "deb-src http://archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse" >> /etc/apt/sources.list && \
21-
echo "deb http://archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse" >> /etc/apt/sources.list && \
22-
echo "deb-src http://archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse" >> /etc/apt/sources.list && \
23-
echo "deb http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse" >> /etc/apt/sources.list && \
24-
echo "deb-src http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse" >> /etc/apt/sources.list && \
25-
echo "deb http://archive.canonical.com/ubuntu focal partner" >> /etc/apt/sources.list && \
26-
echo "deb-src http://archive.canonical.com/ubuntu focal partner" >> /etc/apt/sources.list
27-
28-
29-
RUN apt-get install -y curl && \
30-
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - && \
31-
sudo dpkg --configure -a && \
32-
printf 'y\n1\n\1n' | apt upgrade
33-
34-
35-
RUN apt-get install -y aptitude && \
36-
aptitude install -y nodejs && \
37-
aptitude install -y npm && \
38-
apt install -y python3-pip
39-
407
WORKDIR /app
418

42-
COPY [ \
43-
"package.json", \
44-
"tsconfig.json", \
45-
"src/*", \
46-
"*.js", \
47-
"./" \
48-
]
9+
COPY package.json ./
10+
11+
COPY ./ ./
4912

13+
# RUN apk add --no-cache git make bash python3 py3-pip net-tools gcc alpine-sdk iproute2 linux-headers
14+
RUN apt-get update && apt-get install -y build-essential python3 python3-pip iproute2 net-tools make
5015
RUN npm install
5116
RUN npm install typescript -g
5217
RUN tsc
5318

5419
# for throttling traffic
55-
RUN apt-get install -y net-tools iproute2
20+
# RUN apt-get install -y net-tools iproute2
5621

5722
# ENV DEBUG="mediasoup*"
5823
CMD [ "node", "dist/main.js" ]

mediasoup-sfu/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "sfu",
33
"version": "1.0.0",
4-
"description": "Simple Mediasoup SFU for transcribing",
4+
"description": "Simple Mediasoup SFU",
55
"main": "main.js",
66
"scripts": {
77
"dev": "ts-node-dev --respawn --pretty --transpile-only src/main.ts",
@@ -26,15 +26,15 @@
2626
"@observertc/sfu-monitor-js": "^1.0.0-beta.34",
2727
"@types/ws": "^8.2.2",
2828
"events": "^3.3.0",
29-
"log4js": "^6.4.6",
30-
"mediasoup": "^3.9.12",
29+
"log4js": "^6.5.2",
30+
"mediasoup": "^3.10.0",
3131
"uuid": "^8.3.2",
32-
"ws": "^8.6.0",
32+
"ws": "^8.8.0",
3333
"yargs-parser": "^21.0.0"
3434
},
3535
"devDependencies": {
3636
"@types/uuid": "^8.3.3",
3737
"ts-node-dev": "^1.1.8",
38-
"typescript": "^4.6.4"
38+
"typescript": "^4.7.4"
3939
}
4040
}

mediasoup-sfu/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ async function main(): Promise<void> {
7777
if (outboundLatencyInMs) {
7878
await new Promise<void>((resolve, reject) => {
7979
const command = `tc qdisc add dev eth0 root handle 1 netem delay ${outboundLatencyInMs}ms`;
80-
logger.debug(`Executing ${command}`);
80+
logger.info(`Executing ${command}`);
8181
exec(command, (error: any, stdout: any, stderr: any) => {
8282
if (error) reject(error);
8383
else if (stderr) reject(stderr)

my-notebooks/Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM jupyter/base-notebook
2+
3+
USER root
4+
5+
# Add requirements file
6+
ADD requirements.txt /app/
7+
8+
# Installs, clean, and update
9+
RUN apt-get update \
10+
&& apt-get clean \
11+
&& apt-get update -qqq \
12+
&& apt-get install -y -q g++ \
13+
&& pip install --upgrade pip \
14+
&& pip install -r /app/requirements.txt
15+
16+
ENV JUPYTER_ENABLE_LAB=yes
17+
18+
CMD jupyter notebook --port=8888 --no-browser --ip=0.0.0.0 --allow-root --NotebookApp.token='' --NotebookApp.password=''
19+
20+
EXPOSE 8888

my-notebooks/basic-questions.ipynb

Lines changed: 24 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
"id": "69fbed7d",
66
"metadata": {},
77
"source": [
8-
"# Calls"
8+
"# Calls\n",
9+
"\n",
10+
"List the calls"
911
]
1012
},
1113
{
1214
"cell_type": "code",
13-
"execution_count": 39,
15+
"execution_count": 5,
1416
"id": "5a51b9ce",
1517
"metadata": {},
1618
"outputs": [
@@ -19,59 +21,22 @@
1921
"output_type": "stream",
2022
"text": [
2123
"\n",
22-
"Room: Santo Domingo\n",
24+
"Room: Pyongyang\n",
2325
"--------\n",
2426
"\n",
25-
"Call ae2b890e-4c67-4947-9448-9b074ee947a7\n",
26-
"\n",
27-
"\tUserId: Peeves \n",
28-
"\tClientId: 64aeee1c-b6b6-43d4-a076-80cc1377d174\n",
29-
"\tJoined: 1654800562698\n",
30-
"\tLeft: 1654801764402\n",
31-
"\tDuration: 20 min\n",
32-
"\n",
33-
"\tUserId: Bellatrix Lestrange \n",
34-
"\tClientId: e6c57372-08c8-4853-9cb3-912daadd3e20\n",
35-
"\tJoined: 1654801711505\n",
36-
"\tLeft: 1654801784404\n",
37-
"\tDuration: 1 min\n",
38-
"\n",
39-
"Call 3f7c39a9-1ae5-4d9f-a6e5-5f467d367ce3\n",
40-
"\n",
41-
"\tUserId: Hedwig \n",
42-
"\tClientId: bf7b9ea1-d2c5-4762-93d8-33a3a9729bcd\n",
43-
"\tJoined: 1654803322051\n",
44-
"\tLeft: 1654803966491\n",
45-
"\tDuration: 10 min\n",
27+
"Call 9236312f-2697-41e4-82d4-3ff43fd404e8\n",
4628
"\n",
4729
"\tUserId: Dumbledore \n",
48-
"\tClientId: 89c82d9d-d9a9-4d82-bcb7-82fe9eec4811\n",
49-
"\tJoined: 1654803326351\n",
50-
"\tLeft: 1654803966491\n",
51-
"\tDuration: 10 min\n",
52-
"\n",
53-
"\tUserId: Bellatrix Lestrange \n",
54-
"\tClientId: dff1e8a7-9633-49ca-9e9b-19f6e52a9931\n",
55-
"\tJoined: 1654803329499\n",
56-
"\tLeft: 1654803966491\n",
57-
"\tDuration: 10 min\n",
30+
"\tClientId: 8b2a6420-b596-4005-aabf-e849a992502d\n",
31+
"\tJoined: 1657197987140\n",
32+
"\tLeft: 1657197999786\n",
33+
"\tDuration: 0 min\n",
5834
"\n",
59-
"Room: Washington, D.C.\n",
60-
"--------\n",
61-
"\n",
62-
"Call 84f0aacc-b135-42ad-932f-b7b010a5754c\n",
63-
"\n",
64-
"\tUserId: Seamus Finnigan \n",
65-
"\tClientId: d0b47c12-969f-4681-836a-143f4fd27d66\n",
66-
"\tJoined: 1654803655203\n",
67-
"\tLeft: 1654803966491\n",
68-
"\tDuration: 5 min\n",
69-
"\n",
70-
"\tUserId: Hedwig \n",
71-
"\tClientId: a7ed9d5d-d6e4-49dc-8637-ba836fc04165\n",
72-
"\tJoined: 1654803662356\n",
73-
"\tLeft: 1654803966491\n",
74-
"\tDuration: 5 min\n"
35+
"\tUserId: Fleur Delacour \n",
36+
"\tClientId: 806b77ce-a81c-4e05-9b50-956ec618d442\n",
37+
"\tJoined: 1657197994033\n",
38+
"\tLeft: 1657197999786\n",
39+
"\tDuration: 0 min\n"
7540
]
7641
}
7742
],
@@ -80,7 +45,11 @@
8045
"\n",
8146
"import time\n",
8247
"\n",
83-
"MONGO_HOST=\"localhost\"\n",
48+
"# If jupyter runs on localhost:\n",
49+
"# MONGO_HOST=\"localhost\"\n",
50+
"\n",
51+
"# If jupyter runs in docker\n",
52+
"MONGO_HOST=\"host.docker.internal\"\n",
8453
"MONGO_USER=\"root\"\n",
8554
"MONGO_PASSWORD=\"password\"\n",
8655
"MONGO_PORT=27017\n",
@@ -152,15 +121,15 @@
152121
},
153122
{
154123
"cell_type": "code",
155-
"execution_count": 40,
124+
"execution_count": 6,
156125
"id": "40f84b55",
157126
"metadata": {},
158127
"outputs": [
159128
{
160129
"name": "stdout",
161130
"output_type": "stream",
162131
"text": [
163-
"number of concurrent sfu streams 34\n"
132+
"number of concurrent sfu streams 8\n"
164133
]
165134
}
166135
],
@@ -475,7 +444,7 @@
475444
],
476445
"metadata": {
477446
"kernelspec": {
478-
"display_name": "Python 3",
447+
"display_name": "Python 3 (ipykernel)",
479448
"language": "python",
480449
"name": "python3"
481450
},
@@ -489,7 +458,7 @@
489458
"name": "python",
490459
"nbconvert_exporter": "python",
491460
"pygments_lexer": "ipython3",
492-
"version": "3.9.10"
461+
"version": "3.10.5"
493462
}
494463
},
495464
"nbformat": 4,

0 commit comments

Comments
 (0)