Skip to content

Commit

Permalink
Refactor dockefiles and add jupyter notebook (#3)
Browse files Browse the repository at this point in the history
* 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!)
  • Loading branch information
balazskreith authored Jul 7, 2022
1 parent 064445f commit db9a04e
Showing 14 changed files with 365 additions and 265 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ In terminal, run:
```

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


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

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

## Using Multiple SFUs

Examples of monitoring cascaded SFU environment requires to run multiple, at least two SFUs.

```bash
SFU_ANNOUNCED_IP={MY_LOCAL_IP_ADDRESS} docker-compose -f docker-compose-cascaded-sfus.yaml up
```

In your browser tabs you go to http://localhost:9000/?sfuPort=5959, and http://localhost:9000/?sfuPort=7171.



## Dev mode

if you want to modify the [mediasoup-sfu](mediasoup-sfu/) or the [webrtc-app](my-webrtc-app/) locally,
10 changes: 10 additions & 0 deletions docker-compose-cascaded-sfus.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
services:
notebooks:
restart: always
build:
context: ./my-notebooks
dockerfile: Dockerfile
ports:
- 8888:8888
volumes:
- ./my-notebooks:/home/jovyan/work

observer:
restart: always
image: observertc/observer:1.0.0-beta
12 changes: 12 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
services:
notebooks:
restart: always
build:
context: ./my-notebooks
dockerfile: Dockerfile
ports:
- 8888:8888
volumes:
- ./my-notebooks:/home/jovyan/work

observer:
restart: always
image: observertc/observer:1.0.0-beta
@@ -34,6 +44,7 @@ services:
- mongodb

mediasoup_sfu:
restart: always
build:
context: ./mediasoup-sfu
dockerfile: Dockerfile
@@ -54,6 +65,7 @@ services:
- OBSERVER_INTERNAL_ADDRESS=host.docker.internal:7080
depends_on:
- observer

webrtc-app:
build:
context: ./my-webrtc-app
49 changes: 7 additions & 42 deletions mediasoup-sfu/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,58 +1,23 @@
FROM ubuntu:20.04
# FROM sitespeedio/node:ubuntu-20.04-nodejs-16.13.2
FROM node:latest

USER root

ENV TZ=Europe/Helsinki

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update && apt-get -y --no-install-recommends install \
sudo \
vim \
wget \
build-essential \
pkg-config \
gdb

RUN echo "deb http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse" >> /etc/apt/sources.list && \
echo "deb-src http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse" >> /etc/apt/sources.list && \
echo "deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse" >> /etc/apt/sources.list && \
echo "deb-src http://archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse" >> /etc/apt/sources.list && \
echo "deb http://archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse" >> /etc/apt/sources.list && \
echo "deb-src http://archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse" >> /etc/apt/sources.list && \
echo "deb http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse" >> /etc/apt/sources.list && \
echo "deb-src http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse" >> /etc/apt/sources.list && \
echo "deb http://archive.canonical.com/ubuntu focal partner" >> /etc/apt/sources.list && \
echo "deb-src http://archive.canonical.com/ubuntu focal partner" >> /etc/apt/sources.list


RUN apt-get install -y curl && \
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - && \
sudo dpkg --configure -a && \
printf 'y\n1\n\1n' | apt upgrade


RUN apt-get install -y aptitude && \
aptitude install -y nodejs && \
aptitude install -y npm && \
apt install -y python3-pip

WORKDIR /app

COPY [ \
"package.json", \
"tsconfig.json", \
"src/*", \
"*.js", \
"./" \
]
COPY package.json ./

COPY ./ ./

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

# for throttling traffic
RUN apt-get install -y net-tools iproute2
# RUN apt-get install -y net-tools iproute2

# ENV DEBUG="mediasoup*"
CMD [ "node", "dist/main.js" ]
10 changes: 5 additions & 5 deletions mediasoup-sfu/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sfu",
"version": "1.0.0",
"description": "Simple Mediasoup SFU for transcribing",
"description": "Simple Mediasoup SFU",
"main": "main.js",
"scripts": {
"dev": "ts-node-dev --respawn --pretty --transpile-only src/main.ts",
@@ -26,15 +26,15 @@
"@observertc/sfu-monitor-js": "^1.0.0-beta.34",
"@types/ws": "^8.2.2",
"events": "^3.3.0",
"log4js": "^6.4.6",
"mediasoup": "^3.9.12",
"log4js": "^6.5.2",
"mediasoup": "^3.10.0",
"uuid": "^8.3.2",
"ws": "^8.6.0",
"ws": "^8.8.0",
"yargs-parser": "^21.0.0"
},
"devDependencies": {
"@types/uuid": "^8.3.3",
"ts-node-dev": "^1.1.8",
"typescript": "^4.6.4"
"typescript": "^4.7.4"
}
}
2 changes: 1 addition & 1 deletion mediasoup-sfu/src/main.ts
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ async function main(): Promise<void> {
if (outboundLatencyInMs) {
await new Promise<void>((resolve, reject) => {
const command = `tc qdisc add dev eth0 root handle 1 netem delay ${outboundLatencyInMs}ms`;
logger.debug(`Executing ${command}`);
logger.info(`Executing ${command}`);
exec(command, (error: any, stdout: any, stderr: any) => {
if (error) reject(error);
else if (stderr) reject(stderr)
20 changes: 20 additions & 0 deletions my-notebooks/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM jupyter/base-notebook

USER root

# Add requirements file
ADD requirements.txt /app/

# Installs, clean, and update
RUN apt-get update \
&& apt-get clean \
&& apt-get update -qqq \
&& apt-get install -y -q g++ \
&& pip install --upgrade pip \
&& pip install -r /app/requirements.txt

ENV JUPYTER_ENABLE_LAB=yes

CMD jupyter notebook --port=8888 --no-browser --ip=0.0.0.0 --allow-root --NotebookApp.token='' --NotebookApp.password=''

EXPOSE 8888
79 changes: 24 additions & 55 deletions my-notebooks/basic-questions.ipynb
Original file line number Diff line number Diff line change
@@ -5,12 +5,14 @@
"id": "69fbed7d",
"metadata": {},
"source": [
"# Calls"
"# Calls\n",
"\n",
"List the calls"
]
},
{
"cell_type": "code",
"execution_count": 39,
"execution_count": 5,
"id": "5a51b9ce",
"metadata": {},
"outputs": [
@@ -19,59 +21,22 @@
"output_type": "stream",
"text": [
"\n",
"Room: Santo Domingo\n",
"Room: Pyongyang\n",
"--------\n",
"\n",
"Call ae2b890e-4c67-4947-9448-9b074ee947a7\n",
"\n",
"\tUserId: Peeves \n",
"\tClientId: 64aeee1c-b6b6-43d4-a076-80cc1377d174\n",
"\tJoined: 1654800562698\n",
"\tLeft: 1654801764402\n",
"\tDuration: 20 min\n",
"\n",
"\tUserId: Bellatrix Lestrange \n",
"\tClientId: e6c57372-08c8-4853-9cb3-912daadd3e20\n",
"\tJoined: 1654801711505\n",
"\tLeft: 1654801784404\n",
"\tDuration: 1 min\n",
"\n",
"Call 3f7c39a9-1ae5-4d9f-a6e5-5f467d367ce3\n",
"\n",
"\tUserId: Hedwig \n",
"\tClientId: bf7b9ea1-d2c5-4762-93d8-33a3a9729bcd\n",
"\tJoined: 1654803322051\n",
"\tLeft: 1654803966491\n",
"\tDuration: 10 min\n",
"Call 9236312f-2697-41e4-82d4-3ff43fd404e8\n",
"\n",
"\tUserId: Dumbledore \n",
"\tClientId: 89c82d9d-d9a9-4d82-bcb7-82fe9eec4811\n",
"\tJoined: 1654803326351\n",
"\tLeft: 1654803966491\n",
"\tDuration: 10 min\n",
"\n",
"\tUserId: Bellatrix Lestrange \n",
"\tClientId: dff1e8a7-9633-49ca-9e9b-19f6e52a9931\n",
"\tJoined: 1654803329499\n",
"\tLeft: 1654803966491\n",
"\tDuration: 10 min\n",
"\tClientId: 8b2a6420-b596-4005-aabf-e849a992502d\n",
"\tJoined: 1657197987140\n",
"\tLeft: 1657197999786\n",
"\tDuration: 0 min\n",
"\n",
"Room: Washington, D.C.\n",
"--------\n",
"\n",
"Call 84f0aacc-b135-42ad-932f-b7b010a5754c\n",
"\n",
"\tUserId: Seamus Finnigan \n",
"\tClientId: d0b47c12-969f-4681-836a-143f4fd27d66\n",
"\tJoined: 1654803655203\n",
"\tLeft: 1654803966491\n",
"\tDuration: 5 min\n",
"\n",
"\tUserId: Hedwig \n",
"\tClientId: a7ed9d5d-d6e4-49dc-8637-ba836fc04165\n",
"\tJoined: 1654803662356\n",
"\tLeft: 1654803966491\n",
"\tDuration: 5 min\n"
"\tUserId: Fleur Delacour \n",
"\tClientId: 806b77ce-a81c-4e05-9b50-956ec618d442\n",
"\tJoined: 1657197994033\n",
"\tLeft: 1657197999786\n",
"\tDuration: 0 min\n"
]
}
],
@@ -80,7 +45,11 @@
"\n",
"import time\n",
"\n",
"MONGO_HOST=\"localhost\"\n",
"# If jupyter runs on localhost:\n",
"# MONGO_HOST=\"localhost\"\n",
"\n",
"# If jupyter runs in docker\n",
"MONGO_HOST=\"host.docker.internal\"\n",
"MONGO_USER=\"root\"\n",
"MONGO_PASSWORD=\"password\"\n",
"MONGO_PORT=27017\n",
@@ -152,15 +121,15 @@
},
{
"cell_type": "code",
"execution_count": 40,
"execution_count": 6,
"id": "40f84b55",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"number of concurrent sfu streams 34\n"
"number of concurrent sfu streams 8\n"
]
}
],
@@ -475,7 +444,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@@ -489,7 +458,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.10"
"version": "3.10.5"
}
},
"nbformat": 4,
Loading

0 comments on commit db9a04e

Please sign in to comment.