diff --git a/Dockerfile b/Dockerfile index d7fdee4..28390e3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -49,16 +49,18 @@ RUN pip install --no-cache-dir --upgrade pip && \ RUN groupadd -g ${GROUP_ID} ${APP_USER} && \ useradd -u ${USER_ID} -g ${APP_USER} -m -s /bin/bash ${APP_USER} -# Create directories for new structure -RUN mkdir -p /config /logs /cache /drm-plugins /playlists /scripts /app/routes /app/lib && \ - chown -R ${USER_ID}:${GROUP_ID} /config /logs /cache /drm-plugins /playlists /scripts /app/routes /app/lib +# Create directories for new structure (including routes/streams) +RUN mkdir -p /config /logs /cache /drm-plugins /playlists /scripts && \ + mkdir -p /app/routes /app/routes/streams /app/lib && \ + chown -R ${USER_ID}:${GROUP_ID} /config /logs /cache /drm-plugins /playlists /scripts /app # CRITICAL FIX: Copy the lib directory containing streaming_providers COPY --chown=${USER_ID}:${GROUP_ID} lib/ /app/lib/ # Copy application code with new structure COPY --chown=${USER_ID}:${GROUP_ID} service.py . -# Copy the entire routes directory + +# Copy the entire routes directory (including streams subdirectory) COPY --chown=${USER_ID}:${GROUP_ID} routes/ /app/routes/ # Copy resources directory (for web UI) @@ -72,13 +74,27 @@ RUN mkdir -p /app/lib/streaming_providers/base/drm/plugins && \ RUN echo "=== Directory structure ===" && \ ls -la /app && \ echo "--- routes ---" && \ - ls -la /app/routes/ 2>/dev/null || echo "routes directory not found" && \ + ls -la /app/routes/ 2>/dev/null || echo "ERROR: routes directory not found" && \ + echo "--- routes/streams ---" && \ + ls -la /app/routes/streams/ 2>/dev/null || echo "ERROR: routes/streams directory not found" && \ echo "--- lib ---" && \ - ls -la /app/lib/ 2>/dev/null || echo "lib directory not found" && \ + ls -la /app/lib/ 2>/dev/null || echo "ERROR: lib directory not found" && \ echo "--- streaming_providers ---" && \ - ls -la /app/lib/streaming_providers/ 2>/dev/null || echo "streaming_providers not found" + ls -la /app/lib/streaming_providers/ 2>/dev/null || echo "ERROR: streaming_providers not found" -# Copy updated entrypoint script +# Validate critical split structure files exist +RUN echo "=== Validating split structure ===" && \ + test -f /app/routes/__init__.py && echo "✓ routes/__init__.py" || (echo "✗ MISSING: routes/__init__.py" && exit 1) && \ + test -f /app/routes/streams/__init__.py && echo "✓ routes/streams/__init__.py" || (echo "✗ MISSING: routes/streams/__init__.py" && exit 1) && \ + test -f /app/routes/streams/channels.py && echo "✓ routes/streams/channels.py" || (echo "✗ MISSING: routes/streams/channels.py" && exit 1) && \ + test -f /app/routes/streams/events.py && echo "✓ routes/streams/events.py" || (echo "✗ MISSING: routes/streams/events.py" && exit 1) && \ + test -f /app/routes/streams/vod.py && echo "✓ routes/streams/vod.py" || (echo "✗ MISSING: routes/streams/vod.py" && exit 1) && \ + test -f /app/routes/streams/recordings.py && echo "✓ routes/streams/recordings.py" || (echo "✗ MISSING: routes/streams/recordings.py" && exit 1) && \ + test -f /app/routes/streams/epg.py && echo "✓ routes/streams/epg.py" || (echo "✗ MISSING: routes/streams/epg.py" && exit 1) && \ + test -f /app/service.py && echo "✓ service.py" || (echo "✗ MISSING: service.py" && exit 1) && \ + echo "✓ All split structure files validated successfully!" + +# Copy entrypoint script COPY docker-entrypoint.sh /usr/local/bin/ RUN chmod +x /usr/local/bin/docker-entrypoint.sh @@ -99,7 +115,8 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \ # Labels LABEL maintainer="nirvana-7777" \ - description="Ultimate Backend Streaming Service" + description="Ultimate Backend Streaming Service with split route modules" \ + version="2.0" # Entrypoint with wrapper script ENTRYPOINT ["docker-entrypoint.sh"] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index dbde7e2..234a813 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -19,33 +19,71 @@ if [ -z "$(ls -A /drm-plugins)" ] && [ -d "/app/lib/streaming_providers/base/drm cp -r /app/lib/streaming_providers/base/drm/default-plugins/* /drm-plugins/ fi -# IMPORTANT: Ensure routes directory exists and has required files -# This is needed for the new split structure +# IMPORTANT: Verify the new split routes structure +# The routes are now split across: +# - routes/*.py (top-level route files) +# - routes/streams/*.py (split stream modules) + if [ ! -d "/app/routes" ]; then echo "ERROR: routes directory not found!" echo "The service has been split into modules. Make sure routes/ directory exists in /app/" exit 1 fi -# Verify all required route files exist -REQUIRED_ROUTES=("__init__.py" "providers.py" "streams.py" "m3u.py" "drm.py" "cache.py" "config.py" "epg.py") +# Verify all required top-level route files exist +REQUIRED_TOP_ROUTES=("__init__.py" "providers.py" "m3u.py" "drm.py" "cache.py" "config.py" "epg.py" "events.py" "vod.py" "recordings.py" "timers.py" "bookmarks.py" "favorites.py") MISSING_FILES=0 -for route in "${REQUIRED_ROUTES[@]}"; do +for route in "${REQUIRED_TOP_ROUTES[@]}"; do if [ ! -f "/app/routes/$route" ]; then echo "ERROR: Missing required route file: /app/routes/$route" MISSING_FILES=$((MISSING_FILES + 1)) fi done +# Verify the streams subdirectory exists +if [ ! -d "/app/routes/streams" ]; then + echo "ERROR: Missing routes/streams directory! This is required for the split stream modules." + MISSING_FILES=$((MISSING_FILES + 1)) +else + # Verify all required stream module files exist + REQUIRED_STREAM_MODULES=("__init__.py" "channels.py" "events.py" "vod.py" "recordings.py" "epg.py") + for module in "${REQUIRED_STREAM_MODULES[@]}"; do + if [ ! -f "/app/routes/streams/$module" ]; then + echo "ERROR: Missing required stream module: /app/routes/streams/$module" + MISSING_FILES=$((MISSING_FILES + 1)) + fi + done +fi + if [ $MISSING_FILES -gt 0 ]; then - echo "ERROR: Missing $MISSING_FILES required route files. Service cannot start." + echo "ERROR: Missing $MISSING_FILES required route files/modules. Service cannot start." exit 1 fi -# Set Python path to include routes directory +# Set Python path to include app directory (for absolute imports) export PYTHONPATH="${PYTHONPATH}:/app" +# Verify Python can import the routes module +echo "Testing Python imports..." +python3 -c " +import sys +sys.path.insert(0, '/app') +try: + from routes.streams import setup_stream_routes + print('✓ routes.streams module loaded successfully') +except ImportError as e: + print(f'✗ Failed to import routes.streams: {e}') + sys.exit(1) +try: + from routes import providers, m3u, drm, cache, config, epg, events, vod, recordings, timers, bookmarks, favorites + print('✓ All top-level route modules loaded successfully') +except ImportError as e: + print(f'✗ Failed to import top-level route modules: {e}') + sys.exit(1) +print('All imports successful!') +" || exit 1 + echo "Routes directory check passed. Starting service..." # Execute the main command