Spaces:
Build error
Build error
Commit
·
71c7b3c
1
Parent(s):
c12d51a
update
Browse files- Dockerfile +28 -23
- docker-compose.yml +34 -6
- requirements.txt +13 -0
- scripts/start.sh +5 -16
Dockerfile
CHANGED
@@ -1,57 +1,62 @@
|
|
1 |
# Multi-stage Dockerfile to run both frontend (Next.js) and backend (FastAPI) in a single container
|
2 |
|
3 |
-
# 1
|
4 |
FROM node:20-bullseye AS frontend-builder
|
5 |
WORKDIR /app/frontend
|
6 |
ENV NEXT_TELEMETRY_DISABLED=1
|
7 |
|
8 |
-
#
|
9 |
-
COPY metsa-frontend/package
|
10 |
-
|
|
|
11 |
|
12 |
-
# Copy
|
13 |
COPY metsa-frontend/ .
|
14 |
-
RUN npm run build && npm run export
|
15 |
|
16 |
-
#
|
|
|
|
|
|
|
17 |
FROM node:20-bullseye AS runtime
|
18 |
WORKDIR /app
|
19 |
ENV NODE_ENV=production
|
20 |
ENV NEXT_TELEMETRY_DISABLED=1
|
21 |
|
22 |
-
# Install Python and build tools
|
23 |
RUN apt-get update \
|
24 |
&& apt-get install -y --no-install-recommends \
|
25 |
python3 python3-pip python3-venv \
|
26 |
build-essential python3-dev libffi-dev libssl-dev \
|
27 |
&& rm -rf /var/lib/apt/lists/*
|
28 |
|
29 |
-
#
|
30 |
-
|
31 |
-
COPY metsa-backend/ ./metsa-backend/
|
32 |
RUN python3 -m venv /app/venv \
|
33 |
&& . /app/venv/bin/activate \
|
34 |
&& pip install --upgrade pip \
|
35 |
&& pip install --no-cache-dir -r metsa-backend/requirements.txt
|
36 |
|
37 |
-
#
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
-
#
|
41 |
-
# Copy Next.js exported static site into backend-served directory
|
42 |
-
WORKDIR /app
|
43 |
COPY --from=frontend-builder /app/frontend/out ./metsa-frontend/out
|
44 |
|
45 |
-
#
|
46 |
-
WORKDIR /app
|
47 |
COPY scripts/start.sh ./scripts/start.sh
|
48 |
RUN chmod +x ./scripts/start.sh
|
49 |
|
50 |
-
#
|
51 |
-
EXPOSE 8000
|
52 |
-
|
53 |
-
# API URL used by frontend static site
|
54 |
ENV NEXT_PUBLIC_API_URL="http://localhost:8000/api/v1"
|
|
|
55 |
|
56 |
-
|
|
|
57 |
|
|
|
|
|
|
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 package files (ensure package-lock.json exists)
|
9 |
+
COPY metsa-frontend/package.json ./package.json
|
10 |
+
# Generate package-lock.json if it doesn't exist
|
11 |
+
RUN npm install
|
12 |
|
13 |
+
# Copy all frontend source files
|
14 |
COPY metsa-frontend/ .
|
|
|
15 |
|
16 |
+
# Build the Next.js app (with static export configured in next.config.ts)
|
17 |
+
RUN npm run build
|
18 |
+
|
19 |
+
# Stage 2: Final runtime with Node + Python
|
20 |
FROM node:20-bullseye AS runtime
|
21 |
WORKDIR /app
|
22 |
ENV NODE_ENV=production
|
23 |
ENV NEXT_TELEMETRY_DISABLED=1
|
24 |
|
25 |
+
# Install Python and required build tools
|
26 |
RUN apt-get update \
|
27 |
&& apt-get install -y --no-install-recommends \
|
28 |
python3 python3-pip python3-venv \
|
29 |
build-essential python3-dev libffi-dev libssl-dev \
|
30 |
&& rm -rf /var/lib/apt/lists/*
|
31 |
|
32 |
+
# Backend setup - create venv and install dependencies
|
33 |
+
COPY metsa-backend/requirements.txt ./metsa-backend/requirements.txt
|
|
|
34 |
RUN python3 -m venv /app/venv \
|
35 |
&& . /app/venv/bin/activate \
|
36 |
&& pip install --upgrade pip \
|
37 |
&& pip install --no-cache-dir -r metsa-backend/requirements.txt
|
38 |
|
39 |
+
# Copy backend code
|
40 |
+
COPY metsa-backend/ ./metsa-backend/
|
41 |
+
|
42 |
+
# Ensure uploads directory exists with proper subdirectories
|
43 |
+
RUN mkdir -p metsa-backend/uploads/commercial \
|
44 |
+
&& mkdir -p metsa-backend/uploads/compliance \
|
45 |
+
&& mkdir -p metsa-backend/uploads/other
|
46 |
|
47 |
+
# Copy Next.js static export from builder stage
|
|
|
|
|
48 |
COPY --from=frontend-builder /app/frontend/out ./metsa-frontend/out
|
49 |
|
50 |
+
# Copy and prepare startup script
|
|
|
51 |
COPY scripts/start.sh ./scripts/start.sh
|
52 |
RUN chmod +x ./scripts/start.sh
|
53 |
|
54 |
+
# Set environment variables
|
|
|
|
|
|
|
55 |
ENV NEXT_PUBLIC_API_URL="http://localhost:8000/api/v1"
|
56 |
+
ENV PYTHONPATH=/app/metsa-backend
|
57 |
|
58 |
+
# Expose port
|
59 |
+
EXPOSE 8000
|
60 |
|
61 |
+
# Start the application
|
62 |
+
CMD ["/bin/bash", "/app/scripts/start.sh"]
|
docker-compose.yml
CHANGED
@@ -1,15 +1,43 @@
|
|
1 |
-
version:
|
|
|
2 |
services:
|
3 |
app:
|
4 |
-
build:
|
5 |
-
|
|
|
6 |
ports:
|
7 |
- "8000:8000"
|
8 |
environment:
|
|
|
9 |
- NEXT_PUBLIC_API_URL=http://localhost:8000/api/v1
|
10 |
-
-
|
11 |
-
-
|
|
|
|
|
12 |
volumes:
|
13 |
- ./metsa-backend/uploads:/app/metsa-backend/uploads
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
|
|
|
|
|
|
|
1 |
+
version: '3.8'
|
2 |
+
|
3 |
services:
|
4 |
app:
|
5 |
+
build:
|
6 |
+
context: .
|
7 |
+
dockerfile: Dockerfile
|
8 |
ports:
|
9 |
- "8000:8000"
|
10 |
environment:
|
11 |
+
- NODE_ENV=production
|
12 |
- NEXT_PUBLIC_API_URL=http://localhost:8000/api/v1
|
13 |
+
- DATABASE_URL=mongodb://mongo:27017/metsa
|
14 |
+
- SECRET_KEY=your-secret-key-change-in-production
|
15 |
+
- ALGORITHM=HS256
|
16 |
+
- ACCESS_TOKEN_EXPIRE_MINUTES=30
|
17 |
volumes:
|
18 |
- ./metsa-backend/uploads:/app/metsa-backend/uploads
|
19 |
+
- ./metsa-backend/.env:/app/metsa-backend/.env
|
20 |
+
depends_on:
|
21 |
+
- mongo
|
22 |
+
networks:
|
23 |
+
- metsa-network
|
24 |
+
|
25 |
+
mongo:
|
26 |
+
image: mongo:7.0
|
27 |
+
ports:
|
28 |
+
- "27017:27017"
|
29 |
+
volumes:
|
30 |
+
- mongo-data:/data/db
|
31 |
+
environment:
|
32 |
+
- MONGO_INITDB_ROOT_USERNAME=admin
|
33 |
+
- MONGO_INITDB_ROOT_PASSWORD=admin123
|
34 |
+
- MONGO_INITDB_DATABASE=metsa
|
35 |
+
networks:
|
36 |
+
- metsa-network
|
37 |
+
|
38 |
+
volumes:
|
39 |
+
mongo-data:
|
40 |
|
41 |
+
networks:
|
42 |
+
metsa-network:
|
43 |
+
driver: bridge
|
requirements.txt
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastapi==0.104.1
|
2 |
+
uvicorn==0.24.0
|
3 |
+
pymongo==4.5.0
|
4 |
+
motor==3.3.2
|
5 |
+
python-jose[cryptography]==3.3.0
|
6 |
+
passlib[bcrypt]==1.7.4
|
7 |
+
python-multipart==0.0.6
|
8 |
+
python-dotenv==1.0.0
|
9 |
+
pydantic==2.4.2
|
10 |
+
pydantic[email]==2.4.2
|
11 |
+
pydantic-settings==2.0.3
|
12 |
+
aiofiles==23.2.1
|
13 |
+
python-dateutil==2.8.2
|
scripts/start.sh
CHANGED
@@ -1,18 +1,7 @@
|
|
1 |
-
#!/
|
2 |
-
set -
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
# Run backend (FastAPI) in background on :8000
|
8 |
-
# Note: Using 0.0.0.0 so it's reachable from the frontend container process
|
9 |
cd /app/metsa-backend
|
10 |
-
uvicorn app.main:app --host 0.0.0.0 --port 8000
|
11 |
-
BACK_PID=$!
|
12 |
-
cd /app
|
13 |
-
|
14 |
-
echo "Backend started with PID ${BACK_PID}"
|
15 |
-
|
16 |
-
# We now serve the frontend statically from FastAPI (same port). Nothing else to run here.
|
17 |
-
wait ${BACK_PID}
|
18 |
-
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|