Skip to content

Commit

Permalink
chore: Improve build time cacheing
Browse files Browse the repository at this point in the history
  • Loading branch information
jim60105 committed Aug 29, 2023
1 parent 1faee93 commit caa5806
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
18 changes: 9 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ FROM python:3.10-slim as dependencies
# Setup venv
RUN python3 -m venv /venv
ARG PATH="/venv/bin:$PATH"
RUN python3 -m pip install --upgrade pip setuptools
RUN --mount=type=cache,target=/root/.cache/pip pip install --upgrade pip setuptools
# Install requirements
RUN python3 -m pip install torch torchaudio --extra-index-url https://download.pytorch.org/whl/cu118
RUN --mount=type=cache,target=/root/.cache/pip pip install torch torchaudio --extra-index-url https://download.pytorch.org/whl/cu118

# Add git
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends git

# Install whisperX
COPY ./whisperX /code
RUN python3 -m pip install /code
RUN --mount=type=cache,target=/root/.cache/pip pip install /code


FROM dependencies as load_model
Expand All @@ -42,27 +42,27 @@ RUN python3 load_align_model.py ${LANG}

FROM python:3.10-slim

# ffmpeg
COPY --link --from=mwader/static-ffmpeg:6.0 /ffmpeg /usr/local/bin/
COPY --link --from=mwader/static-ffmpeg:6.0 /ffprobe /usr/local/bin/

# Copy and use venv
COPY --from=dependencies /venv /venv
COPY --link --from=dependencies /venv /venv
ARG PATH="/venv/bin:$PATH"
ENV PATH=${PATH}

# Non-root user
RUN useradd -m -s /bin/bash appuser
USER appuser

COPY --chown=appuser --from=load_model /cache /cache
COPY --link --chown=appuser --from=load_model /cache /cache

WORKDIR /app
ARG TORCH_HOME
ARG HF_HOME
ENV TORCH_HOME=${TORCH_HOME}
ENV HF_HOME=${HF_HOME}

# ffmpeg
COPY --link --from=mwader/static-ffmpeg:6.0 /ffmpeg /usr/local/bin/
COPY --link --from=mwader/static-ffmpeg:6.0 /ffprobe /usr/local/bin/

ARG WHISPER_MODEL
ENV WHISPER_MODEL=${WHISPER_MODEL}
ARG LANG
Expand Down
10 changes: 5 additions & 5 deletions Dockerfile.no_model
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ RUN python3 -m pip install /code

FROM python:3.10-slim

# ffmpeg
COPY --link --from=mwader/static-ffmpeg:6.0 /ffmpeg /usr/local/bin/
COPY --link --from=mwader/static-ffmpeg:6.0 /ffprobe /usr/local/bin/

# Copy and use venv
COPY --from=dependencies /venv /venv
COPY --link --from=dependencies /venv /venv
ARG PATH="/venv/bin:$PATH"
ENV PATH=${PATH}

Expand All @@ -38,10 +42,6 @@ ARG HF_HOME
ENV TORCH_HOME=${TORCH_HOME}
ENV HF_HOME=${HF_HOME}

# ffmpeg
COPY --link --from=mwader/static-ffmpeg:6.0 /ffmpeg /usr/local/bin/
COPY --link --from=mwader/static-ffmpeg:6.0 /ffprobe /usr/local/bin/

ARG WHISPER_MODEL
ENV WHISPER_MODEL=${WHISPER_MODEL}
ARG LANG
Expand Down

0 comments on commit caa5806

Please sign in to comment.