-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
style: improve Dockerfile readability
- Loading branch information
Showing
1 changed file
with
13 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,12 @@ | ||
FROM python:3.11-slim-bookworm as base | ||
LABEL org.opencontainers.image.authors="MrPandir <[email protected]>" | ||
LABEL org.opencontainers.image.source="https://github.com/twirapp/silero-tts-api-server" | ||
LABEL org.opencontainers.image.licenses="MIT" | ||
LABEL org.opencontainers.image.title="Silero TTS API server" | ||
LABEL org.opencontainers.image.description="This is a simple server that uses Silero models to convert text to audio files over HTTP" | ||
LABEL org.opencontainers.image.vendor="TwirApp" | ||
FROM python:3.11-slim-bookworm AS python-and-curl | ||
RUN apt-get update && apt-get -y --no-install-recommends install curl | ||
|
||
# Install all dependencies from pyproject.toml | ||
# NOTE: Rye is used because you need to determine which version of torch to use +cpu or not | ||
# NOTE: The problem with uv is that it does not read the rye.excluded-dependencies metadata | ||
FROM base as dependencies-installer | ||
FROM python-and-curl AS dependencies-installer | ||
WORKDIR /app | ||
RUN <<EOF | ||
apt-get -y update && apt-get -y install curl | ||
apt-get autoremove && apt-get clean | ||
|
||
curl -LsSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" RYE_TOOLCHAIN=/usr/local/bin/python3 bash | ||
ln -s /root/.rye/shims/rye /usr/local/bin/rye | ||
rye pin 3.11 | ||
|
@@ -24,17 +16,24 @@ COPY pyproject.toml . | |
RUN --mount=type=cache,target=/root/.cache rye sync --no-dev | ||
|
||
# Install all silero models from the Internet or locally if available in the `models` directory | ||
FROM base as models-installer | ||
RUN apt-get -y update && apt-get -y install curl | ||
FROM python-and-curl AS models-installer | ||
COPY models models | ||
COPY install_models.sh install_models.sh | ||
RUN chmod -x ./install_models.sh && bash ./install_models.sh >&2 | ||
|
||
# Final State | ||
# Distroless is a small image with only python, providing a non-root user | ||
FROM gcr.io/distroless/python3-debian12:nonroot | ||
LABEL org.opencontainers.image.authors="MrPandir <[email protected]>" | ||
LABEL org.opencontainers.image.source="https://github.com/twirapp/silero-tts-api-server" | ||
LABEL org.opencontainers.image.licenses="MIT" | ||
LABEL org.opencontainers.image.title="Silero TTS API server" | ||
LABEL org.opencontainers.image.description="This is a simple server that uses Silero models to convert text to audio files over HTTP" | ||
LABEL org.opencontainers.image.vendor="TwirApp" | ||
|
||
WORKDIR /app | ||
ENV PATH=/app/.venv/bin:$PATH | ||
# This is necessary for Python to understand where to look for libraries. | ||
# This is necessary for python to understand where to look for libraries | ||
ENV PYTHONPATH="/app/.venv/lib/python3.11/site-packages/:$PYTHONPATH" | ||
USER nonroot | ||
COPY --from=models-installer /models models | ||
|