From 922e4537a014f976c4d1b18f37540ab05d6f5411 Mon Sep 17 00:00:00 2001 From: Shannon Atkinson Date: Mon, 16 Dec 2024 12:52:06 -0800 Subject: [PATCH] Update Dockerfile Fix cache Issue --- Dockerfile | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index d6918fe..f9871e5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -150,32 +150,38 @@ WORKDIR /app # Set environment variable for Whisper cache ENV WHISPER_CACHE_DIR="/app/whisper_cache" -# Create cache directory -RUN mkdir -p ${WHISPER_CACHE_DIR} && chmod 777 ${WHISPER_CACHE_DIR} +# Create cache directory (no need for chown here yet) +RUN mkdir -p ${WHISPER_CACHE_DIR} # Copy the requirements file first to optimize caching COPY requirements.txt . -# Install Python dependencies, upgrade pip, and pre-download the Whisper model -RUN pip install openai-whisper && \ - pip install jsonschema && \ - pip install --no-cache-dir --upgrade pip && \ +# Install Python dependencies, upgrade pip +RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir -r requirements.txt && \ - python -c "import os; os.environ['WHISPER_CACHE_DIR'] = '${WHISPER_CACHE_DIR}'; import whisper; whisper.load_model('base')" + pip install openai-whisper && \ + pip install jsonschema -# Copy the rest of the application code -COPY . . +# Create the appuser +RUN useradd -m appuser + +# Give appuser ownership of the /app directory (including whisper_cache) +RUN chown appuser:appuser /app -# Create a non-root user and switch to it -RUN useradd -m appuser && chown -R appuser /app +# Important: Switch to the appuser before downloading the model USER appuser -# Set environment variables -ENV PYTHONUNBUFFERED=1 +RUN python -c "import os; print(os.environ.get('WHISPER_CACHE_DIR')); import whisper; whisper.load_model('base')" + +# Copy the rest of the application code +COPY . . # Expose the port the app runs on EXPOSE 8080 +# Set environment variables +ENV PYTHONUNBUFFERED=1 + RUN echo '#!/bin/bash\n\ gunicorn --bind 0.0.0.0:8080 \ --workers ${GUNICORN_WORKERS:-2} \