Merge pull request #690 from jb-alvarado/master

optimize for docker
This commit is contained in:
jb-alvarado 2024-07-04 14:51:29 +00:00 committed by GitHub
commit 73c8ecce98
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 136 additions and 111 deletions

View File

@ -1,42 +1,27 @@
FROM almalinux:9 AS base FROM alpine:latest
ENV container docker ARG FFPLAYOUT_VERSION=0.24.0-alpha1
ARG SHARED_STORAGE=false
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == \ ENV DB=/db
systemd-tmpfiles-setup.service ] || rm -f $i; done); \ ENV SHARED_STORAGE=${SHARED_STORAGE}
rm -f /lib/systemd/system/multi-user.target.wants/*; \
rm -f /etc/systemd/system/*.wants/*; \
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*; \
rm -f /lib/systemd/system/anaconda.target.wants/*
FROM base COPY README.md ffplayout-v${FFPLAYOUT_VERSION}_x86_64-unknown-linux-musl.tar.* /tmp/
ARG FFPLAYOUT_VERSION=0.22.0 RUN apk update && \
COPY README.md *.rpm /tmp/ apk upgrade && \
apk add --no-cache ffmpeg sqlite font-dejavu
RUN dnf update -y && \ RUN [[ -f "/tmp/ffplayout-v${FFPLAYOUT_VERSION}_x86_64-unknown-linux-musl.tar.gz" ]] || \
dnf install -y epel-release && \ wget -q "https://github.com/ffplayout/ffplayout/releases/download/v${FFPLAYOUT_VERSION}/ffplayout-v${FFPLAYOUT_VERSION}_x86_64-unknown-linux-musl.tar.gz" -P /tmp/ && \
dnf install -y 'dnf-command(config-manager)' && \ cd /tmp && \
dnf config-manager --set-enabled crb && \ tar xf "ffplayout-v${FFPLAYOUT_VERSION}_x86_64-unknown-linux-musl.tar.gz" && \
dnf install -y --nogpgcheck https://mirrors.rpmfusion.org/free/el/rpmfusion-free-release-$(rpm -E %rhel).noarch.rpm && \ cp ffplayout /usr/bin/ && \
dnf install -y --nogpgcheck https://mirrors.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-$(rpm -E %rhel).noarch.rpm && \ rm -rf /tmp/* && \
dnf install -y ffmpeg wget dejavu-sans-fonts sudo && \ mkdir ${DB}
dnf clean all
RUN [[ -f /tmp/ffplayout-${FFPLAYOUT_VERSION}-1.x86_64.rpm ]] || wget -q "https://github.com/ffplayout/ffplayout/releases/download/v${FFPLAYOUT_VERSION}/ffplayout-${FFPLAYOUT_VERSION}-1.x86_64.rpm" -P /tmp/ && \ RUN ffplayout -u admin -p admin -m contact@example.com --storage-path "/tv-media" --playlist-path "/playlists" --hls-path "/hls" --log-path "/logging"
dnf install -y /tmp/ffplayout-${FFPLAYOUT_VERSION}-1.x86_64.rpm && \
rm /tmp/ffplayout-${FFPLAYOUT_VERSION}-1.x86_64.rpm && \
sed -i "s/User=ffpu/User=root/g" /usr/lib/systemd/system/ffplayout.service && \
systemctl enable ffplayout && \
ffplayout -u admin -p admin -m contact@example.com
EXPOSE 8787 EXPOSE 8787
# Maybe on some systems is needed, combined with run parameters: --tmpfs /tmp --tmpfs /run --tmpfs /run/lock CMD ["/usr/bin/ffplayout", "-l", "0.0.0.0:8787"]
# More infos: https://serverfault.com/a/1087467/387878
#VOLUME [ "/tmp", "/run", "/run/lock" ]
CMD ["/usr/sbin/init"]

View File

@ -40,8 +40,11 @@ How to build the image:\
# build default # build default
docker build -t ffplayout-image . docker build -t ffplayout-image .
# build with shared storage (same storage for all channels)
docker build --build-arg SHARED_STORAGE=true .
# build from root folder, to copy local *.rpm package # build from root folder, to copy local *.rpm package
docker build -f docker/Dockerfile -t ffplayout-image:alma . docker build -f docker/Dockerfile -t ffplayout-image .
# build ffmpeg from source # build ffmpeg from source
docker build -f fromSource.Dockerfile -t ffplayout-image:from-source . docker build -f fromSource.Dockerfile -t ffplayout-image:from-source .
@ -53,10 +56,10 @@ docker build -f nvidia-centos7.Dockerfile -t ffplayout-image:nvidia .
example of command to start the container: example of command to start the container:
```BASH ```BASH
docker run -it --name ffplayout --privileged -p 8787:8787 ffplayout-image docker run -it -v /path/to/db:/db -v /path/to/storage:/tv-media -v /path/to/playlists:/playlists -v /path/to/hls:/hls -v /path/to/logging:/logging --name ffplayout -p 8787:8787 ffplayout-image
# run in daemon mode # run in daemon mode
docker run -d --name ffplayout --privileged -p 8787:8787 ffplayout-image docker run -d --name ffplayout -p 8787:8787 ffplayout-image
# run with docker-compose # run with docker-compose
docker-compose up -d docker-compose up -d

View File

@ -2,10 +2,7 @@ version: '3'
services: services:
ffplayout: ffplayout:
cap_add:
- SYS_ADMIN
container_name: ffplayout container_name: ffplayout
privileged: true
build: build:
context: . context: .
dockerfile: ./Dockerfile dockerfile: ./Dockerfile

View File

@ -81,12 +81,6 @@ async fn main() -> std::io::Result<()> {
.await .await
.map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))?; .map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))?;
if ARGS.dump_advanced.is_none() && ARGS.dump_config.is_none() {
if let Err(e) = handles::db_migrate(&pool).await {
panic!("{e}");
};
}
if let Err(c) = run_args(&pool).await { if let Err(c) = run_args(&pool).await {
exit(c); exit(c);
} }

View File

@ -592,6 +592,10 @@ pub fn filter_chains(
) -> Filters { ) -> Filters {
let mut filters = Filters::new(config.clone(), 0); let mut filters = Filters::new(config.clone(), 0);
if node.source.contains("color=c=") {
filters.audio_position = 1;
}
if node.unit == Encoder { if node.unit == Encoder {
if !config.processing.audio_only { if !config.processing.audio_only {
add_text(node, &mut filters, config, filter_chain); add_text(node, &mut filters, config, filter_chain);
@ -672,13 +676,11 @@ pub fn filter_chains(
|| Path::new(&node.audio).is_file() || Path::new(&node.audio).is_file()
{ {
extend_audio(node, &mut filters, i, config); extend_audio(node, &mut filters, i, config);
} else if node.unit == Decoder { } else if node.unit == Decoder && !node.source.contains("color=c=") {
if !node.source.contains("color=c=") {
warn!(target: Target::file_mail(), channel = config.general.channel_id; warn!(target: Target::file_mail(), channel = config.general.channel_id;
"Missing audio track (id {i}) from <b><magenta>{}</></b>", "Missing audio track (id {i}) from <b><magenta>{}</></b>",
node.source node.source
); );
}
add_audio(node, &mut filters, i, config); add_audio(node, &mut filters, i, config);
} }

View File

@ -1,7 +1,6 @@
use std::{ use std::{
io::{stdin, stdout, Write}, io::{stdin, stdout, Write},
path::PathBuf, path::PathBuf,
process::exit,
}; };
use clap::Parser; use clap::Parser;
@ -9,7 +8,7 @@ use rpassword::read_password;
use sqlx::{Pool, Sqlite}; use sqlx::{Pool, Sqlite};
use crate::db::{ use crate::db::{
handles::{self, insert_user}, handles,
models::{Channel, GlobalSettings, User}, models::{Channel, GlobalSettings, User},
}; };
use crate::utils::{ use crate::utils::{
@ -112,13 +111,13 @@ pub struct Args {
pub log_to_console: bool, pub log_to_console: bool,
#[clap(long, env, help = "HLS output path")] #[clap(long, env, help = "HLS output path")]
pub hls_path: Option<PathBuf>, pub hls_path: Option<String>,
#[clap(long, env, help = "Playlist root path")] #[clap(long, env, help = "Playlist root path")]
pub playlist_path: Option<PathBuf>, pub playlist_path: Option<String>,
#[clap(long, env, help = "Storage root path")] #[clap(long, env, help = "Storage root path")]
pub storage_path: Option<PathBuf>, pub storage_path: Option<String>,
#[clap(long, env, help = "Share storage across channels")] #[clap(long, env, help = "Share storage across channels")]
pub shared_storage: bool, pub shared_storage: bool,
@ -188,9 +187,20 @@ fn global_user(args: &mut Args) {
} }
pub async fn run_args(pool: &Pool<Sqlite>) -> Result<(), i32> { pub async fn run_args(pool: &Pool<Sqlite>) -> Result<(), i32> {
let channels = handles::select_related_channels(pool, None).await;
let mut args = ARGS.clone(); let mut args = ARGS.clone();
if args.dump_advanced.is_none() && args.dump_config.is_none() {
if let Err(e) = handles::db_migrate(pool).await {
panic!("{e}");
};
}
let channels = handles::select_related_channels(pool, None)
.await
.unwrap_or(vec![Channel::default()]);
let mut error_code = -1;
if args.init { if args.init {
let check_user = handles::select_users(pool).await; let check_user = handles::select_users(pool).await;
@ -288,7 +298,7 @@ pub async fn run_args(pool: &Pool<Sqlite>) -> Result<(), i32> {
if let Err(e) = handles::update_global(pool, global.clone()).await { if let Err(e) = handles::update_global(pool, global.clone()).await {
eprintln!("{e}"); eprintln!("{e}");
return Err(1); error_code = 1;
}; };
if !global.shared_storage { if !global.shared_storage {
@ -306,40 +316,60 @@ pub async fn run_args(pool: &Pool<Sqlite>) -> Result<(), i32> {
} }
if let Some(username) = args.username { if let Some(username) = args.username {
error_code = 0;
if args.mail.is_none() || args.password.is_none() { if args.mail.is_none() || args.password.is_none() {
eprintln!("Mail/password missing!"); eprintln!("Mail/password missing!");
return Err(1); error_code = 1;
} }
let chl: Vec<i32> = channels.clone().iter().map(|c| c.id).collect();
let user = User { let user = User {
id: 0, id: 0,
mail: Some(args.mail.unwrap()), mail: Some(args.mail.unwrap()),
username: username.clone(), username: username.clone(),
password: args.password.unwrap(), password: args.password.unwrap(),
role_id: Some(1), role_id: Some(1),
channel_ids: Some( channel_ids: Some(chl.clone()),
channels
.unwrap_or(vec![Channel::default()])
.iter()
.map(|c| c.id)
.collect(),
),
token: None, token: None,
}; };
if let Err(e) = insert_user(pool, user).await { if let Err(e) = handles::insert_user(pool, user).await {
eprintln!("{e}"); eprintln!("{e}");
return Err(1); error_code = 1;
}; };
println!("Create global admin user \"{username}\" done..."); println!("Create global admin user \"{username}\" done...");
}
return Err(0); if !args.init
&& args.storage_path.is_some()
&& args.playlist_path.is_some()
&& args.hls_path.is_some()
&& args.log_path.is_some()
{
error_code = 0;
let global = GlobalSettings {
id: 0,
secret: None,
hls_path: args.hls_path.unwrap(),
playlist_path: args.playlist_path.unwrap(),
storage_path: args.storage_path.unwrap(),
logging_path: args.log_path.unwrap().to_string_lossy().to_string(),
shared_storage: args.shared_storage,
};
if let Err(e) = handles::update_global(pool, global.clone()).await {
eprintln!("{e}");
error_code = 1;
} else {
println!("Update global paths...");
};
} }
if ARGS.list_channels { if ARGS.list_channels {
match channels {
Ok(channels) => {
let chl = channels let chl = channels
.iter() .iter()
.map(|c| (c.id, c.name.clone())) .map(|c| (c.id, c.name.clone()))
@ -353,26 +383,18 @@ pub async fn run_args(pool: &Pool<Sqlite>) -> Result<(), i32> {
.join("\n") .join("\n")
); );
return Err(0); error_code = 0;
}
Err(e) => {
eprintln!("List channels: {e}");
exit(1);
}
}
} }
if let Some(id) = ARGS.dump_config { if let Some(id) = ARGS.dump_config {
match PlayoutConfig::dump(pool, id).await { match PlayoutConfig::dump(pool, id).await {
Ok(_) => { Ok(_) => {
println!("Dump config to: ffplayout_{id}.toml"); println!("Dump config to: ffplayout_{id}.toml");
exit(0); error_code = 0;
} }
Err(e) => { Err(e) => {
eprintln!("Dump config: {e}"); eprintln!("Dump config: {e}");
error_code = 1;
exit(1);
} }
}; };
} }
@ -381,12 +403,11 @@ pub async fn run_args(pool: &Pool<Sqlite>) -> Result<(), i32> {
match PlayoutConfig::dump(pool, id).await { match PlayoutConfig::dump(pool, id).await {
Ok(_) => { Ok(_) => {
println!("Dump config to: ffplayout_{id}.toml"); println!("Dump config to: ffplayout_{id}.toml");
exit(0); error_code = 0;
} }
Err(e) => { Err(e) => {
eprintln!("Dump config: {e}"); eprintln!("Dump config: {e}");
error_code = 1;
exit(1);
} }
}; };
} }
@ -395,12 +416,11 @@ pub async fn run_args(pool: &Pool<Sqlite>) -> Result<(), i32> {
match AdvancedConfig::dump(pool, id).await { match AdvancedConfig::dump(pool, id).await {
Ok(_) => { Ok(_) => {
println!("Dump config to: advanced_{id}.toml"); println!("Dump config to: advanced_{id}.toml");
exit(0); error_code = 0;
} }
Err(e) => { Err(e) => {
eprintln!("Dump config: {e}"); eprintln!("Dump config: {e}");
error_code = 1;
exit(1);
} }
}; };
} }
@ -409,12 +429,11 @@ pub async fn run_args(pool: &Pool<Sqlite>) -> Result<(), i32> {
match PlayoutConfig::import(pool, import.clone()).await { match PlayoutConfig::import(pool, import.clone()).await {
Ok(_) => { Ok(_) => {
println!("Import config done..."); println!("Import config done...");
exit(0); error_code = 0;
} }
Err(e) => { Err(e) => {
eprintln!("{e}"); eprintln!("{e}");
error_code = 1;
exit(1);
} }
}; };
} }
@ -423,15 +442,18 @@ pub async fn run_args(pool: &Pool<Sqlite>) -> Result<(), i32> {
match AdvancedConfig::import(pool, import.clone()).await { match AdvancedConfig::import(pool, import.clone()).await {
Ok(_) => { Ok(_) => {
println!("Import config done..."); println!("Import config done...");
exit(0); error_code = 0;
} }
Err(e) => { Err(e) => {
eprintln!("{e}"); eprintln!("{e}");
error_code = 1;
exit(1);
} }
}; };
} }
if error_code > -1 {
Err(error_code)
} else {
Ok(()) Ok(())
} }
}

View File

@ -1,4 +1,5 @@
use std::{ use std::{
ffi::OsStr,
io, io,
path::Path, path::Path,
sync::{Arc, Mutex}, sync::{Arc, Mutex},
@ -33,7 +34,18 @@ fn preview_url(url: &str, id: i32) -> String {
if let Some(parent) = url_path.parent() { if let Some(parent) = url_path.parent() {
if let Some(filename) = url_path.file_name() { if let Some(filename) = url_path.file_name() {
let new_path = parent.join(id.to_string()).join(filename); let new_path = if parent
.file_name()
.unwrap_or_else(|| OsStr::new("0"))
.to_string_lossy()
.to_string()
.parse::<i32>()
.is_ok()
{
parent.join(filename)
} else {
parent.join(id.to_string()).join(filename)
};
if let Some(new_url) = new_path.to_str() { if let Some(new_url) = new_path.to_str() {
return new_url.to_string(); return new_url.to_string();
@ -55,7 +67,7 @@ pub async fn create_channel(
handles::update_channel(conn, channel.id, channel.clone()).await?; handles::update_channel(conn, channel.id, channel.clone()).await?;
let output_param = format!("-c:v libx264 -crf 23 -x264-params keyint=50:min-keyint=25:scenecut=-1 -maxrate 1300k -bufsize 2600k -preset faster -tune zerolatency -profile:v Main -level 3.1 -c:a aac -ar 44100 -b:a 128k -flags +cgop -f hls -hls_time 6 -hls_list_size 600 -hls_flags append_list+delete_segments+omit_endlist -hls_segment_filename {0}/stream-%d.ts {0}/stream.m3u8", channel.id); let output_param = "-c:v libx264 -crf 23 -x264-params keyint=50:min-keyint=25:scenecut=-1 -maxrate 1300k -bufsize 2600k -preset faster -tune zerolatency -profile:v Main -level 3.1 -c:a aac -ar 44100 -b:a 128k -flags +cgop -f hls -hls_time 6 -hls_list_size 600 -hls_flags append_list+delete_segments+omit_endlist -hls_segment_filename live/stream-%d.ts live/stream.m3u8".to_string();
handles::insert_advanced_configuration(conn, channel.id).await?; handles::insert_advanced_configuration(conn, channel.id).await?;
handles::insert_configuration(conn, channel.id, output_param).await?; handles::insert_configuration(conn, channel.id, output_param).await?;

View File

@ -590,6 +590,12 @@ impl PlayoutConfig {
.expect("Can't create playlist folder"); .expect("Can't create playlist folder");
} }
if !global.logging_path.is_dir() {
tokio::fs::create_dir_all(&global.logging_path)
.await
.expect("Can't create logging folder");
}
let (filler_path, _, _) = norm_abs_path(&global.storage_path, &config.storage_filler) let (filler_path, _, _) = norm_abs_path(&global.storage_path, &config.storage_filler)
.expect("Can't get filler path"); .expect("Can't get filler path");

View File

@ -156,13 +156,17 @@ impl fmt::Display for TextFilter {
pub fn db_path() -> Result<&'static str, Box<dyn std::error::Error>> { pub fn db_path() -> Result<&'static str, Box<dyn std::error::Error>> {
if let Some(path) = ARGS.db.clone() { if let Some(path) = ARGS.db.clone() {
let absolute_path = if path.is_absolute() { let mut absolute_path = if path.is_absolute() {
path path
} else { } else {
env::current_dir()?.join(path) env::current_dir()?.join(path)
} }
.clean(); .clean();
if absolute_path.is_dir() {
absolute_path = absolute_path.join("ffplayout.db");
}
if let Some(abs_path) = absolute_path.parent() { if let Some(abs_path) = absolute_path.parent() {
if abs_path.writable() { if abs_path.writable() {
return Ok(Box::leak( return Ok(Box::leak(

@ -1 +1 @@
Subproject commit e8fd6f65bf255c55c1ca509f9fe59c2c7875c394 Subproject commit 18518dd53acb2b78c2bf7f3ac199f038fc225fd9