Skip to content

Commit

Permalink
Update Dockerfiles to improve caching
Browse files Browse the repository at this point in the history
  • Loading branch information
EricTendian committed Jan 6, 2025
1 parent a909aea commit 8c00280
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 32 deletions.
12 changes: 4 additions & 8 deletions docker/Dockerfile.fasterwhisper
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,21 @@ ENV UV_COMPILE_BYTECODE=1
# Copy from the cache instead of linking since it's a mounted volume
ENV UV_LINK_MODE=copy

COPY pyproject.toml pyproject.toml
COPY uv.lock uv.lock

# Install the project's dependencies using the lockfile and settings
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen --no-install-project --no-dev --group faster-whisper

# Then, add the rest of the project source code and install it
# Installing separately from its dependencies allows optimal layer caching
ADD . /src
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev --group faster-whisper

# Setup Faster Whisper
ARG WHISPER_MODEL=base.en
ENV WHISPER_MODEL=${WHISPER_MODEL}
# Pre-download the Whisper model
RUN uv run python -c "import os; from faster_whisper.utils import download_model; download_model(os.getenv('WHISPER_MODEL'))"
ENV WHISPER_IMPLEMENTATION=faster-whisper

COPY alembic.ini alembic.ini
COPY app app
COPY config config
COPY docker/docker-entrypoint.sh /usr/local/bin/
Expand Down
12 changes: 4 additions & 8 deletions docker/Dockerfile.whisper
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,21 @@ ENV UV_COMPILE_BYTECODE=1
# Copy from the cache instead of linking since it's a mounted volume
ENV UV_LINK_MODE=copy

COPY pyproject.toml pyproject.toml
COPY uv.lock uv.lock

# Install the project's dependencies using the lockfile and settings
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen --no-install-project --no-dev --group whisper

# Then, add the rest of the project source code and install it
# Installing separately from its dependencies allows optimal layer caching
ADD . /src
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev --group whisper

# Setup Whisper
ARG WHISPER_MODEL=base.en
ENV WHISPER_MODEL=${WHISPER_MODEL}
# Pre-download the Whisper model
RUN uv run python -c "import whisper; import os; whisper.load_model(os.getenv('WHISPER_MODEL'))"
ENV WHISPER_IMPLEMENTATION=whisper

COPY alembic.ini alembic.ini
COPY app app
COPY config config
COPY docker/docker-entrypoint.sh /usr/local/bin/
Expand Down
12 changes: 4 additions & 8 deletions docker/Dockerfile.whispercpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,13 @@ ENV UV_COMPILE_BYTECODE=1
# Copy from the cache instead of linking since it's a mounted volume
ENV UV_LINK_MODE=copy

COPY pyproject.toml pyproject.toml
COPY uv.lock uv.lock

# Install the project's dependencies using the lockfile and settings
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen --no-install-project --no-dev $WHISPER_IMPLEMENTATION_GROUP

# Then, add the rest of the project source code and install it
# Installing separately from its dependencies allows optimal layer caching
ADD . /src
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev $WHISPER_IMPLEMENTATION_GROUP

# Install Whisper.cpp
COPY --from=whispercpp /whisper.cpp/main /usr/local/bin/whisper-cpp
COPY --from=whispercpp /whisper.cpp/models/ggml-*.bin /usr/local/lib/whisper-models/
Expand All @@ -83,6 +78,7 @@ ARG WHISPER_MODEL=base.en
ENV WHISPER_MODEL=${WHISPER_MODEL}
ENV WHISPERCPP_MODEL_DIR=/usr/local/lib/whisper-models

COPY alembic.ini alembic.ini
COPY app app
COPY config config
COPY docker/docker-entrypoint.sh /usr/local/bin/
Expand Down
12 changes: 4 additions & 8 deletions docker/Dockerfile.whispers2t
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,13 @@ ENV UV_COMPILE_BYTECODE=1
# Copy from the cache instead of linking since it's a mounted volume
ENV UV_LINK_MODE=copy

COPY pyproject.toml pyproject.toml
COPY uv.lock uv.lock

# Install the project's dependencies using the lockfile and settings
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen --no-install-project --no-dev --group whispers2t

# Then, add the rest of the project source code and install it
# Installing separately from its dependencies allows optimal layer caching
ADD . /src
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev --group whispers2t

# Setup WhisperS2T
ARG WHISPER_MODEL=base.en
ENV WHISPER_MODEL=${WHISPER_MODEL}
Expand All @@ -61,6 +56,7 @@ RUN uv run python -c "import os; from whisper_s2t.backends.ctranslate2.hf_utils
ENV WHISPER_IMPLEMENTATION=whispers2t
ENV TQDM_DISABLE=1

COPY alembic.ini alembic.ini
COPY app app
COPY config config
COPY docker/docker-entrypoint.sh /usr/local/bin/
Expand Down

0 comments on commit 8c00280

Please sign in to comment.