Skip to content

Commit

Permalink
feat: improve image sizes; add twilio functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfromyeg committed Jan 7, 2024
1 parent bf023d5 commit 671ec95
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 44 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"README": "plaintext",
"*.mako": "python",
"*.conf": "ini",
"*.rdb": "sql",
},
"files.insertFinalNewline": true,
"editor.formatOnSave": true,
Expand Down
3 changes: 0 additions & 3 deletions bereal/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions bereal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from dotenv import load_dotenv

from .logger import logger

# Environment variables
load_dotenv()
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions bereal/videos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 9 additions & 9 deletions docker/Dockerfile.celery
Original file line number Diff line number Diff line change
@@ -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"]
11 changes: 5 additions & 6 deletions docker/Dockerfile.cli
Original file line number Diff line number Diff line change
@@ -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"]
16 changes: 8 additions & 8 deletions docker/Dockerfile.flower
Original file line number Diff line number Diff line change
@@ -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"]
19 changes: 8 additions & 11 deletions docker/Dockerfile.server
Original file line number Diff line number Diff line change
@@ -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"]
2 changes: 2 additions & 0 deletions nginx/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
User-agent: *
Disallow: /
1 change: 1 addition & 0 deletions requirements/common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 671ec95

Please sign in to comment.