Vibi007 commited on
Commit
1fad674
·
1 Parent(s): 3993cab

reduce docker image size

Browse files
Files changed (2) hide show
  1. .dockerignore +7 -0
  2. Dockerfile +20 -19
.dockerignore ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ node_modules
2
+ build/
3
+ .git
4
+ *.log
5
+ .cache
6
+ backend/data/
7
+ backend/token_frequencies.json
Dockerfile CHANGED
@@ -1,9 +1,9 @@
1
  # Stage 1: Build React frontend
2
- FROM node:14 AS frontend-builder
3
 
4
  WORKDIR /app/frontend
5
 
6
- # Copy frontend code
7
  COPY frontend/package*.json ./
8
  RUN npm install
9
 
@@ -11,34 +11,35 @@ COPY frontend/ ./
11
  RUN npm run build
12
 
13
  # Stage 2: Build FastAPI backend
14
- FROM python:3.8-slim AS backend-builder
15
 
16
  WORKDIR /app/backend
17
 
18
- # Install system dependencies
19
- RUN apt-get update && apt-get install -y gcc libpq-dev
20
 
21
- # Copy backend code
22
  COPY backend/requirements.txt ./
23
-
24
- # Debugging: List contents to verify requirements.txt is present
25
- RUN ls -la
26
-
27
- # Install Python dependencies
28
- RUN pip install --no-cache-dir -r ./requirements.txt && pip freeze
29
 
30
  COPY backend/ ./
31
 
32
  # Stage 3: Final stage
33
- FROM python:3.8-slim
34
 
35
  WORKDIR /app
36
 
37
- # Install serve globally to serve the React app
38
- RUN pip install uvicorn fastapi tqdm wikitextparser pydantic requests beautifulsoup4 && apt-get update && apt-get install -y nodejs npm && npm install -g serve
 
 
 
 
 
 
 
39
 
40
- # Install supervisord
41
- RUN apt-get install -y supervisor
42
 
43
  # Copy supervisord configuration
44
  COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
@@ -53,5 +54,5 @@ COPY --from=backend-builder /app/backend /app/backend
53
  EXPOSE 7860
54
  EXPOSE 8000
55
 
56
- # Start supervisord
57
- CMD ["supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
 
1
  # Stage 1: Build React frontend
2
+ FROM node:14-alpine AS frontend-builder
3
 
4
  WORKDIR /app/frontend
5
 
6
+ # Copy frontend code and install dependencies
7
  COPY frontend/package*.json ./
8
  RUN npm install
9
 
 
11
  RUN npm run build
12
 
13
  # Stage 2: Build FastAPI backend
14
+ FROM python:3.8-alpine AS backend-builder
15
 
16
  WORKDIR /app/backend
17
 
18
+ # Install system dependencies (use lightweight alternatives)
19
+ RUN apk update && apk add --no-cache gcc libpq-dev
20
 
21
+ # Copy backend code and install Python dependencies
22
  COPY backend/requirements.txt ./
23
+ RUN pip install --no-cache-dir -r requirements.txt
 
 
 
 
 
24
 
25
  COPY backend/ ./
26
 
27
  # Stage 3: Final stage
28
+ FROM python:3.8-alpine
29
 
30
  WORKDIR /app
31
 
32
+ # Step 1: Install nodejs, npm, and supervisor
33
+ RUN apk update
34
+ RUN apk add --no-cache nodejs npm supervisor
35
+
36
+ # Step 2: Install Python dependencies
37
+ RUN pip install --no-cache-dir uvicorn fastapi tqdm wikitextparser pydantic requests beautifulsoup4
38
+
39
+ # Step 3: Install serve globally for serving React app
40
+ RUN npm install -g serve
41
 
42
+ # No need for apk clean, it's not required
 
43
 
44
  # Copy supervisord configuration
45
  COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
 
54
  EXPOSE 7860
55
  EXPOSE 8000
56
 
57
+ # Start supervisord to manage both React frontend and FastAPI backend
58
+ CMD ["supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]