hfacemko commited on
Commit
c1ea9a8
·
verified ·
1 Parent(s): cd36f29

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +55 -14
Dockerfile CHANGED
@@ -1,25 +1,66 @@
1
- # Use an official Python runtime as a parent image
2
- FROM python:3.9-slim
 
3
 
4
- # Set the working directory in the container to /app
5
- WORKDIR /app
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
- # Install git and other dependencies
8
  RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
9
 
10
  # Clone the repository
11
- RUN git clone https://github.com/KenKout/CO3001.git /app
12
 
13
- # Install Python dependencies
 
14
  RUN pip install --no-cache-dir -r requirements.txt
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
- RUN chmod 777 /app
 
 
 
17
 
18
- COPY studyspace.db .
19
- RUN chmod 777 studyspace.db
 
 
 
 
20
 
21
- # Expose the port that Uvicorn will run on
22
- EXPOSE 8000
23
 
24
- # Run Uvicorn when the container launches
25
- CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
 
1
+ # Frontend build stage
2
+ FROM node:18-slim AS frontend-builder
3
+ WORKDIR /frontend
4
 
5
+ # Install git
6
+ RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
7
+
8
+ # Clone the repository
9
+ RUN git clone https://github.com/KenKout/CO3001.git /tmp/repo
10
+
11
+ # Copy frontend files from cloned repo
12
+ COPY /tmp/repo/frontend/package*.json ./
13
+ RUN npm install
14
+ COPY /tmp/repo/frontend/ ./
15
+ RUN npm run build
16
+
17
+ # Backend build stage
18
+ FROM python:3.11-slim AS backend-builder
19
+ WORKDIR /backend
20
 
21
+ # Install git
22
  RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
23
 
24
  # Clone the repository
25
+ RUN git clone https://github.com/KenKout/CO3001.git /tmp/repo
26
 
27
+ # Copy backend files from cloned repo
28
+ COPY /tmp/repo/requirements.txt .
29
  RUN pip install --no-cache-dir -r requirements.txt
30
+ COPY /tmp/repo/app/ app/
31
+
32
+ # Final stage
33
+ FROM node:18-slim
34
+ WORKDIR /app
35
+
36
+ # Install Python and required system dependencies
37
+ RUN apt-get update && apt-get install -y \
38
+ python3 \
39
+ python3-pip \
40
+ && rm -rf /var/lib/apt/lists/*
41
+
42
+ # Copy backend from backend-builder
43
+ COPY --from=backend-builder /usr/local/lib/python3.11/site-packages/ /usr/local/lib/python3.11/site-packages/
44
+ COPY --from=backend-builder /backend/app/ ./app/
45
+
46
+ # Copy frontend from frontend-builder
47
+ COPY --from=frontend-builder /frontend/.next ./.next
48
+ COPY --from=frontend-builder /frontend/public ./public
49
+ COPY --from=frontend-builder /frontend/package*.json ./
50
+ COPY --from=frontend-builder /frontend/node_modules ./node_modules
51
 
52
+ # Set environment variables
53
+ ENV PYTHONUNBUFFERED=1
54
+ ENV NODE_ENV=production
55
+ ENV PORT=3000
56
 
57
+ # Clone repository again to get entrypoint script
58
+ RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/* \
59
+ && git clone https://github.com/KenKout/CO3001.git /tmp/repo \
60
+ && cp /tmp/repo/entrypoint.sh /entrypoint.sh \
61
+ && chmod +x /entrypoint.sh \
62
+ && rm -rf /tmp/repo
63
 
64
+ EXPOSE 3000
 
65
 
66
+ ENTRYPOINT ["/entrypoint.sh"]