File size: 1,780 Bytes
b0c3c39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
56
57
58
59
60
61
62
63
# Use official Python 3.10 image as base
FROM python:3.10-slim

# Install Node.js (for React build) and other dependencies
RUN apt-get update && \

    apt-get install -y curl build-essential git && \
    curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
    apt-get install -y nodejs && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

# Set up a new user named "user" with user ID 1000
RUN useradd -m -u 1000 user

# Set environment variables
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

# Set the working directory to the user's home directory
WORKDIR $HOME/app

# Copy requirements first for better caching
COPY --chown=user requirements.txt $HOME/app/requirements.txt

# Install Python dependencies
RUN pip install --no-cache-dir --upgrade pip && \

    pip install --no-cache-dir -r requirements.txt

# Copy the rest of the code
COPY --chown=user . $HOME/app

# Build the React frontend
WORKDIR $HOME/app/frontend
RUN npm install --legacy-peer-deps && npm run build

# Move build to a static directory for Flask to serve
RUN mkdir -p $HOME/app/static && \

    cp -r build/* $HOME/app/static/

# Switch back to backend directory
WORKDIR $HOME/app

# Install supervisor
RUN apt-get update && apt-get install -y supervisor

# Create supervisor config directory
RUN mkdir -p /etc/supervisor/conf.d

# Copy supervisor config
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# Switch to the "user" user
USER user

# Expose both ports (adjust as needed)
EXPOSE 7860 3000

# Set environment for React dev server
ENV HOST=0.0.0.0
ENV PORT=3000

# Start supervisor (which starts both Flask and React)
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]