File size: 1,854 Bytes
ce4bc73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
779ae91
ce4bc73
 
779ae91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ce4bc73
 
779ae91
ce4bc73
 
 
 
 
 
 
779ae91
ce4bc73
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
FROM python:3.11-slim

WORKDIR /app

# Set environment variables
ENV PYTHONPATH=/app
# Use PORT 7860 for Hugging Face Spaces, 8050 for local development
# The application will check for HF_SPACE environment variable to determine the environment
ENV PORT=8050
ENV HF_SPACE=1
# No need to set LOG_LEVEL as it will be determined from folio.yaml based on environment
# Note: Sensitive environment variables like GEMINI_API_KEY should be passed at runtime
# rather than build time for security reasons

# Flag to install development dependencies
ARG INSTALL_DEV=false

# Install only the necessary system dependencies
RUN apt-get update && \
    apt-get install -y --no-install-recommends gcc curl && \
    rm -rf /var/lib/apt/lists/*

# Install Poetry
ENV POETRY_HOME=/opt/poetry
ENV POETRY_VIRTUALENVS_CREATE=false
RUN curl -sSL https://install.python-poetry.org | python3 - && \
    ln -s /opt/poetry/bin/poetry /usr/local/bin/poetry

# Copy only what's needed for dependency installation
COPY pyproject.toml poetry.lock* ./

# Install dependencies with --no-root to skip installing the current project
RUN if [ "$INSTALL_DEV" = "true" ]; then \
    echo "Installing with development dependencies..." && \
    poetry install --no-interaction --no-ansi --no-root; \
    else \
    echo "Installing without development dependencies..." && \
    poetry install --no-interaction --no-ansi --only main --no-root; \
    fi

# Copy only the application code
COPY src ./src

# Expose both ports (7860 for Hugging Face, 8050 for local)
EXPOSE 7860 8050

# Run the application with Gunicorn for production deployment
# The command will determine the correct port based on environment
# Note: Huggingface must use port 7860
CMD ["sh", "-c", "if [ -n \"$HF_SPACE\" ]; then PORT=7860; fi && gunicorn --bind 0.0.0.0:$PORT --workers 2 --timeout 60 src.folio.app:server"]