Skip to content

Commit

Permalink
Update Dockerfile
Browse files Browse the repository at this point in the history
Fix cache Issue
  • Loading branch information
rainmanjam authored Dec 16, 2024
1 parent 463074a commit 922e453
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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} \
Expand Down

0 comments on commit 922e453

Please sign in to comment.