From 2faf521cd28e2b0ae9389b8fed8891dbf922006e Mon Sep 17 00:00:00 2001
From: Felipe Cecagno <fcecagno@gmail.com>
Date: Fri, 1 Feb 2019 17:29:27 -0300
Subject: [PATCH] update docker files for kurento

---
 labs/docker/kurento/Dockerfile           | 21 +++++++++++++++++----
 labs/docker/kurento/docker-entrypoint.sh | 21 +++++++++++----------
 labs/docker/kurento/healthchecker.sh     |  2 +-
 3 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/labs/docker/kurento/Dockerfile b/labs/docker/kurento/Dockerfile
index 97dbf88925..f6619abf74 100644
--- a/labs/docker/kurento/Dockerfile
+++ b/labs/docker/kurento/Dockerfile
@@ -1,13 +1,20 @@
 FROM ubuntu:16.04
 
+# In order to build kurento dev, use:
+# docker build --build-arg APT_KEY="http://keyserver.ubuntu.com/pks/lookup?op=get&options=mr&search=0xFC8A16625AFA7A83" --build-arg APT_REPO="deb [arch=amd64] http://ubuntu.openvidu.io/dev xenial kms6" --build-arg CACHE_BUST="$(date +%s)" -t mconf/kurento:upstream-dev .
+
+ARG APT_KEY="https://ubuntu.bigbluebutton.org/repo/bigbluebutton.asc"
+ARG APT_REPO="deb https://ubuntu.bigbluebutton.org/xenial-220-dev bigbluebutton-xenial main"
+ARG CACHE_BUST=1
+
 ENV DEBIAN_FRONTEND noninteractive
 
 RUN apt-get update \
  && apt-get -y dist-upgrade \
  && apt-get install -y software-properties-common curl wget apt-transport-https
 
-RUN wget https://ubuntu.bigbluebutton.org/repo/bigbluebutton.asc -O- | apt-key add - \
- && add-apt-repository "deb https://ubuntu.bigbluebutton.org/xenial-200-dev bigbluebutton-xenial main" \
+RUN wget "$APT_KEY" -O- | apt-key add - \
+ && add-apt-repository "$APT_REPO" \
  && apt-get update \
  && apt-get -y install kurento-media-server bzip2 jq \
  && apt-get clean \
@@ -19,10 +26,16 @@ RUN apt-get update \
 COPY ./docker-entrypoint.sh /usr/local/bin/
 COPY ./healthchecker.sh /healthchecker.sh
 
-HEALTHCHECK --start-period=15s --interval=30s --timeout=3s --retries=1 CMD /healthchecker.sh
-
 ENV GST_DEBUG=Kurento*:5
 ENV PORT=8888
+# stun.l.google.com
+ENV STUN_IP=64.233.186.127
+ENV STUN_PORT=19302
+ENV TURN_URL=""
+ENV RTP_MIN_PORT=24577
+ENV RTP_MAX_PORT=32768
+
+HEALTHCHECK --start-period=15s --interval=30s --timeout=3s --retries=1 CMD /healthchecker.sh
 
 ENTRYPOINT ["docker-entrypoint.sh"]
 CMD ["/usr/bin/kurento-media-server"]
diff --git a/labs/docker/kurento/docker-entrypoint.sh b/labs/docker/kurento/docker-entrypoint.sh
index 4d1d3a444e..82d3429101 100755
--- a/labs/docker/kurento/docker-entrypoint.sh
+++ b/labs/docker/kurento/docker-entrypoint.sh
@@ -3,20 +3,21 @@
 apt-get install -y openh264-gst-plugins-bad-1.5
 
 rm -f /etc/kurento/modules/kurento/WebRtcEndpoint.conf.ini
-touch /etc/kurento/modules/kurento/WebRtcEndpoint.conf.ini
+# Generate WebRtcEndpoint configuration
+echo "stunServerAddress=$STUN_IP" >> /etc/kurento/modules/kurento/WebRtcEndpoint.conf.ini
+echo "stunServerPort=$STUN_PORT" >> /etc/kurento/modules/kurento/WebRtcEndpoint.conf.ini
 
-if [ -n "$KMS_TURN_URL" ]; then
-  echo "turnURL=$KMS_TURN_URL" >> /etc/kurento/modules/kurento/WebRtcEndpoint.conf.ini
+if [ "$TURN_URL" != "" ]; then
+  echo "turnURL=$TURN_URL" >> /etc/kurento/modules/kurento/WebRtcEndpoint.conf.ini
 fi
 
-if [ -n "$KMS_STUN_IP" -a -n "$KMS_STUN_PORT" ]; then
-  # Generate WebRtcEndpoint configuration
-  echo "stunServerAddress=$KMS_STUN_IP" >> /etc/kurento/modules/kurento/WebRtcEndpoint.conf.ini
-  echo "stunServerPort=$KMS_STUN_PORT" >> /etc/kurento/modules/kurento/WebRtcEndpoint.conf.ini
-fi
+rm -f /etc/kurento/modules/kurento/BaseRtpEndpoint.conf.ini
+# Generate BaseRtpEndpoint configuration
+echo "minPort=$RTP_MIN_PORT" >> /etc/kurento/modules/kurento/BaseRtpEndpoint.conf.ini
+echo "maxPort=$RTP_MAX_PORT" >> /etc/kurento/modules/kurento/BaseRtpEndpoint.conf.ini
 
-KMS_CONFIG=$(cat /etc/kurento/kurento.conf.json | sed '/^[ ]*\/\//d' | jq ".mediaServer.net.websocket.port = $PORT")
-echo $KMS_CONFIG > /etc/kurento/kurento.conf.json
+CONFIG=$(cat /etc/kurento/kurento.conf.json | sed '/^[ ]*\/\//d' | jq ".mediaServer.net.websocket.port = $PORT")
+echo $CONFIG > /etc/kurento/kurento.conf.json
 
 # Remove ipv6 local loop until ipv6 is supported
 cat /etc/hosts | sed '/::1/d' | tee /etc/hosts > /dev/null
diff --git a/labs/docker/kurento/healthchecker.sh b/labs/docker/kurento/healthchecker.sh
index c7f6ce82fa..f127ae41c1 100755
--- a/labs/docker/kurento/healthchecker.sh
+++ b/labs/docker/kurento/healthchecker.sh
@@ -1,3 +1,3 @@
 #!/bin/bash
 
-[[ "$(curl -w '%{http_code}' -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: 127.0.0.1:8888" -H "Origin: 127.0.0.1" http://127.0.0.1:8888/kurento)" == 500 ]] && exit 0 || exit 1
+[[ "$(curl -w '%{http_code}' -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: 127.0.0.1:$PORT" -H "Origin: 127.0.0.1" http://127.0.0.1:$PORT/kurento)" == 500 ]] && exit 0 || exit 1
-- 
GitLab