diff --git a/.vscode/settings.json b/.vscode/settings.json index 28daddc..6a5ed78 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,6 +9,7 @@ "README": "plaintext", "*.mako": "python", "*.conf": "ini", + "*.rdb": "sql", }, "files.insertFinalNewline": true, "editor.formatOnSave": true, diff --git a/bereal/server.py b/bereal/server.py index 58c0545..3f0a56c 100644 --- a/bereal/server.py +++ b/bereal/server.py @@ -57,9 +57,6 @@ logger.info("Running in %s mode", FLASK_ENV) -logger.info("CONTENT_PATH: %s", CONTENT_PATH) -logger.info("EXPORTS_PATH: %s", EXPORTS_PATH) - if FLASK_ENV == "development": logger.info("Enabling CORS for development") CORS(app) diff --git a/bereal/utils.py b/bereal/utils.py index 80e6cb2..132ae42 100644 --- a/bereal/utils.py +++ b/bereal/utils.py @@ -9,7 +9,6 @@ from dotenv import load_dotenv -from .logger import logger # Environment variables load_dotenv() @@ -98,9 +97,6 @@ def str2mode(s: str | None) -> Mode: REDIS_PORT: str | None = os.getenv("REDIS_PORT") or config.get("bereal", "redis_port", fallback="6379") REDIS_PORT = int(REDIS_PORT) if REDIS_PORT is not None else None -logger.info(f"REDIS_HOST: {REDIS_HOST}") -logger.info(f"REDIS_PORT: {REDIS_PORT}") - TIMEOUT = config.getint("bereal", "timeout", fallback=10) IMAGE_QUALITY = config.getint("bereal", "image_quality", fallback=50) diff --git a/bereal/videos.py b/bereal/videos.py index 3e4fb19..f9de185 100644 --- a/bereal/videos.py +++ b/bereal/videos.py @@ -195,7 +195,7 @@ def create_slideshow2( ] ) - logger.info("Padded %d images with %d timestamps...", len(image_paths), len(timestamps)) + logger.info("Have %d images with %d timestamps...", len(image_paths), len(timestamps)) if len(timestamps) < len(image_paths): additional_needed = len(image_paths) - len(timestamps) @@ -304,8 +304,8 @@ def create_slideshow3( music = AudioFileClip(music_file) if music.duration < main_clip.duration: - # TODO(michaelfromyeg): implement silence padding! (or maybe repeat clip...) - raise NotImplementedError("Music is shorter than final clip, not supported") + logger.warning("Music is shorter than final clip; looping music") + music = music.fx(vfx.loop, duration=main_clip.duration) else: logger.info("Music is longer than final clip; clipping appropriately") music = music.subclip(0, main_clip.duration) diff --git a/docker-compose.yml b/docker-compose.yml index 7695888..ec36eda 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -44,6 +44,7 @@ services: - "443:443" volumes: - ./nginx:/etc/nginx/conf.d + - ./nginx/robots.txt:/usr/share/nginx/html/robots.txt - /etc/letsencrypt:/etc/letsencrypt depends_on: - web diff --git a/docker/Dockerfile.celery b/docker/Dockerfile.celery index 2b14c05..327c770 100644 --- a/docker/Dockerfile.celery +++ b/docker/Dockerfile.celery @@ -1,16 +1,16 @@ -FROM python:3.11 +FROM python:3.11-slim WORKDIR /app -COPY . /app +COPY . . -RUN pip install --upgrade pip -RUN pip install --no-cache-dir -r requirements/prod.txt +RUN pip install --upgrade pip && \ + pip install --no-cache-dir -r requirements/prod.txt && \ + adduser --disabled-password --gecos '' thekid && \ + chown -R thekid:thekid /app -ENV FLASK_APP=bereal.server - -RUN adduser --disabled-password --gecos '' thekid -RUN chown -R thekid:thekid /app && chmod -R 777 /app USER thekid -CMD ["celery", "-A", "bereal.celery worker", "--loglevel=INFO", "--logfile=celery.log", "-E", "-c", "1"] +ENV FLASK_APP=bereal.server + +CMD ["celery", "-A", "bereal.celery", "worker", "--loglevel=INFO", "--logfile=celery.log", "-E", "-c", "1"] diff --git a/docker/Dockerfile.cli b/docker/Dockerfile.cli index 8a88fe7..41f8a70 100644 --- a/docker/Dockerfile.cli +++ b/docker/Dockerfile.cli @@ -1,13 +1,12 @@ -FROM python:3.11 +FROM python:3.11-slim WORKDIR /app -COPY . /app +COPY . . -RUN pip install --upgrade pip -RUN pip install --no-cache-dir -r requirements/prod.txt +RUN pip install --upgrade pip && \ + pip install --no-cache-dir -r requirements/prod.txt -EXPOSE 80 -EXPOSE 443 +EXPOSE 80 443 CMD ["python", "-m", "bereal.cli"] diff --git a/docker/Dockerfile.flower b/docker/Dockerfile.flower index a781baa..661353a 100644 --- a/docker/Dockerfile.flower +++ b/docker/Dockerfile.flower @@ -1,16 +1,16 @@ -FROM python:3.11 +FROM python:3.11-slim WORKDIR /app -COPY . /app +COPY . . -RUN pip install --upgrade pip -RUN pip install --no-cache-dir -r requirements/prod.txt +RUN pip install --upgrade pip && \ + pip install --no-cache-dir -r requirements/prod.txt && \ + adduser --disabled-password --gecos '' thekid && \ + chown -R thekid:thekid /app -ENV FLASK_APP=bereal.server - -RUN adduser --disabled-password --gecos '' thekid -RUN chown -R thekid:thekid /app && chmod -R 777 /app USER thekid +ENV FLASK_APP=bereal.server + CMD ["celery", "-A", "bereal.celery", "flower", "--address=0.0.0.0", "--inspect", "--enable-events", "--loglevel=DEBUG", --"logfile=flower.log"] diff --git a/docker/Dockerfile.server b/docker/Dockerfile.server index 2c5c333..40e0a23 100644 --- a/docker/Dockerfile.server +++ b/docker/Dockerfile.server @@ -1,22 +1,19 @@ -FROM python:3.11 +FROM python:3.11-slim WORKDIR /app -COPY . /app +COPY . . +COPY --chmod=+x ./scripts/server-entrypoint.sh . -RUN apt-get update && apt-get install -y netcat-openbsd +RUN pip install --upgrade pip && \ + pip install --no-cache-dir -r requirements/prod.txt && \ + adduser --disabled-password --gecos '' thekid && \ + chown -R thekid:thekid /app -RUN pip install --upgrade pip -RUN pip install --no-cache-dir -r requirements/prod.txt - -COPY --chmod=+x ./scripts/server-entrypoint.sh /app/ +USER thekid ENV FLASK_APP=bereal.server -RUN adduser --disabled-password --gecos '' thekid -RUN chown -R thekid:thekid /app && chmod -R 777 /app -USER thekid - EXPOSE 5000 ENTRYPOINT ["/app/server-entrypoint.sh"] diff --git a/nginx/robots.txt b/nginx/robots.txt new file mode 100644 index 0000000..1f53798 --- /dev/null +++ b/nginx/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: / diff --git a/requirements/common.txt b/requirements/common.txt index cba9f29..cdbbf44 100644 --- a/requirements/common.txt +++ b/requirements/common.txt @@ -16,3 +16,4 @@ pydub==0.25.1 python-dotenv==1.0.0 Requests==2.31.0 tqdm==4.66.1 +twilio==8.11.0