dockerized
This commit is contained in:
parent
ba65b1cc9d
commit
5621d3531f
21
dockerfile
Normal file
21
dockerfile
Normal file
@ -0,0 +1,21 @@
|
||||
FROM python:3.12-slim
|
||||
|
||||
# Install ffmpeg (needed for your script)
|
||||
RUN apt-get update && \
|
||||
apt-get install -y ffmpeg && \
|
||||
apt-get clean && rm -rf /var/lib/apt/lists/*
|
||||
RUN pip install watchdog
|
||||
|
||||
# Set working directory inside container
|
||||
WORKDIR /app
|
||||
|
||||
# Copy your script
|
||||
COPY main.py /app/main.py
|
||||
|
||||
# Install any Python dependencies if needed
|
||||
# RUN pip install -r requirements.txt
|
||||
|
||||
# Copy watchdog script (or create inside Docker)
|
||||
COPY watcher.py /app/watcher.py
|
||||
|
||||
CMD ["python3", "watcher.py"]
|
||||
29
watcher.py
Normal file
29
watcher.py
Normal file
@ -0,0 +1,29 @@
|
||||
import os
|
||||
import subprocess
|
||||
import time
|
||||
from watchdog.observers import Observer
|
||||
from watchdog.events import FileSystemEventHandler
|
||||
|
||||
WATCH_DIR = "/data" # Mount your host directory here
|
||||
|
||||
class NewBookHandler(FileSystemEventHandler):
|
||||
def on_created(self, event):
|
||||
if event.is_directory:
|
||||
book_dir = event.src_path
|
||||
print(f"New directory detected: {book_dir}")
|
||||
# Run your main.py with the new book directory
|
||||
subprocess.run(["python3", "main.py", "-da", book_dir], check=True)
|
||||
|
||||
if __name__ == "__main__":
|
||||
observer = Observer()
|
||||
event_handler = NewBookHandler()
|
||||
observer.schedule(event_handler, WATCH_DIR, recursive=True)
|
||||
observer.start()
|
||||
print(f"Watching for new folders in {WATCH_DIR} ...")
|
||||
|
||||
try:
|
||||
while True:
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
observer.stop()
|
||||
observer.join()
|
||||
Loading…
x
Reference in New Issue
Block a user