File size: 1,710 Bytes
773c828
 
 
 
a26c4e8
773c828
 
 
a26c4e8
 
773c828
 
a26c4e8
773c828
a26c4e8
773c828
 
 
ae46fe5
 
1012e51
b42f8a9
 
 
 
 
ae46fe5
b42f8a9
 
 
7b72076
dca2fa6
 
8391eb5
 
 
 
 
 
2a67c57
 
 
3c9ef9b
2b02f32
76161e8
 
 
 
a154475
ef960d3
 
8391eb5
b1e9740
 
3c9ef9b
7b72076
 
 
b42f8a9
1c87d00
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
# Step #1: build the React front end
FROM node:14-bullseye-slim as build-step
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
RUN mkdir ./frontend
COPY ./frontend/package.json ./frontend/package-lock.json ./frontend/
WORKDIR /app/frontend
RUN npm install -g [email protected]
# It's OK to have multiple consecutive `RUN` instructions.
# hadolint ignore=DL3059
RUN npm install

WORKDIR /app
COPY ./frontend ./frontend

WORKDIR /app/frontend
RUN npm run build

# Step #2: set up the Python backend and Nginx
FROM python:3.10.13-slim-bullseye
RUN apt-get update && apt-get install -y nginx procps \
    && rm -rf /var/lib/apt/lists/*

RUN python3 -m pip install --upgrade pip \
    && pip install gunicorn==20.1.0

# Copy backend code and install dependencies
COPY ./backend ./backend
RUN pip install -r ./backend/requirements.txt

# Ensure necessary permissions and create directories
RUN mkdir -p /var/log/nginx && \
    touch /var/log/nginx/error.log && \
    touch /var/log/nginx/access.log && \
    chmod -R 777 /var/log/nginx && \
    chown -R root:root /var/log/nginx && \
    chmod -R 777 /var/lib/nginx && \
    chown -R root:root /var/lib/nginx && \
    chmod -R 777 /usr/share/nginx/html && \
    chown -R root:root /usr/share/nginx/html && \
    mkdir -p /run && \
    chmod -R 777 /run

# Step #3: Configure nginx and flask
COPY --from=build-step /app/frontend/build /usr/share/nginx/html
COPY deployment/docker/nginx.conf /etc/nginx/nginx.conf  
COPY deployment/docker/serve.sh /serve.sh 
RUN chmod a+x /serve.sh

# Remove the user directive if present
RUN sed -i '/^user /d' /etc/nginx/nginx.conf

# Expose port 8080
EXPOSE 8080

# Run as root user
USER root

ENTRYPOINT ["/bin/bash"]
CMD ["/serve.sh"]