muhammadnoman76 commited on
Commit
cd3b571
·
1 Parent(s): 8d1fed3
.dockerignore ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Git
2
+ .git
3
+ .gitignore
4
+
5
+ # Node modules
6
+ node_modules
7
+ npm-debug.log*
8
+ yarn-debug.log*
9
+ yarn-error.log*
10
+
11
+ # Next.js
12
+ .next/
13
+ out/
14
+ build/
15
+
16
+ # Python
17
+ __pycache__/
18
+ *.py[cod]
19
+ *$py.class
20
+ *.so
21
+ .Python
22
+ env/
23
+ venv/
24
+ .venv/
25
+ pip-log.txt
26
+ pip-delete-this-directory.txt
27
+
28
+ # IDE
29
+ .vscode/
30
+ .idea/
31
+ *.swp
32
+ *.swo
33
+
34
+ # OS
35
+ .DS_Store
36
+ Thumbs.db
37
+
38
+ # Logs
39
+ *.log
40
+
41
+ # Environment files (will be copied explicitly)
42
+ .env*
43
+ !.env.example
44
+
45
+ # Cache
46
+ .cache/
47
+ .npm/
48
+ .eslintcache
49
+
50
+ # Coverage
51
+ coverage/
52
+ .nyc_output/
53
+
54
+ # Documentation
55
+ *.md
56
+ !README.md
57
+
58
+ # Temporary files
59
+ *.tmp
60
+ *.temp
.vscode/settings.json ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ {
2
+ }
Dockerfile CHANGED
@@ -1,63 +1,69 @@
1
- # Multi-stage Dockerfile to run both frontend (Next.js) and backend (FastAPI) in a single container
 
2
 
3
- # Stage 1: Build the Next.js frontend as static export
4
- FROM node:20-bullseye AS frontend-builder
5
  WORKDIR /app/frontend
6
- ENV NEXT_TELEMETRY_DISABLED=1
7
 
8
- # Copy BOTH package.json and package-lock.json explicitly
9
- COPY metsa-frontend/package.json ./package.json
10
- COPY metsa-frontend/package-lock.json ./package-lock.json
11
 
12
- # Install dependencies with npm ci
13
- RUN npm ci
14
 
15
- # Copy all frontend source files
16
- COPY metsa-frontend/ .
17
 
18
- # Build Next.js (output: 'export' is already in next.config.ts, so it will create /out directory)
19
  RUN npm run build
20
 
21
- # Stage 2: Final runtime with Node + Python
22
- FROM node:20-bullseye AS runtime
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  WORKDIR /app
24
- ENV NODE_ENV=production
25
- ENV NEXT_TELEMETRY_DISABLED=1
26
-
27
- # Install Python and required build tools
28
- RUN apt-get update \
29
- && apt-get install -y --no-install-recommends \
30
- python3 python3-pip python3-venv \
31
- build-essential python3-dev libffi-dev libssl-dev \
32
- && rm -rf /var/lib/apt/lists/*
33
-
34
- # Backend setup - create venv and install dependencies
35
- COPY metsa-backend/requirements.txt ./metsa-backend/requirements.txt
36
- RUN python3 -m venv /app/venv \
37
- && . /app/venv/bin/activate \
38
- && pip install --upgrade pip \
39
- && pip install --no-cache-dir -r metsa-backend/requirements.txt
40
-
41
- # Copy backend code
42
- COPY metsa-backend/ ./metsa-backend/
43
-
44
- # Ensure uploads directory exists with proper subdirectories
45
- RUN mkdir -p metsa-backend/uploads/commercial \
46
- && mkdir -p metsa-backend/uploads/compliance \
47
- && mkdir -p metsa-backend/uploads/other
48
-
49
- # Copy Next.js static export from builder stage
50
- COPY --from=frontend-builder /app/frontend/out ./metsa-frontend/out
51
-
52
- # Copy and prepare startup script
53
- COPY scripts/start.sh ./scripts/start.sh
54
- RUN chmod +x ./scripts/start.sh
55
-
56
- # Set Python path
57
- ENV PYTHONPATH=/app/metsa-backend
58
-
59
- # Expose port
60
  EXPOSE 8000
61
 
62
  # Start the application
63
- CMD ["/bin/bash", "/app/scripts/start.sh"]
 
1
+ # Multi-stage build for the application
2
+ FROM node:18-alpine AS frontend-builder
3
 
4
+ # Set working directory for frontend build
 
5
  WORKDIR /app/frontend
 
6
 
7
+ # Copy frontend package files
8
+ COPY metsa-frontend/package*.json ./
 
9
 
10
+ # Install frontend dependencies
11
+ RUN npm install --force
12
 
13
+ # Copy frontend source code
14
+ COPY metsa-frontend/ ./
15
 
16
+ # Build frontend
17
  RUN npm run build
18
 
19
+ # Python dependencies stage
20
+ FROM python:3.11-slim AS python-deps
21
+
22
+ # Install system dependencies
23
+ RUN apt-get update && apt-get install -y \
24
+ gcc \
25
+ && rm -rf /var/lib/apt/lists/*
26
+
27
+ # Set working directory
28
+ WORKDIR /app
29
+
30
+ # Copy backend requirements
31
+ COPY requirements.txt ./
32
+
33
+ # Install Python dependencies
34
+ RUN pip install --no-cache-dir -r requirements.txt
35
+
36
+ # Final stage - Python runtime
37
+ FROM python:3.11-slim
38
+
39
+ # Install only runtime dependencies
40
+ RUN apt-get update && apt-get install -y \
41
+ libpq5 \
42
+ && rm -rf /var/lib/apt/lists/*
43
+
44
+ # Set working directory
45
  WORKDIR /app
46
+
47
+ # Copy installed packages from python-deps stage
48
+ COPY --from=python-deps /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
49
+ COPY --from=python-deps /usr/local/bin /usr/local/bin
50
+
51
+ # Copy backend application code
52
+ COPY metsa-backend/ ./
53
+
54
+ # Copy built frontend files from the builder stage to static directory
55
+ COPY --from=frontend-builder /app/frontend/out ./static
56
+
57
+ # Create uploads directory structure
58
+ RUN mkdir -p uploads/commercial \
59
+ && mkdir -p uploads/compliance \
60
+ && mkdir -p uploads/other
61
+
62
+ # Set environment variable for port
63
+ ENV PORT=8000
64
+
65
+ # Expose the port
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  EXPOSE 8000
67
 
68
  # Start the application
69
+ CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
scripts/build_frontend.sh DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
-
4
- cd /app/metsa-frontend
5
- export NEXT_TELEMETRY_DISABLED=1
6
- npm ci
7
- npm run build
8
- # Remove the npm run export line - not needed with output: 'export'
 
 
 
 
 
 
 
 
 
scripts/start.sh DELETED
@@ -1,7 +0,0 @@
1
- #!/bin/bash
2
- set -e
3
-
4
- echo "Starting FastAPI backend..."
5
- . /app/venv/bin/activate
6
- cd /app/metsa-backend
7
- exec python -m uvicorn app.main:app --host 0.0.0.0 --port 8000