summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2020-08-20 00:52:52 +0200
committerChristian Pointner <equinox@spreadspace.org>2020-08-20 00:52:52 +0200
commit7d134001fe95c0ee5e798f2d7cfd27162b76dd8c (patch)
treebbe520531c7e8637c8c6c0ad83b9f86a70d7617e
parentmove blackmagic desktopvideo role (diff)
add new rtmp streamer role
-rw-r--r--inventory/host_vars/s2-thetys.yml4
-rw-r--r--roles/streaming/rtmp/streamer/defaults/main.yml13
-rw-r--r--roles/streaming/rtmp/streamer/tasks/main.yml30
-rw-r--r--roles/streaming/rtmp/streamer/templates/nginx.conf.j231
-rw-r--r--roles/streaming/rtmp/streamer/templates/pod-spec.yml.j269
-rw-r--r--spreadspace/s2-thetys.yml1
6 files changed, 148 insertions, 0 deletions
diff --git a/inventory/host_vars/s2-thetys.yml b/inventory/host_vars/s2-thetys.yml
index 38909332..a73c33d9 100644
--- a/inventory/host_vars/s2-thetys.yml
+++ b/inventory/host_vars/s2-thetys.yml
@@ -46,3 +46,7 @@ kubernetes_version: 1.18.8
kubernetes_container_runtime: docker
kubernetes_standalone_max_pods: 42
kubernetes_standalone_cni_variant: with-portmap
+
+rtmp_streamer_inst_name: feed
+rtmp_streamer_nginx_image_version: 2020-04-29.7
+rtmp_streamer_decklink_card: "DeckLink Mini Recorder"
diff --git a/roles/streaming/rtmp/streamer/defaults/main.yml b/roles/streaming/rtmp/streamer/defaults/main.yml
new file mode 100644
index 00000000..5a9b48f7
--- /dev/null
+++ b/roles/streaming/rtmp/streamer/defaults/main.yml
@@ -0,0 +1,13 @@
+---
+rtmp_streamer_base_path: /srv/rtmp/streamer
+
+# rtmp_streamer_inst_name: feed
+# rtmp_streamer_nginx_image_version: 2020-04-29.7
+# rtmp_streamer_decklink_card: "DeckLink Mini Recorder"
+rtmp_streamer_app_name: "{{ rtmp_streamer_inst_name }}"
+rtmp_streamer_quality_levels:
+ - full
+
+rtmp_streamer_config: {}
+
+rtmp_streamer_port: 1935
diff --git a/roles/streaming/rtmp/streamer/tasks/main.yml b/roles/streaming/rtmp/streamer/tasks/main.yml
new file mode 100644
index 00000000..828ceba6
--- /dev/null
+++ b/roles/streaming/rtmp/streamer/tasks/main.yml
@@ -0,0 +1,30 @@
+---
+- name: create rtmp-streamer scripts subdirectories
+ file:
+ path: "{{ rtmp_streamer_base_path }}/{{ rtmp_streamer_inst_name }}"
+ state: directory
+
+- name: generate nginx config
+ template:
+ src: nginx.conf.j2
+ dest: "{{ rtmp_streamer_base_path }}/{{ rtmp_streamer_inst_name }}/nginx.conf"
+
+- name: generate streamer config
+ copy:
+ content: "{{ rtmp_streamer_config | combine({'rtmp_base_url': 'rtmp://127.0.0.1/'+rtmp_streamer_app_name}) | to_nice_yaml }}\n"
+ dest: "{{ rtmp_streamer_base_path }}/{{ rtmp_streamer_inst_name }}/config.yml"
+
+- name: install pod manifest
+ vars:
+ kubernetes_standalone_pod:
+ name: "rtmp-streamer-{{ rtmp_streamer_inst_name }}"
+ spec: "{{ lookup('template', 'pod-spec.yml.j2') }}"
+ config_hash_items:
+ - path: "{{ rtmp_streamer_base_path }}/{{ rtmp_streamer_inst_name }}/nginx.conf"
+ properties:
+ - checksum
+ - path: "{{ rtmp_streamer_base_path }}/{{ rtmp_streamer_inst_name }}/config.yml"
+ properties:
+ - checksum
+ include_role:
+ name: kubernetes/standalone/pod
diff --git a/roles/streaming/rtmp/streamer/templates/nginx.conf.j2 b/roles/streaming/rtmp/streamer/templates/nginx.conf.j2
new file mode 100644
index 00000000..61cdfd92
--- /dev/null
+++ b/roles/streaming/rtmp/streamer/templates/nginx.conf.j2
@@ -0,0 +1,31 @@
+worker_processes 1;
+pid /var/lib/nginx/nginx.pid;
+error_log /dev/stderr info;
+
+include /etc/nginx/modules-enabled/*.conf;
+
+events {
+ worker_connections 768;
+ # multi_accept on;
+}
+
+rtmp {
+ access_log /dev/null;
+
+ server {
+ listen 1935;
+
+ ping 10s;
+ ping_timeout 3s;
+ drop_idle_publisher 10s;
+ idle_streams off;
+
+ application {{ rtmp_streamer_app_name }} {
+ live on;
+ meta copy;
+
+ allow publish 127.0.0.1;
+ deny publish all;
+ }
+ }
+}
diff --git a/roles/streaming/rtmp/streamer/templates/pod-spec.yml.j2 b/roles/streaming/rtmp/streamer/templates/pod-spec.yml.j2
new file mode 100644
index 00000000..b4a6ee9d
--- /dev/null
+++ b/roles/streaming/rtmp/streamer/templates/pod-spec.yml.j2
@@ -0,0 +1,69 @@
+containers:
+- name: nginx
+ image: registry.gitlab.com/spreadspace/docker/nginx:{{ rtmp_streamer_nginx_image_version }}
+ imagePullPolicy: Always
+ command:
+ - nginx
+ args:
+ - -c
+ - /srv/nginx.conf
+ - -g
+ - "daemon off;"
+ ports:
+ - containerPort: 1935
+ hostPort: {{ rtmp_streamer_port }}
+ volumeMounts:
+ - name: home
+ mountPath: /srv
+ readOnly: true
+ - name: nginx-lib
+ mountPath: /var/lib/nginx
+
+- name: ffmpeg
+ image: registry.gitlab.com/spreadspace/docker/nginx:{{ rtmp_streamer_nginx_image_version }}
+ imagePullPolicy: Always
+ command:
+ - ffmpeg-decklink-rtmp.py
+ args:
+ - "{{ rtmp_streamer_decklink_card }}"
+{% for level in rtmp_streamer_quality_levels %}
+ - {{ level }}
+{% endfor %}
+ securityContext:
+ privileged: true
+ volumeMounts:
+ - name: home
+ mountPath: /srv
+ readOnly: true
+ - name: decklink-device
+ mountPath: /dev/blackmagic
+ - name: decklink-libs
+ subPath: libDeckLinkAPI.so
+ mountPath: /usr/lib/libDeckLinkAPI.so
+ readOnly: true
+ - name: decklink-libs
+ subPath: libDeckLinkPreviewAPI.so
+ mountPath: /usr/lib/libDeckLinkPreviewAPI.so
+ readOnly: true
+ - name: decklink-libs
+ subPath: blackmagic
+ mountPath: /usr/lib/blackmagic
+ readOnly: true
+ env:
+ - name: CONFIG_FILENAME
+ value: /srv/config.yml
+
+volumes:
+- name: home
+ hostPath:
+ path: "{{ rtmp_streamer_base_path }}/{{ rtmp_streamer_inst_name }}"
+- name: nginx-lib
+ emptyDir:
+ medium: Memory
+- name: decklink-device
+ hostPath:
+ path: /dev/blackmagic
+- name: decklink-libs
+ hostPath:
+ type: Directory
+ path: /usr/lib/
diff --git a/spreadspace/s2-thetys.yml b/spreadspace/s2-thetys.yml
index 2fe73691..fc3c58e3 100644
--- a/spreadspace/s2-thetys.yml
+++ b/spreadspace/s2-thetys.yml
@@ -12,3 +12,4 @@
- role: streaming/blackmagic/desktopvideo
- role: kubernetes/base
- role: kubernetes/standalone/base
+ - role: streaming/rtmp/streamer