implement basic video streaming pipeline
This commit is contained in:
46
def/envsink8s
Normal file
46
def/envsink8s
Normal file
@@ -0,0 +1,46 @@
|
||||
You're absolutely right! In Kubernetes, environment variables are handled at the deployment level through ConfigMaps and Secrets, not
|
||||
individual service .env files.
|
||||
|
||||
Kubernetes approach:
|
||||
# k8s/configmap.yaml
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: media-analyzer-config
|
||||
data:
|
||||
DB_HOST: "postgres-service"
|
||||
HLS_BASE_URL: "http://nginx-hls-service"
|
||||
|
||||
# k8s/deployment.yaml
|
||||
env:
|
||||
- name: DB_HOST
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: media-analyzer-config
|
||||
key: DB_HOST
|
||||
|
||||
Better structure:
|
||||
- Development: Single .env for docker-compose
|
||||
- Production: K8s ConfigMaps/Secrets per environment
|
||||
- No service-specific .env files
|
||||
|
||||
Recommended approach:
|
||||
|
||||
● Write(.env.development)
|
||||
⎿ Wrote 8 lines to .env.development
|
||||
# Development environment variables for docker-compose
|
||||
DB_HOST=postgres
|
||||
DB_NAME=media_analyzer
|
||||
DB_USER=media_user
|
||||
DB_PASSWORD=media_pass
|
||||
RTMP_PORT=1935
|
||||
HLS_BASE_URL=http://localhost:8081
|
||||
DEBUG=1
|
||||
|
||||
● Then K8s handles it via:
|
||||
- k8s/base/configmap.yaml - Non-secret config
|
||||
- k8s/base/secret.yaml - Passwords, keys
|
||||
- k8s/overlays/staging/ - Staging overrides
|
||||
- k8s/overlays/production/ - Production overrides
|
||||
|
||||
This way each deployment environment controls its own config, not the services themselves.
|
||||
37
def/how-to-test
Normal file
37
def/how-to-test
Normal file
@@ -0,0 +1,37 @@
|
||||
1. Start the stack:
|
||||
# Start Docker services
|
||||
docker compose --env-file .env.development up -d
|
||||
|
||||
# Start Django backend (in separate terminal)
|
||||
cd backend && python manage.py runserver
|
||||
|
||||
# Start Angular frontend (in separate terminal)
|
||||
cd frontend && ng serve
|
||||
|
||||
2. Test the API:
|
||||
# Check if Django API works
|
||||
curl http://localhost:8000/api/streams/
|
||||
|
||||
# Create a test stream
|
||||
curl -X POST http://localhost:8000/api/streams/create/ \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"name": "Test Stream"}'
|
||||
|
||||
3. Test with OBS:
|
||||
1. Open OBS Studio
|
||||
2. Go to Settings → Stream
|
||||
3. Set:
|
||||
- Service: Custom
|
||||
- Server: rtmp://localhost:1935/live
|
||||
- Stream Key: (Copy from API response or frontend)
|
||||
4. Start streaming in OBS
|
||||
|
||||
4. Test video playback:
|
||||
1. Open http://localhost:4200
|
||||
2. Create a stream in the frontend
|
||||
3. Copy the RTMP URL to OBS
|
||||
4. Start the stream
|
||||
5. Click "View" to watch the HLS stream
|
||||
|
||||
Expected flow:
|
||||
OBS → RTMP (port 1935) → NGINX-RTMP → HLS segments → Angular player
|
||||
38
def/whyclaudewhy
Normal file
38
def/whyclaudewhy
Normal file
@@ -0,0 +1,38 @@
|
||||
media-analyzer/backend/media_analyzer/urls.py
|
||||
why MEDIA_ROOT just in debug
|
||||
|
||||
this to store media files which is obvious not ideal to store in the db (at least on postgres)
|
||||
|
||||
|
||||
nginx
|
||||
why add cors straigth in nginx conf
|
||||
|
||||
|
||||
> is it correct to have cors configuration in nginx?
|
||||
|
||||
● Yes and No - it depends on the service responsibility:
|
||||
|
||||
NGINX CORS is correct when:
|
||||
- NGINX serves static media files (HLS videos)
|
||||
- Browser needs to access video files cross-origin
|
||||
- NGINX is the media server
|
||||
|
||||
Django CORS is correct when:
|
||||
- Django serves API endpoints
|
||||
- Angular makes API calls cross-origin
|
||||
- Django is the application server
|
||||
|
||||
Your current setup needs BOTH:
|
||||
- Django CORS: For Angular → Django API calls (/api/streams/)
|
||||
- NGINX CORS: For Angular → NGINX media requests (/playlist.m3u8, /segment.ts)
|
||||
|
||||
Separation of concerns:
|
||||
Angular (4200) → Django (8000) # API calls - Django CORS
|
||||
Angular (4200) → NGINX (8081) # Video files - NGINX CORS
|
||||
|
||||
In production/K8s, you'd typically:
|
||||
- Have one ingress controller handle all CORS
|
||||
- Or use service mesh (Istio) for cross-origin policies
|
||||
|
||||
But for development, having CORS in both services is correct because they serve different content types to the browser.
|
||||
|
||||
Reference in New Issue
Block a user