ARG PYTHON_VERSION=3.10.15 FROM python:$PYTHON_VERSION-slim as builder RUN pip install poetry==1.8.2 ENV POETRY_NO_INTERACTION=1 \ POETRY_VIRTUALENVS_IN_PROJECT=1 \ POETRY_VIRTUALENVS_CREATE=1 \ POETRY_CACHE_DIR=/tmp/poetry_cache WORKDIR /app COPY pyproject.toml poetry.lock ./ RUN poetry install --no-root && rm -rf $POETRY_CACHE_DIR FROM python:$PYTHON_VERSION-slim as runtime # Create user first RUN useradd -m -u 1000 user ####### Add your own installation commands here ####### # Create necessary directories with proper permissions RUN mkdir -p /app/cache && chmod 777 /app/cache && \ mkdir -p /app/output && chmod 777 /app/output && \ chown -R user:user /app/output /app/cache # Copy virtual environment and set permissions COPY --from=builder /app/.venv /app/.venv RUN chown -R user:user /app/.venv # Copy application code COPY . /app RUN chown -R user:user /app # Switch to user USER user ENV VIRTUAL_ENV=/app/.venv \ PATH="/app/.venv/bin:$PATH" # Install additional dependencies RUN pip install python-multipart # Install spaCy model as user RUN python -m spacy download en_core_web_sm EXPOSE 7860 CMD ["sh", "/app/bin/api-start.sh"]