-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathDockerfile
46 lines (33 loc) · 1.16 KB
/
Dockerfile
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
# Stage 1: Build React Frontend
FROM node:18 as frontend-builder
WORKDIR /app/frontend
# Copy frontend source code to the container
COPY frontend/ .
# Copy package.json and package-lock.json (or npm-shrinkwrap.json)
COPY frontend/package*.json ./
# Install dependencies using npm ci for caching
RUN npm install
RUN npm run build
# Stage 2: Build Django Backend
FROM python:3.11 as backend-builder
WORKDIR /app/backend
# Copy backend source code to the container
COPY backend/ .
# Install Python dependencies
RUN pip install -r requirements.txt
# Stage 3: Final Image
FROM python:3.11
WORKDIR /app
# Copy the built React app from the frontend builder stage
COPY --from=frontend-builder /app/frontend/build/ /app/frontend/build/
# Copy the built Django backend from the backend builder stage
COPY --from=backend-builder /app/backend/ /app/backend/
# Expose any necessary ports
EXPOSE 8000
# Set environment variables if needed
# ENV DJANGO_SECRET_KEY=<your_secret_key>
# ENV DEBUG=False
# Install any additional dependencies if needed
# RUN apt-get update && apt-get install -y ...
# Start your Django application
CMD ["python", "backend/manage.py", "runserver", "0.0.0.0:8000"]