add minimum image type

This commit is contained in:
Feng Wang
2024-10-18 20:10:17 +08:00
parent ce236ef074
commit 625d620970
4 changed files with 176 additions and 11 deletions

View File

@@ -1,6 +1,7 @@
FROM python:3.11-slim-bookworm as base
FROM python:3.11-slim-bookworm AS base
# Use args
ARG MINIMUM_BUILD
ARG USE_CUDA
ARG USE_CUDA_VER
@@ -8,11 +9,12 @@ ARG USE_CUDA_VER
ENV ENV=prod \
PORT=9099 \
# pass build args to the build
MINIMUM_BUILD=${MINIMUM_BUILD} \
USE_CUDA_DOCKER=${USE_CUDA} \
USE_CUDA_DOCKER_VER=${USE_CUDA_VER}
# Install GCC and build tools
# Install GCC and build tools.
# These are kept in the final image to enable installing packages on the fly.
RUN apt-get update && \
apt-get install -y gcc build-essential curl git && \
apt-get clean && \
@@ -22,13 +24,20 @@ WORKDIR /app
# Install Python dependencies
COPY ./requirements.txt .
RUN pip3 install uv && \
if [ "$USE_CUDA" = "true" ]; then \
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/$USE_CUDA_DOCKER_VER --no-cache-dir; \
else \
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu --no-cache-dir; \
COPY ./requirements-minimum.txt .
RUN pip3 install uv
RUN if [ "$MINIMUM_BUILD" != "true" ]; then \
if [ "$USE_CUDA_DOCKER" = "true" ]; then \
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/$USE_CUDA_DOCKER_VER --no-cache-dir; \
else \
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu --no-cache-dir; \
fi \
fi
RUN if [ "$MINIMUM_BUILD" = "true" ]; then \
uv pip install --system -r requirements-minimum.txt --no-cache-dir; \
else \
uv pip install --system -r requirements.txt --no-cache-dir; \
fi
RUN uv pip install --system -r requirements.txt --no-cache-dir
# Copy the application code
COPY . .
@@ -37,4 +46,4 @@ COPY . .
ENV HOST="0.0.0.0"
ENV PORT="9099"
ENTRYPOINT [ "bash", "start.sh" ]
ENTRYPOINT [ "bash", "start.sh" ]