Skip to content

Commit

Permalink
chore: fix CodeFactor suggestions
Browse files Browse the repository at this point in the history
- Add `**.png` to the `.dockerignore` file
- Add a new file `.hadolint.yml`
- Specify the ignored rule in `.hadolint.yml`
- Update the Dockerfile to install specific versions of `libgomp1` and `libsndfile1`
- Update the Dockerfile to install specific versions of `torch` and `torchaudio`
- Update the Dockerfile to install a specific version of `git`
- Copy the `load_align_model.py` file to a static location
- Use arguments JSON notation for CMD and ENTRYPOINT arguments

Signed-off-by: 陳鈞 <[email protected]>
  • Loading branch information
jim60105 committed Dec 9, 2023
1 parent a446032 commit 01940fa
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 23 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
**.git*
**Dockerfile*
**.vscode
**.png
2 changes: 2 additions & 0 deletions .hadolint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignored:
- DL3042 # Avoid use of cache directory with pip. Use `pip install --no-cache-dir <package>`
20 changes: 12 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,27 @@ FROM python:3.11-slim as python
RUN python3 -m venv /venv
ARG PATH="/venv/bin:$PATH"
ENV PATH=${PATH}
RUN --mount=type=cache,target=/root/.cache/pip pip install --upgrade pip setuptools

# Missing dependencies for arm64
# https://github.com/jim60105/docker-whisperX/issues/14
ARG TARGETPLATFORM
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
apt-get update && apt-get install -y --no-install-recommends libgomp1 libsndfile1; \
apt-get update && apt-get install -y --no-install-recommends libgomp1=12.2.0-14 libsndfile1=1.2.0-1 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*; \
fi


FROM python as build

# Install requirements
RUN --mount=type=cache,target=/root/.cache/pip pip install torch torchaudio --extra-index-url https://download.pytorch.org/whl/cu118
RUN --mount=type=cache,target=/root/.cache/pip pip install torch==2.1.1 torchaudio==2.1.1 --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
RUN apt-get update && apt-get install -y --no-install-recommends git=1:2.39.2-1.1 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Install whisperX
COPY ./whisperX /code
Expand Down Expand Up @@ -61,12 +64,14 @@ ARG PATH="/venv/bin:$PATH"

# Preload align models
ARG LANG
COPY load_align_model.py .
RUN for i in ${LANG}; do echo "Aliging lang $i"; python3 load_align_model.py $i; done
COPY load_align_model.py /
RUN for i in ${LANG}; do echo "Aliging lang $i"; python3 /load_align_model.py "$i"; done


FROM python as final

RUN pip uninstall -y setuptools pip

# 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/
Expand Down Expand Up @@ -95,5 +100,4 @@ WORKDIR /app

STOPSIGNAL SIGINT
# Take the first language from LANG env variable
ENTRYPOINT LANG=$(echo ${LANG} | cut -d ' ' -f1); \
whisperx --model "${WHISPER_MODEL}" --language "${LANG}" "$@"
ENTRYPOINT ["sh", "-c", "LANG=$(echo ${LANG} | cut -d ' ' -f1); whisperx --model \"${WHISPER_MODEL}\" --language \"${LANG}\" \"$@\""]
7 changes: 3 additions & 4 deletions Dockerfile.cache
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ FROM ghcr.io/jim60105/whisperx:cache-${WHISPER_MODEL} as load_align

# Preload align models
ARG LANG
COPY load_align_model.py .
RUN for i in ${LANG}; do echo "Aliging lang $i"; python3 load_align_model.py $i; done
COPY load_align_model.py /
RUN for i in ${LANG}; do echo "Aliging lang $i"; python3 /load_align_model.py "$i"; done


FROM ghcr.io/jim60105/whisperx:no_model as final
Expand All @@ -31,5 +31,4 @@ ARG LANG
ENV LANG=${LANG}

# Take the first language from LANG env variable
ENTRYPOINT LANG=$(echo ${LANG} | cut -d ' ' -f1); \
whisperx --model "${WHISPER_MODEL}" --language "${LANG}" "$@"
ENTRYPOINT ["sh", "-c", "LANG=$(echo ${LANG} | cut -d ' ' -f1); whisperx --model \"${WHISPER_MODEL}\" --language \"${LANG}\" \"$@\""]
16 changes: 11 additions & 5 deletions Dockerfile.no_model
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,27 @@ FROM python:3.11-slim as python
RUN python3 -m venv /venv
ARG PATH="/venv/bin:$PATH"
ENV PATH=${PATH}
RUN --mount=type=cache,target=/root/.cache/pip pip install --upgrade pip setuptools

# Missing dependencies for arm64
# https://github.com/jim60105/docker-whisperX/issues/14
ARG TARGETPLATFORM
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
apt-get update && apt-get install -y --no-install-recommends libgomp1 libsndfile1; \
apt-get update && apt-get install -y --no-install-recommends libgomp1=12.2.0-14 libsndfile1=1.2.0-1 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*; \
fi


FROM python as build

# Install requirements
RUN --mount=type=cache,target=/root/.cache/pip pip install torch torchaudio --extra-index-url https://download.pytorch.org/whl/cu118
RUN --mount=type=cache,target=/root/.cache/pip pip install torch==2.1.1 torchaudio==2.1.1 --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
RUN apt-get update && apt-get install -y --no-install-recommends git=1:2.39.2-1.1 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Install whisperX
COPY ./whisperX /code
Expand All @@ -40,6 +43,8 @@ RUN --mount=type=cache,target=/root/.cache/pip pip install /code

FROM python as final

RUN pip uninstall -y setuptools pip

# 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/
Expand Down Expand Up @@ -67,4 +72,5 @@ USER 1001
WORKDIR /app

STOPSIGNAL SIGINT
ENTRYPOINT whisperx $@

ENTRYPOINT ["sh", "-c", "whisperx \"$@\""]
11 changes: 6 additions & 5 deletions Dockerfile.ubi
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ FROM python as build
RUN microdnf -y install git && \
microdnf clean all

RUN --mount=type=cache,target=/root/.cache/pip pip install torch torchaudio --extra-index-url https://download.pytorch.org/whl/cu118
RUN --mount=type=cache,target=/root/.cache/pip pip install torch==2.1.1 torchaudio==2.1.1 --extra-index-url https://download.pytorch.org/whl/cu118

# Install whisperX
COPY ./whisperX /code
Expand Down Expand Up @@ -62,12 +62,14 @@ ARG PATH="/venv/bin:$PATH"

# Preload align models
ARG LANG
COPY load_align_model.py .
RUN for i in ${LANG}; do echo "Aliging lang $i"; python3 load_align_model.py $i; done
COPY load_align_model.py /
RUN for i in ${LANG}; do echo "Aliging lang $i"; python3 /load_align_model.py "$i"; done


FROM python as final

RUN pip uninstall -y setuptools pip

# 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/
Expand Down Expand Up @@ -96,5 +98,4 @@ WORKDIR /app

STOPSIGNAL SIGINT
# Take the first language from LANG env variable
ENTRYPOINT LANG=$(echo ${LANG} | cut -d ' ' -f1); \
whisperx --model "${WHISPER_MODEL}" --language "${LANG}" "$@"
ENTRYPOINT ["sh", "-c", "LANG=$(echo ${LANG} | cut -d ' ' -f1); whisperx --model \"${WHISPER_MODEL}\" --language \"${LANG}\" \"$@\""]
2 changes: 1 addition & 1 deletion Dockerfile.ubi-no_model
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ USER 1001
WORKDIR /app

STOPSIGNAL SIGINT
ENTRYPOINT whisperx $@
ENTRYPOINT ["sh", "-c", "whisperx \"$@\""]
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# docker-whisperX

[![CodeFactor](https://www.codefactor.io/repository/github/jim60105/docker-whisperx/badge)](https://www.codefactor.io/repository/github/jim60105/docker-whisperx)

This is the docker image for [WhisperX: Automatic Speech Recognition with Word-Level Timestamps (and Speaker Diarization)](https://github.com/m-bain/whisperX) from the community.

Get the Dockerfile at [GitHub](https://github.com/jim60105/docker-whisperX), or pull the image from [ghcr.io](https://ghcr.io/jim60105/whisperx).
Expand Down

0 comments on commit 01940fa

Please sign in to comment.