gabe-vazquez commited on
Commit
8e7b8ed
·
1 Parent(s): 5c28894

more docker changes

Browse files
Files changed (5) hide show
  1. .dockerignore +26 -0
  2. Dockerfile +35 -58
  3. docker-entrypoint.sh +12 -0
  4. frontend/tsconfig.json +2 -5
  5. supervisord.conf +20 -0
.dockerignore ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Dependencies
2
+ **/node_modules
3
+ **/__pycache__
4
+ **/*.pyc
5
+
6
+ # Build outputs
7
+ frontend/.next
8
+ frontend/out
9
+ **/*.pyo
10
+ **/*.pyd
11
+
12
+ # Environment and IDE
13
+ .env*
14
+ .vscode
15
+ .idea
16
+ *.swp
17
+ *.swo
18
+
19
+ # Git
20
+ .git
21
+ .gitignore
22
+
23
+ # Logs
24
+ **/logs
25
+ **/*.log
26
+ npm-debug.log*
Dockerfile CHANGED
@@ -1,79 +1,56 @@
1
- FROM node:20-slim as frontend-builder
2
-
3
- # Set working directory for frontend
4
- WORKDIR /app/frontend
5
-
6
- # Copy frontend files
7
- COPY frontend/package*.json ./
8
- RUN npm install
9
-
10
- COPY frontend/ ./
11
- RUN npm run build
12
-
13
- # Python backend stage
14
  FROM python:3.10-slim
15
 
 
 
16
  # Install system dependencies
17
  RUN apt-get update && apt-get install -y \
18
  build-essential \
19
  curl \
20
- gcc \
21
- g++ \
22
  git \
23
- python3-dev \
 
24
  && rm -rf /var/lib/apt/lists/*
25
 
26
- # Install Node.js for serving the frontend
27
- RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
28
  && apt-get install -y nodejs \
29
  && rm -rf /var/lib/apt/lists/*
30
 
31
- # Set working directory
32
- WORKDIR /app
33
-
34
- # Copy frontend build from previous stage
35
- COPY --from=frontend-builder /app/frontend/.next ./.next
36
- COPY --from=frontend-builder /app/frontend/public ./public
37
- COPY --from=frontend-builder /app/frontend/package*.json ./
38
 
39
- # Copy backend files
40
- COPY requirements.txt .
41
- COPY packages.txt .
42
- COPY app.py .
43
- COPY en.txt .
44
- COPY frankenstein5k.md .
45
- COPY gatsby5k.md .
46
 
47
- # Create constraints file for pre-built wheels
48
- RUN echo "spacy==3.7.2\n\
49
- numpy==1.26.4\n\
50
- Cython==0.29.37\n\
51
- --prefer-binary" > constraints.txt
52
 
53
- # Install Python dependencies
54
- RUN pip install --no-cache-dir --upgrade pip && \
55
- pip install --no-cache-dir -r requirements.txt -c constraints.txt
56
 
57
- # Install frontend runtime dependencies
58
- RUN npm install --production
59
 
60
- # Expose port
61
- EXPOSE 7860
 
 
 
62
 
63
- # Set environment variables
64
- ENV PYTHONUNBUFFERED=1
65
- ENV NODE_ENV=production
66
 
67
- # Start both services using a shell script
68
- COPY <<EOF ./start.sh
69
- #!/bin/bash
70
- # Start the Next.js frontend in the background
71
- npm start &
72
- # Start the Python backend
73
- python app.py
74
- EOF
75
 
76
- RUN chmod +x ./start.sh
 
 
77
 
78
- # Command to run both services
79
- CMD ["./start.sh"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  FROM python:3.10-slim
2
 
3
+ WORKDIR /app
4
+
5
  # Install system dependencies
6
  RUN apt-get update && apt-get install -y \
7
  build-essential \
8
  curl \
 
 
9
  git \
10
+ cmake \
11
+ pkg-config \
12
  && rm -rf /var/lib/apt/lists/*
13
 
14
+ # Install Node.js
15
+ RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
16
  && apt-get install -y nodejs \
17
  && rm -rf /var/lib/apt/lists/*
18
 
19
+ # Upgrade pip and install wheel
20
+ RUN pip install --no-cache-dir --upgrade pip setuptools wheel
 
 
 
 
 
21
 
22
+ # Install backend requirements
23
+ COPY backend/requirements.txt .
24
+ RUN pip install --no-cache-dir --prefer-binary -r requirements.txt
 
 
 
 
25
 
26
+ # Set up frontend
27
+ WORKDIR /app/frontend
 
 
 
28
 
29
+ # Install frontend dependencies
30
+ COPY frontend/package*.json ./
31
+ RUN npm install
32
 
33
+ # Copy all frontend files (except those in .dockerignore)
34
+ COPY frontend/ ./
35
 
36
+ # Set build environment
37
+ ENV NEXT_PUBLIC_API_URL=http://localhost:7860 \
38
+ NEXT_TELEMETRY_DISABLED=1 \
39
+ NODE_ENV=production \
40
+ DISABLE_ESLINT_PLUGIN=true
41
 
42
+ # Build frontend
43
+ RUN npm run build
 
44
 
45
+ # Set up backend and supervisor
46
+ WORKDIR /app
47
+ COPY backend/ ./backend/
48
+ COPY supervisord.conf /etc/supervisor/conf.d/
49
+ COPY docker-entrypoint.sh /
 
 
 
50
 
51
+ RUN pip install supervisor && \
52
+ mkdir -p /var/log/supervisor && \
53
+ chmod +x /docker-entrypoint.sh
54
 
55
+ EXPOSE 7860
56
+ ENTRYPOINT ["/docker-entrypoint.sh"]
docker-entrypoint.sh ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # If running in Hugging Face Spaces (SPACE_ID is set)
4
+ if [ -n "$SPACE_ID" ]; then
5
+ export NEXT_PUBLIC_API_URL="https://$SPACE_ID.hf.space"
6
+ else
7
+ # Local development
8
+ export NEXT_PUBLIC_API_URL="http://localhost:7860"
9
+ fi
10
+
11
+ # Start supervisor
12
+ exec supervisord -c /etc/supervisor/conf.d/supervisord.conf
frontend/tsconfig.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "compilerOptions": {
3
- "target": "ES2017",
4
  "lib": ["dom", "dom.iterable", "esnext"],
5
  "allowJs": true,
6
  "skipLibCheck": true,
@@ -18,11 +18,8 @@
18
  "name": "next"
19
  }
20
  ],
21
- "baseUrl": ".",
22
  "paths": {
23
- "@/*": ["src/*"],
24
- "@/lib/*": ["src/lib/*"],
25
- "@/components/*": ["src/components/*"]
26
  }
27
  },
28
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
 
1
  {
2
  "compilerOptions": {
3
+ "target": "es5",
4
  "lib": ["dom", "dom.iterable", "esnext"],
5
  "allowJs": true,
6
  "skipLibCheck": true,
 
18
  "name": "next"
19
  }
20
  ],
 
21
  "paths": {
22
+ "@/*": ["./src/*"]
 
 
23
  }
24
  },
25
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
supervisord.conf ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [supervisord]
2
+ nodaemon=true
3
+ user=root
4
+
5
+ [program:backend]
6
+ directory=/app/backend
7
+ command=uvicorn main:app --host 0.0.0.0 --port 7860
8
+ autostart=true
9
+ autorestart=true
10
+ stderr_logfile=/var/log/supervisor/backend.err.log
11
+ stdout_logfile=/var/log/supervisor/backend.out.log
12
+
13
+ [program:frontend]
14
+ directory=/app/frontend
15
+ command=npm start -- -p 7860
16
+ autostart=true
17
+ autorestart=true
18
+ stderr_logfile=/var/log/supervisor/frontend.err.log
19
+ stdout_logfile=/var/log/supervisor/frontend.out.log
20
+ environment=PORT=7860