Skip to content

Commit 17f684f

Browse files
committed
Initial checkin
0 parents  commit 17f684f

File tree

5 files changed

+125
-0
lines changed

5 files changed

+125
-0
lines changed

Dockerfile

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM alpine:latest
2+
MAINTAINER Ian Blenke <ian@blenke.com>
3+
4+
ENV COTURN_VERSION 4.5.0.3
5+
6+
RUN apk add --no-cache --update bash curl git make build-base automake autoconf readline readline-dev gettext libcrypto1.0 openssl openssl-dev libevent libevent-dev linux-headers sqlite sqlite-libs sqlite-dev mariadb-libs mysql-dev postgresql postgresql-dev sqlite hiredis hiredis-dev jq && \
7+
######################################################################
8+
## Adding mongodb from alpine edge adds 130M to the 44M image size. ##
9+
## Uncomment the apk line below if you really need this. ##
10+
######################################################################
11+
# apk add --no-cache --update --repository http://dl-4.alpinelinux.org/alpine/edge/testing mongodb && \
12+
git clone --branch ${COTURN_VERSION} https://github.com/coturn/coturn /build && \
13+
cd /build && \
14+
./configure --prefix=/app && \
15+
make install && \
16+
rm -fr /build && \
17+
apk del hiredis-dev postgresql-dev mysql-dev sqlite-dev linux-headers libevent-dev openssl-dev readline-dev automake autoconf build-base make git && \
18+
rm -rf /var/cache/apk/*
19+
20+
WORKDIR /app
21+
22+
ADD coturn.sh /coturn.sh
23+
RUN chmod u+rx /coturn.sh
24+
25+
CMD /coturn.sh

Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build:
2+
docker build -t ianblenke/coturn .

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# ianblenke/coturn:latest
2+
3+
This is an autobuild docker image repo for an Alpine based 44M image build of coturn.
4+
5+
This builds from the origin source tree:
6+
7+
https://github.com/coturn/coturn
8+
9+
The startup script will auto-discover a public and private IP address, which can be
10+
environmentally overridden.
11+
12+
The startup script will also accept a `JSON_CONFIG` environment variable containing a
13+
JSON formatted string with a `config` key array of lines to add to the generated
14+
coturn configuration file.
15+
16+
There is presently support compiled in for sqlite3, redis, mysql, and postgresql.
17+
Note: Mongo support is commented out, as it adds 130M to the image size.
18+

coturn.sh

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
3+
# Discover public and private IP for this instance
4+
PUBLIC_IPV4="$(curl -qs http://169.254.169.254/2014-11-05/meta-data/public-ipv4)"
5+
[ -n "$PUBLIC_IPV4" ] || PUBLIC_IPV4="$(curl -qs ipinfo.io/ip)"
6+
PRIVATE_IPV4="$(curl -qs http://169.254.169.254/2014-11-05/meta-data/local-ipv4)"
7+
[ -n "$PRIVATE_IPV4" ] || PRIVATE_IPV4="$(ip addr show eth0 | grep 'inet ' | awk '{print $2}' | cut -d/ -f1)"
8+
9+
# Yes, this does work. See: https://github.com/ianblenke/aws-6to4-docker-ipv6
10+
#IPV6="$(ip -6 addr show eth0 scope global | grep inet6 | awk '{print $2}')"
11+
12+
PORT=${PORT:-3478}
13+
ALT_PORT=${PORT:-3479}
14+
15+
TLS_PORT=${TLS:-5349}
16+
TLS_ALT_PORT=${PORT:-5350}
17+
18+
MIN_PORT=${MIN_PORT:-49152}
19+
MAX_PORT=${MAX_PORT:-65535}
20+
21+
TURNSERVER_CONFIG=/app/etc/turnserver.conf
22+
23+
cat <<EOF > ${TURNSERVER_CONFIG}-template
24+
# https://github.com/coturn/coturn/blob/master/examples/etc/turnserver.conf
25+
listening-port=${PORT}
26+
min-port=${MIN_PORT}
27+
max-port=${MAX_PORT}
28+
EOF
29+
30+
if [ "${PUBLIC_IPV4}" != "${PRIVATE_IPV4}" ]; then
31+
echo "external-ip=${PUBLIC_IPV4}/${PRIVATE_IPV4}" >> ${TURNSERVER_CONFIG}-template
32+
else
33+
echo "external-ip=${PUBLIC_IPV4}" >> ${TURNSERVER_CONFIG}-template
34+
fi
35+
36+
if [ -n "${JSON_CONFIG}" ]; then
37+
echo "${JSON_CONFIG}" | jq -r '.config[]' >> ${TURNSERVER_CONFIG}-template
38+
fi
39+
40+
if [ -n "$SSL_CERTIFICATE" ]; then
41+
echo "$SSL_CA_CHAIN" > /app/etc/turn_server_cert.pem
42+
echo "$SSL_CERTIFICATE" >> /app/etc/turn_server_cert.pem
43+
echo "$SSL_PRIVATE_KEY" > /app/etc/turn_server_pkey.pem
44+
45+
cat <<EOT >> ${TURNSERVER_CONFIG}-template
46+
tls-listening-port=${TLS_PORT}
47+
alt-tls-listening-port=${TLS_ALT_PORT}
48+
cert=/app/etc/turn_server_cert.pem
49+
pkey=/app/etc/turn_server_pkey.pem
50+
EOT
51+
52+
fi
53+
54+
# Allow for ${VARIABLE} substitution using envsubst from gettext
55+
envsubst < ${TURNSERVER_CONFIG}-template > ${TURNSERVER_CONFIG}
56+
57+
exec /app/bin/turnserver

docker-compose.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
coturn:
2+
build: .
3+
container_name: coturn
4+
net: host
5+
ports:
6+
- "3478:3478/udp" # STUN/TURN UDP
7+
- "3478:3478/tcp" # STUN/TURN TCP
8+
- "3479:3479/udp" # STUN/TURN UDP Alt port (RFC5780 support)
9+
- "3479:3479/tcp" # STUN/TURN TCP Alt port (RFC5780 support)
10+
- "5349:5349/udp" # STUN/TURN DTLS
11+
- "5349:5349/tcp" # STUN/TURN TLS
12+
- "5350:5350/udp" # STUN/TURN DTLS Alt port (RFC5780 support)
13+
- "5350:5350/tcp" # STUN/TURN TLS Alt port (RFC5780 support)
14+
- "49152:65535/udp" # UDP media ports for TURN relay
15+
environment:
16+
PORT: 3478
17+
ALT_PORT: 3479
18+
TLS_PORT: 5349
19+
TLS_ALT_PORT: 5350
20+
MIN_PORT: 49152
21+
MAX_PORT: 65535
22+
JSON_CONFIG: '{"config":["no-auth"]}'
23+

0 commit comments

Comments
 (0)