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

Commit 381858c

Browse files
committed
First release
Signed-off-by: Zhou, Cheng <[email protected]>
0 parents  commit 381858c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+11134
-0
lines changed

CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cmake_minimum_required (VERSION 2.8)
2+
3+
Project(OVC NONE)
4+
5+
file(GLOB dirs "deployment" "*")
6+
list(REMOVE_DUPLICATES dirs)
7+
foreach(dir ${dirs})
8+
if(EXISTS ${dir}/CMakeLists.txt)
9+
add_subdirectory(${dir})
10+
endif()
11+
endforeach()
12+
13+
# legal message
14+
execute_process(COMMAND printf "\nThis script will build third party components licensed under various open source licenses into your container images. The terms under which those components may be used and distributed can be found with the license document that is provided with those components. Please familiarize yourself with those terms to ensure your distribution of those components complies with the terms of those licenses.\n\n")

LICENSE

Lines changed: 319 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
This project is for Open Visual Cloud CDN Transcode E2E Sample.
2+
3+
## Key ingredients in this repo
4+
- Dockerfiles
5+
- CMakefiles
6+
- Configuration files
7+
- Helper scripts
8+
- Reference Architecture document
9+
- User Guide (Getting Started Guide) document
10+
11+
## How to get started?
12+
- Refer to "doc/CDN_Transcode_Sample_RA.md" to understand the design.
13+
- Refer to "doc/CDN_Transcode_Sample_Getting_Started_Guide.md" to setup and run the sample.
14+

cdn-server/.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CMakeLists.txt
2+
*.sh
3+
*.m4
4+
test/*

cdn-server/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
set(service "ovc_cdn_service")
2+
include("${CMAKE_SOURCE_DIR}/script/service.cmake")

cdn-server/Dockerfile

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
2+
FROM ubuntu:18.04 AS build
3+
WORKDIR /home
4+
5+
# COMMON BUILD TOOLS
6+
RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y -q --no-install-recommends build-essential autoconf make git wget pciutils cpio libtool lsb-release ca-certificates pkg-config bison flex
7+
8+
# Install cmake
9+
ARG CMAKE_VER=3.13.1
10+
ARG CMAKE_REPO=https://cmake.org/files
11+
RUN wget -O - ${CMAKE_REPO}/v${CMAKE_VER%.*}/cmake-${CMAKE_VER}.tar.gz | tar xz && \
12+
cd cmake-${CMAKE_VER} && \
13+
./bootstrap --prefix="/usr" && \
14+
make -j8 && \
15+
make install
16+
17+
# Install automake, use version 1.14 on CentOS
18+
ARG AUTOMAKE_VER=1.14
19+
ARG AUTOMAKE_REPO=https://ftp.gnu.org/pub/gnu/automake/automake-${AUTOMAKE_VER}.tar.xz
20+
RUN apt-get install -y -q automake
21+
22+
# Build nginx-rtmp
23+
ARG NGINX_RTMP_VER=v1.2.1
24+
ARG NGINX_RTMP_REPO=https://github.com/arut/nginx-rtmp-module/archive/${NGINX_RTMP_VER}.tar.gz
25+
ARG NGINX_RTMP_PATCH_HLS=https://raw.githubusercontent.com/VCDP/CDN/master/0001-add-hevc-support-for-rtmp-and-hls.patch
26+
ARG NGINX_RTMP_PATCH_DASH=https://raw.githubusercontent.com/VCDP/CDN/master/0002-add-HEVC-support-for-dash.patch
27+
28+
RUN wget -O - ${NGINX_RTMP_REPO} | tar xz && mv nginx-rtmp-module-${NGINX_RTMP_VER#v} nginx-rtmp-module && \
29+
cd nginx-rtmp-module && \
30+
wget -O - ${NGINX_RTMP_PATCH_HLS} | patch -p1 && \
31+
wget -O - ${NGINX_RTMP_PATCH_DASH} | patch -p1
32+
33+
34+
# Build nginx & nginx-rtmp
35+
ARG NGINX_VER=1.14.2
36+
ARG NGINX_REPO=https://nginx.org/download/nginx-${NGINX_VER}.tar.gz
37+
38+
RUN apt-get update && apt-get install -y -q --no-install-recommends libssl-dev libpcre3-dev zlib1g-dev libxslt1-dev
39+
40+
RUN wget -O - ${NGINX_REPO} | tar xz && \
41+
cd nginx-${NGINX_VER} && \
42+
./configure --prefix=/var/www --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/x86_64-linux-gnu/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/www/log/error.log --pid-path=/var/www/nginx.pid --lock-path=/var/www/nginx.lock --http-log-path=/var/www/log/access.log --http-client-body-temp-path=/var/www/tmp/client_body --http-proxy-temp-path=/var/www/tmp/proxy --http-fastcgi-temp-path=/var/www/tmp/fastcgi --http-uwsgi-temp-path=/var/www/tmp/uwsgi --http-scgi-temp-path=/var/www/tmp/scgi --user=www-data --group=www-data --with-select_module --with-poll_module --with-threads --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-stream --with-stream_ssl_module --with-stream_realip_module --with-stream_ssl_preread_module --with-pcre --add-module=../nginx-rtmp-module && \
43+
make -j8 && \
44+
make install DESTDIR=/home/build
45+
46+
# NGINX Setup
47+
RUN mkdir -p /home/build/var/www/tmp/client_body && \
48+
mkdir -p /home/build/var/www/tmp/proxy && \
49+
mkdir -p /home/build/var/www/tmp/fastcgi && \
50+
mkdir -p /home/build/var/www/tmp/uwsgi && \
51+
mkdir -p /home/build/var/www/tmp/scgi && \
52+
mkdir -p /home/build/var/www/cache && \
53+
mkdir -p /home/build/var/www/html
54+
55+
56+
FROM ubuntu:18.04
57+
LABEL Description="This is the base image for a NGINX+RTMP service"
58+
LABEL Vendor="Intel Corporation"
59+
WORKDIR /home
60+
61+
# Prerequisites
62+
RUN ln -sf /usr/share/zoneinfo/UTC /etc/localtime && \
63+
DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y -q --no-install-recommends libxml2 libssl-dev libpcre3 zlib1g libxslt1.1 python3-tornado python3-kafka python3-bs4 python3-kazoo vim && \
64+
rm -rf /var/lib/apt/lists/*
65+
# Install
66+
COPY --from=build /home/build /
67+
COPY *.xsl /etc/nginx/
68+
COPY *.conf /etc/nginx/
69+
COPY *.ini /home/
70+
COPY *.py /home/
71+
CMD ["/bin/bash","-c","/home/main.py&/usr/sbin/nginx"]
72+
VOLUME /etc/nginx /var/www/html /var/www/tmp/client_body /var/www/tmp/proxy /var/www/tmp/fastcgi /var/www/tmp/uwsgi /var/www/tmp/scgi /var/www/cache /var/www/dash /var/www/hls
73+
EXPOSE 8080

cdn-server/build.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash -e
2+
3+
IMAGE="ovc_cdn_service"
4+
DIR=$(dirname $(readlink -f "$0"))
5+
6+
. "${DIR}/../script/build.sh"

cdn-server/config.ini

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[run]
2+
timeSpan=20000
3+
[mode]
4+
srcMode=local
5+
[path]
6+
srcPath=/var/www/archive
7+

cdn-server/main.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/python3
2+
3+
from tornado import ioloop, web
4+
from tornado.options import define, options, parse_command_line
5+
from playlist import PlayListHandler
6+
from schedule import ScheduleHandler
7+
8+
APP = web.Application([
9+
(r'/playlist', PlayListHandler),
10+
(r'/schedule/.*', ScheduleHandler),
11+
])
12+
13+
if __name__ == "__main__":
14+
define("port", default=2222, help="the binding port", type=int)
15+
define("ip", default="127.0.0.1", help="the binding ip")
16+
parse_command_line()
17+
print("Listening to " + options.ip + ":" + str(options.port))
18+
APP.listen(options.port, address=options.ip)
19+
ioloop.IOLoop.instance().start()

cdn-server/messaging.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/python3
2+
3+
import socket
4+
from kafka import KafkaProducer, KafkaConsumer, TopicPartition
5+
6+
KAFKA_HOSTS = ["kafka:9092"]
7+
8+
class Producer():
9+
def __init__(self):
10+
super(Producer, self).__init__()
11+
self._client_id = socket.gethostname()
12+
self._producer = None
13+
14+
def send(self, topic, message):
15+
if not self._producer:
16+
try:
17+
self._producer = KafkaProducer(bootstrap_servers=KAFKA_HOSTS,
18+
client_id=self._client_id,
19+
api_version=(0, 10), retries=1)
20+
except Exception as e:
21+
print(str(e))
22+
self._producer = None
23+
24+
if self._producer:
25+
try:
26+
self._producer.send(topic, message.encode('utf-8'))
27+
print("send "+topic+": ")
28+
print(message)
29+
except Exception as e:
30+
print(str(e))
31+
else:
32+
print("producer not available")
33+
34+
def flush(self):
35+
if self._producer:
36+
self._producer.flush()
37+
38+
def close(self):
39+
if self._producer:
40+
self.flush()
41+
self._producer.close()
42+
43+
class Consumer():
44+
def __init__(self, group=None):
45+
super(Consumer, self).__init__()
46+
self._client_id = socket.gethostname()
47+
self._group = group
48+
49+
def messages(self, topic, timeout=None):
50+
c = KafkaConsumer(topic, bootstrap_servers=KAFKA_HOSTS, client_id=self._client_id,
51+
group_id=self._group, api_version=(0, 10))
52+
53+
partitions = c.partitions_for_topic(topic)
54+
if not partitions:
55+
raise Exception("Topic "+topic+" not exist")
56+
57+
timeout1 = 100 if timeout is None else timeout
58+
while True:
59+
partitions = c.poll(timeout1)
60+
if partitions:
61+
for p in partitions:
62+
for msg in partitions[p]:
63+
yield msg.value.decode('utf-8')
64+
if timeout is not None:
65+
yield ""
66+
67+
c.close()
68+
69+
def debug(self, topic):
70+
c = KafkaConsumer(bootstrap_servers=KAFKA_HOSTS, client_id=self._client_id,
71+
group_id=None, api_version=(0, 10))
72+
73+
# assign/subscribe topic
74+
partitions = c.partitions_for_topic(topic)
75+
if not partitions:
76+
raise Exception("Topic "+topic+" not exist")
77+
c.assign([TopicPartition(topic, p) for p in partitions])
78+
79+
# seek to beginning if needed
80+
c.seek_to_beginning()
81+
82+
# fetch messages
83+
while True:
84+
partitions = c.poll(100)
85+
if partitions:
86+
for p in partitions:
87+
for msg in partitions[p]:
88+
yield msg.value.decode('utf-8')
89+
yield ""
90+
91+
c.close()

0 commit comments

Comments
 (0)