Skip to content

Commit

Permalink
style: improve Dockerfile readability
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPandir committed May 21, 2024
1 parent 89292fe commit e9c846d
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions docker/Dockerfile
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 <MrPandir@users.noreply.github.com>"
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
Expand All @@ -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 <MrPandir@users.noreply.github.com>"
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
Expand Down

0 comments on commit e9c846d

Please sign in to comment.