File size: 1,973 Bytes
9f7a5a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
52
53
54
55
FROM python:3.9-slim

# Install curl, Node.js, Ollama, and Nginx in a single RUN instruction
RUN apt-get update && \
    apt-get install -y curl nginx && \
    # Install Ollama (using their official script)
    curl -fsSL https://ollama.ai/install.sh | sh && \
    # Install Node.js 18.x from NodeSource
    curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
    apt-get install -y nodejs && \
    # Clean up APT caches to reduce image size
    apt-get clean && rm -rf /var/lib/apt/lists/*

# Create Nginx cache/temp and log directories as root
RUN mkdir -p /var/cache/nginx /var/lib/nginx/body /var/lib/nginx/fastcgi /var/lib/nginx/proxy /var/lib/nginx/scgi /var/lib/nginx/uwsgi /var/log/nginx

# Set up user and environment
# Running as a non-root user is good practice
RUN useradd -m -u 1000 user
# NOW chown the directories, after the user 'user' is created
RUN chown -R user:user /var/cache/nginx /var/lib/nginx /var/log/nginx && \
    chmod -R 755 /var/cache/nginx /var/lib/nginx /var/log/nginx

# --- CRITICAL CHANGE: Move USER instruction HERE ---
USER user
ENV HOME=/home/user \
    PATH="/home/user/.local/bin:$PATH"

WORKDIR $HOME/app

# Copy requirements.txt FIRST to leverage Docker caching for Python dependencies
COPY --chown=user requirements.txt .
RUN pip install --no-cache-dir --upgrade -r requirements.txt

# Copy the entire frontend directory early to ensure Node.js dependencies are installed
COPY --chown=user frontend frontend/

# Install Node.js dependencies for the frontend and build it
RUN cd frontend && npm install --production=false && npm run build

# Copy the Nginx configuration
COPY --chown=user nginx.conf /etc/nginx/nginx.conf

# Copy the rest of the application files AFTER dependencies are installed
COPY --chown=user . .

# Make the start script executable
RUN chmod +x start.sh

# Expose ports for FastAPI (7860) and Nginx (8501)
EXPOSE 7860
EXPOSE 8501

# Command to execute when the container starts
CMD ["./start.sh"]