Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

Commit 2c5afdb

Browse files
authored
Make installing an app into the owt-server Docker image much easier. (#441)
1 parent 7d0e30f commit 2c5afdb

File tree

11 files changed

+128
-38
lines changed

11 files changed

+128
-38
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The media server can be built on following platforms:
2727
### Instructions
2828
In the root of the repository:
2929
1. Build native components: `scripts/build.js -t all --check`.
30-
2. Pack built components and js files: `scripts/pack.js -t all --install-module --sample-path ${webrtc-javascript-sdk-sample-conference-dist}`.
30+
2. Pack built components and js files: `scripts/pack.js -t all --install-module --app-path ${webrtc-javascript-sdk-sample-conference-dist}`.
3131

3232
The ${webrtc-javascript-sdk-sample-conference-dist} is built from owt-javascript-sdk, e.g. `~/owt-client-javascript/dist/sample/conference`, see https://github.com/open-webrtc-toolkit/owt-client-javascript for details.
3333

@@ -42,6 +42,13 @@ In the repository root, run following commands to start media server on single m
4242
## Where to find API documents
4343
See "doc/servermd/Server.md" and "doc/servermd/RESTAPI.md".
4444

45+
## Build a Docker image with your app
46+
Run the build_server.sh script located in docker/conference. It has one required flag, -p, which should contain the filepath of your app. Optional flags are -i for the final Docker image name, and -n
47+
which will make the Docker build run with --no-cache. An example usecase..
48+
```
49+
./docker/conference/build_server.sh -p ~/my_app -i myapp_img
50+
```
51+
4552
## How to contribute
4653
We warmly welcome community contributions to Open WebRTC Toolkit Media Server repository. If you are willing to contribute your features and ideas to OWT, follow the process below:
4754
- Make sure your patch will not break anything, including all the build and tests

doc/servermd/Server.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ After editing the configuration file, you should run `./initcert.js` inside each
180180
| DTLS-SRTP | webrtc_agent/agent.toml |
181181
| management-console HTTPS | management_console/management_console.toml |
182182

183-
For OWT sample application's certificate configuration, please follow the instruction file 'README.md' located at Release-<Version>/extras/basic_example/.
183+
For OWT sample application's certificate configuration, please follow the instruction file 'README.md' located at Release-<Version>/apps/current_app/.
184184

185185
### 2.3.8 Launch the OWT server as single node {#Conferencesection2_3_8}
186186
To launch the OWT server on one machine, follow steps below:
@@ -277,7 +277,7 @@ Follow the steps below to set up a OWT server cluster:
277277

278278
cd Release-<Version>/
279279
bin/daemon.sh start app
280-
> **Note**: You can also deploy the sample application server on separated machine, follow instructions at Release-<Version>/extras/basic_example/README.md
280+
> **Note**: You can also deploy the sample application server on separated machine, follow instructions at Release-<Version>/apps/current_app/README.md
281281
282282
7. Choose machines to run cluster-managers. These machines do not need to be visible to clients, but should be visible to management-api and all workers.
283283
8. Edit the configurations of cluster-manager in Release-<Version>/cluster_manager/cluster_manager.toml.
@@ -738,7 +738,7 @@ Only super service user can access runtime configuration. Current management con
738738
## 4.1 Introduction {#Conferencesection4_1}
739739
The OWT sample application server is a Web application demo that shows how to host audio/video conference services powered by the Open WebRTC Toolkit. The sample application server is based on OWT runtime components. Refer to [Section 2](#Conferencesection2) of this guide, for system requirements and launch/stop instructions.
740740

741-
The source code of the sample application is in Release-<Version>/extras/basic_example/.
741+
The source code of the sample application is in Release-<Version>/apps/current_app/.
742742

743743
This section explains how to start a conference and then connect to a conference using different qualifiers, such as a specific video resolution.
744744

docker/Dockerfile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ FROM ubuntu:18.04
77

88
ENV DEBIAN_FRONTEND=noninteractive
99
ENV MEDIA_SDK_VER=18.4.0
10+
ARG IMG_APP_PATH=/app_data/
11+
ENV APP_PATH=${IMG_APP_PATH}
1012

1113
# Update the system
1214
RUN apt-get update
@@ -18,21 +20,21 @@ RUN npm install -g grunt-cli node-gyp
1820

1921
# Keep proxy environment for sudo
2022
RUN bash -c "echo \"Defaults env_keep = \\\"http_proxy https_proxy no_proxy \\\"\" >> /etc/sudoers"
21-
22-
# Install owt-client
23-
RUN git clone https://github.com/open-webrtc-toolkit/owt-client-javascript.git
24-
RUN cd owt-client-javascript/scripts && npm install && grunt
25-
2623
RUN wget https://github.com/Intel-Media-SDK/MediaSDK/releases/download/intel-mediasdk-$MEDIA_SDK_VER/MediaStack.tar.gz -P /tmp
2724
RUN cd /tmp && tar -zxf MediaStack.tar.gz && cd MediaStack && ./install_media.sh
2825
RUN rm /tmp/MediaStack.tar.gz && rm -rf /tmp/MediaStack
2926
ENV MFX_HOME=/opt/intel/mediasdk
3027

3128
RUN git clone https://github.com/open-webrtc-toolkit/owt-server.git
29+
RUN mkdir -p ${APP_PATH}
30+
3231
WORKDIR /owt-server
3332

3433
# This is needed to patch licode
3534
RUN git config --global user.email "[email protected]" && \
3635
git config --global user.name "Your Name"
3736

3837
RUN ./scripts/installDepsUnattended.sh
38+
39+
# Set workpath to where the app should be installed for the next step of the multibuild
40+
WORKDIR ${APP_PATH}
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
################################
22
# OWT WebRTC Conference Sample
33

4-
FROM owt-server:latest
5-
6-
ENV CLIENT_SAMPLE_PATH=/owt-client-javascript/dist/samples/conference
4+
FROM owt-server-conference-install:latest
75

86
WORKDIR /owt-server
9-
107
RUN ./scripts/build.js -t all --check
11-
RUN ./scripts/pack.js -t all --install-module --sample-path $CLIENT_SAMPLE_PATH .
12-
8+
RUN ./scripts/pack.js -t all --install-module --app-path ${APP_PATH} .
139
RUN ./dist/video_agent/install_openh264.sh

docker/conference/build_server.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
3+
options() {
4+
echo "Usage: $0 [ -p FILEPATH ] [ -i IMAGE_NAME ]" >&2
5+
echo " -p App directory" >&2
6+
echo " -i Docker image name" >&2
7+
echo " -n Request docker use --no-cache" >&2
8+
}
9+
echo "Number of args $# $*"
10+
if [[ $* != *-p* ]]; then
11+
echo "-p is required"
12+
exit 1
13+
fi
14+
15+
DIRNAME=$(dirname "$0")
16+
REALPATH=$(realpath "$DIRNAME")
17+
IMG="owt-server-conference"
18+
NO_CACHE="";
19+
20+
while getopts p:i:n flag; do
21+
case "${flag}" in
22+
p)
23+
echo "using flag: -$flag"
24+
if [[ ${OPTARG} == "." ]]; then
25+
LOCAL_APP_PATH=$PWD
26+
else
27+
LOCAL_APP_PATH=$(realpath "${OPTARG}")
28+
fi
29+
LOCAL_APP_FOLDER=$(basename "$LOCAL_APP_PATH")
30+
LOCAL_APP_PATH=$(dirname "$LOCAL_APP_PATH")
31+
;;
32+
i)
33+
echo "using flag: -$flag"
34+
IMG=${OPTARG}
35+
;;
36+
n)
37+
NO_CACHE="--no-cache"
38+
;;
39+
\?)
40+
echo "Invalid option: -$flag ${OPTARG}"
41+
options
42+
exit 1
43+
;;
44+
:)
45+
echo "option -$flag requires an argument."
46+
exit 1
47+
;;
48+
esac
49+
done
50+
51+
export DOCKER_IMG_NAME=$IMG
52+
export DOCKERFILE_PATH=$REALPATH
53+
export LOCAL_APP_PATH=$LOCAL_APP_PATH
54+
export LOCAL_APP_FOLDER=$LOCAL_APP_FOLDER
55+
56+
echo Adding app in folder ${LOCAL_APP_PATH}/${LOCAL_APP_FOLDER} to Docker image ${DOCKER_IMG_NAME} ${NO_CACHE}
57+
58+
docker-compose -f "${DOCKERFILE_PATH}/docker-compose.yml" build ${NO_CACHE}

docker/conference/docker-compose.yml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,32 @@ services:
99
- http_proxy
1010
- https_proxy
1111
image: owt-server
12-
owt-server-conference:
12+
13+
# Copy the requested app to the owt-server image
14+
owt-server-conference-install:
1315
build:
14-
context: .
15-
dockerfile: Dockerfile-conference
16+
context: ${LOCAL_APP_PATH}
17+
dockerfile: "${LOCAL_APP_PATH}/${LOCAL_APP_FOLDER}/Dockerfile"
1618
args:
1719
- http_proxy
1820
- https_proxy
19-
image: owt-server-conference
21+
image: owt-server-conference-install
22+
depends_on:
23+
- owt-server
24+
25+
# Build the server image and install the app
26+
owt-server-conference-build:
27+
build:
28+
context: ${LOCAL_APP_PATH}
29+
dockerfile: "${DOCKERFILE_PATH}/Dockerfile-conference"
30+
args:
31+
- http_proxy
32+
- https_proxy
33+
image: "${DOCKER_IMG_NAME}"
2034
network_mode: host
2135
ports:
2236
- "3004:3004"
2337
command: sh -c "service mongodb start && service rabbitmq-server start \
2438
&& cd /owt-server/dist/bin && ./init-all.sh && ./start-all.sh && sleep infinity"
2539
depends_on:
26-
- owt-server
40+
- owt-server-conference-install

scripts/pack.js

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ optParser.addOption('e', 'encrypt', 'boolean', 'Whether encrypt during pack (Eg.
2020
optParser.addOption('d', 'debug', 'boolean', '(Disabled)');
2121
optParser.addOption('o', 'addon-debug', 'boolean', 'Whether pack debug addon (Eg. pack.js -t webrtc-agent -o)');
2222
optParser.addOption('f', 'full', 'boolean', 'Whether perform a full pack (--full is the equalivation of pack.js -t all -r -i)');
23-
optParser.addOption('s', 'sample-path', 'string', 'Specify sample path (Eg. pack.js -t all -s ${samplePath})');
23+
optParser.addOption('p', 'app-path', 'string', 'Specify app path (Eg. pack.js -t all --app-path ${appPath})');
2424
optParser.addOption('a', 'archive', 'string', 'Specify archive name (Eg. pack.js -t all -a ${archiveName})');
2525
optParser.addOption('n', 'node-module-path', 'string', 'Specify shared-node-module directory');
2626
optParser.addOption('c', 'copy-module-path', 'string', 'Specify copy node modules directory');
@@ -596,24 +596,37 @@ function packScripts() {
596596
execSync(`chmod +x ${binDir}/\*.sh`);
597597
}
598598

599-
function packSamples() {
600-
if (!options['sample-path']) return;
599+
function packApps() {
600+
if (!options['app-path']) return;
601601
chdir(originCwd);
602-
var samplePath = options['sample-path'];
603-
if (!fs.existsSync(samplePath)) {
604-
console.log(`\x1b[31mError: ${samplePath} does not exist\x1b[0m`);
602+
var appPath = options['app-path'];
603+
if (!fs.existsSync(appPath)) {
604+
console.log(`\x1b[31mError: ${appPath} does not exist\x1b[0m`);
605605
return;
606606
}
607-
execSync(`rm -rf ${distDir}/extras`);
608-
execSync(`mkdir -p ${distDir}/extras`);
609-
execSync(`cp -a ${samplePath} ${distDir}/extras/basic_example`);
607+
execSync(`rm -rf ${distDir}/apps`);
608+
execSync(`mkdir -p ${distDir}/apps`);
609+
console.log('\x1b[32mApps folder created in :', distDir, '\x1b[0m');
610+
execSync(`cp -a ${appPath} ${distDir}/apps/current_app`);
610611

611-
const certScript = `${distDir}/extras/basic_example/initcert.js`;
612+
// Look in the app's package.json to see what file to use for main.js
613+
var jsonTXT = execSync(`cat ${distDir}/apps/current_app/package.json`);
614+
var appJSON = JSON.parse(jsonTXT)["main"];
615+
616+
if (!appJSON === undefined) {
617+
console.log("\x1b[31mError: No main js file for the app\x1b[0m");
618+
return;
619+
} else {
620+
// Make a soft link to the main JS file node.js should call
621+
if (appJSON !== 'main.js')
622+
execSync(`ln -sf ${distDir}/apps/current_app/${appJSON} ${distDir}/apps/current_app/main.js`);
623+
}
624+
const certScript = `${distDir}/apps/current_app/initcert.js`;
612625
if (fs.existsSync(certScript))
613626
execSync(`chmod +x ${certScript}`);
614627

615628
if (options['install-module']) {
616-
chdir(`${distDir}/extras/basic_example`);
629+
chdir(`${distDir}/apps/current_app`);
617630
execSync('npm install' + npmInstallOption);
618631
}
619632
}
@@ -635,7 +648,7 @@ getTargets()
635648
.then(cleanIfRepack)
636649
.then(processTargets)
637650
.then(packScripts)
638-
.then(packSamples)
651+
.then(packApps)
639652
.then(archive)
640653
.then(() => {
641654
console.log('\x1b[32mWork finished in directory:', distDir, '\x1b[0m');

scripts/release/daemon-bin.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ case $startStop in
176176
echo $! > ${pid}
177177
;;
178178
app )
179-
cd ${OWT_HOME}/extras/basic_example/
180-
nohup nice -n ${OWT_NICENESS} node samplertcservice.js \
179+
cd ${OWT_HOME}/apps/current_app/
180+
nohup nice -n ${OWT_NICENESS} node main.js \
181181
> "${stdout}" 2>&1 </dev/null &
182182
echo $! > ${pid}
183183
;;

scripts/release/daemon-mcu.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ case $startStop in
184184
echo $! > ${pid}
185185
;;
186186
app )
187-
cd ${OWT_HOME}/extras/basic_example/
188-
nohup nice -n ${OWT_NICENESS} node samplertcservice.js \
187+
cd ${OWT_HOME}/apps/current_app/
188+
nohup nice -n ${OWT_NICENESS} node main.js \
189189
> "${stdout}" 2>&1 </dev/null &
190190
echo $! > ${pid}
191191
;;

source/management_api/initdb.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var cipher = require('./cipher');
2020

2121
var dirName = !process.pkg ? __dirname : path.dirname(process.execPath);
2222
var configFile = path.join(dirName, 'management_api.toml');
23-
var sampleServiceFile = path.resolve(dirName, '../extras/basic_example/samplertcservice.js');
23+
var sampleServiceFile = path.resolve(dirName, '../apps/current_app/main.js');
2424

2525
function prepareDB(next) {
2626
if (fs.existsSync(cipher.astore)) {

0 commit comments

Comments
 (0)