mirror of
https://github.com/MichaByte/OnBoard-Live.git
synced 2025-12-06 04:43:41 -05:00
more WIP docker stuff
This commit is contained in:
parent
e75f8c944a
commit
8747a8ffe3
7 changed files with 44 additions and 15 deletions
|
|
@ -2,6 +2,8 @@ FROM python:3.12-alpine
|
||||||
|
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
|
RUN apk add --no-cache ffmpeg
|
||||||
|
|
||||||
COPY requirements.txt ./
|
COPY requirements.txt ./
|
||||||
|
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,25 @@ import subprocess
|
||||||
import time
|
import time
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
active_stream = requests.get("http://backend:8000/api/v1/active_stream").text
|
active_stream = requests.get("http://backend:8000/api/v1/active_stream").text
|
||||||
|
print(active_stream)
|
||||||
|
|
||||||
old_active_stream = active_stream
|
old_active_stream = active_stream
|
||||||
|
|
||||||
proc = None
|
proc = None
|
||||||
|
|
||||||
|
if active_stream != "":
|
||||||
|
proc = subprocess.Popen(["/bin/ffmpeg", "-re", "-i", f"rtmp://mediamtx:1935/{active_stream}", "-c:a copy", "rtmp://host.containers.internal:1936/active-input"])
|
||||||
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
proc = subprocess.Popen([f"ffmpeg -re -i rtmp://mediamtx:1935/{active_stream} -c:a copy rtmp://host.containers.internal:1936/active-input"], shell=True)
|
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
active_stream = requests.get("http://backend:8000/api/v1/active_stream").text
|
active_stream = requests.get("http://backend:8000/api/v1/active_stream").text
|
||||||
if old_active_stream is not active_stream:
|
if old_active_stream is not active_stream:
|
||||||
proc.terminate()
|
if proc:
|
||||||
proc = subprocess.Popen([f"ffmpeg -re -i rtmp://mediamtx:1935/{active_stream} -c:a copy rtmp://host.containers.internal:1936/active-input"], shell=True)
|
proc.terminate()
|
||||||
|
print("e")
|
||||||
|
proc = subprocess.Popen(["/bin/ffmpeg", "-re", "-i", f"rtmp://mediamtx:1935/{active_stream}", "-c:a copy", "rtmp://host.containers.internal:1936/active-input"])
|
||||||
old_active_stream = active_stream
|
old_active_stream = active_stream
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,12 @@ RUN apt-get install -y python3-opencv
|
||||||
|
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
COPY main.py schema.prisma .
|
COPY schema.prisma .
|
||||||
|
|
||||||
COPY migrations .
|
ADD migrations .
|
||||||
|
|
||||||
RUN prisma generate
|
RUN prisma generate
|
||||||
|
|
||||||
|
COPY main.py .
|
||||||
|
|
||||||
CMD [ "fastapi", "run", "main.py" ]
|
CMD [ "fastapi", "run", "main.py" ]
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ from contextlib import asynccontextmanager
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from secrets import choice, token_hex
|
from secrets import choice, token_hex
|
||||||
from typing import Dict, List
|
from typing import Dict, List
|
||||||
|
import time
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
import httpx
|
import httpx
|
||||||
|
|
@ -151,12 +152,6 @@ async def check_for_new():
|
||||||
|
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
async def lifespan(app: FastAPI):
|
async def lifespan(app: FastAPI):
|
||||||
await update_active()
|
|
||||||
scheduler.start()
|
|
||||||
scheduler.add_job(update_active, IntervalTrigger(minutes=5))
|
|
||||||
scheduler.add_job(check_for_new, IntervalTrigger(seconds=3))
|
|
||||||
scheduler.add_job(rotate_fernet_key, IntervalTrigger(minutes=30))
|
|
||||||
await rotate_fernet_key()
|
|
||||||
await db.connect()
|
await db.connect()
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
for stream in await db.stream.find_many():
|
for stream in await db.stream.find_many():
|
||||||
|
|
@ -164,6 +159,11 @@ async def lifespan(app: FastAPI):
|
||||||
f"http://{os.environ['MEDIAMTX_IP']}:9997/v3/config/paths/add/" + stream.key,
|
f"http://{os.environ['MEDIAMTX_IP']}:9997/v3/config/paths/add/" + stream.key,
|
||||||
json={"name": stream.key},
|
json={"name": stream.key},
|
||||||
)
|
)
|
||||||
|
scheduler.start()
|
||||||
|
scheduler.add_job(update_active, IntervalTrigger(minutes=5))
|
||||||
|
scheduler.add_job(check_for_new, IntervalTrigger(seconds=3))
|
||||||
|
scheduler.add_job(rotate_fernet_key, IntervalTrigger(minutes=30))
|
||||||
|
await rotate_fernet_key()
|
||||||
yield
|
yield
|
||||||
scheduler.shutdown()
|
scheduler.shutdown()
|
||||||
await db.disconnect()
|
await db.disconnect()
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ generator client {
|
||||||
}
|
}
|
||||||
|
|
||||||
datasource db {
|
datasource db {
|
||||||
provider = "postgresql"
|
provider = "sqlite"
|
||||||
url = "file:./db/dev.db"
|
url = "file:./db/dev.db"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
services:
|
services:
|
||||||
mediamtx:
|
mediamtx:
|
||||||
network_mode: host
|
|
||||||
build:
|
build:
|
||||||
context: ./mediamtx
|
context: ./mediamtx
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
|
ports:
|
||||||
|
- "8889:8889"
|
||||||
|
- "1935:1935"
|
||||||
|
- "9997:9997"
|
||||||
web-frontend:
|
web-frontend:
|
||||||
build:
|
build:
|
||||||
context: ./tiling-frontend
|
context: ./tiling-frontend
|
||||||
|
|
@ -12,8 +15,8 @@ services:
|
||||||
- tiling_frontend_build:/usr/src/app/dist
|
- tiling_frontend_build:/usr/src/app/dist
|
||||||
live-stream:
|
live-stream:
|
||||||
depends_on:
|
depends_on:
|
||||||
web-frontend:
|
active_stream_proxy:
|
||||||
condition: service_completed_successfully
|
condition: service_started
|
||||||
build:
|
build:
|
||||||
context: ./live-stream
|
context: ./live-stream
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
|
|
@ -23,6 +26,8 @@ services:
|
||||||
YT_STREAM_KEY: ${YT_STREAM_KEY}
|
YT_STREAM_KEY: ${YT_STREAM_KEY}
|
||||||
backend:
|
backend:
|
||||||
env_file: .backend.env
|
env_file: .backend.env
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
build:
|
build:
|
||||||
context: ./backend
|
context: ./backend
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
|
|
@ -37,6 +42,8 @@ services:
|
||||||
condition: service_completed_successfully
|
condition: service_completed_successfully
|
||||||
mediamtx:
|
mediamtx:
|
||||||
condition: service_started
|
condition: service_started
|
||||||
|
backend:
|
||||||
|
condition: service_started
|
||||||
volumes:
|
volumes:
|
||||||
mediamtx_recordings:
|
mediamtx_recordings:
|
||||||
tiling_frontend_build:
|
tiling_frontend_build:
|
||||||
|
|
|
||||||
|
|
@ -11,3 +11,12 @@ pathDefaults:
|
||||||
recordDeleteAfter: 0s
|
recordDeleteAfter: 0s
|
||||||
webrtcICEServers2:
|
webrtcICEServers2:
|
||||||
- url: stun:stun.l.google.com:19302
|
- url: stun:stun.l.google.com:19302
|
||||||
|
authInternalUsers:
|
||||||
|
# Username. 'any' means any user, including anonymous ones.
|
||||||
|
- user: any
|
||||||
|
# Password. Not used in case of 'any' user.
|
||||||
|
pass:
|
||||||
|
# IPs or networks allowed to use this user. An empty list means any IP.
|
||||||
|
ips: []
|
||||||
|
permissions:
|
||||||
|
- action: api
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue