🐳 Update Dockerfile
Browse files- Dockerfile +88 -0
Dockerfile
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Multi-stage Dockerfile for Hugging Face Spaces deployment
|
| 2 |
+
# Combines frontend and backend into a single container
|
| 3 |
+
|
| 4 |
+
# ============================================
|
| 5 |
+
# Stage 1: Build Frontend
|
| 6 |
+
# ============================================
|
| 7 |
+
FROM node:18-alpine AS frontend-builder
|
| 8 |
+
|
| 9 |
+
WORKDIR /app/frontend
|
| 10 |
+
|
| 11 |
+
# Copy frontend package files
|
| 12 |
+
COPY frontend/package*.json ./
|
| 13 |
+
|
| 14 |
+
# Install dependencies
|
| 15 |
+
RUN npm install --legacy-peer-deps
|
| 16 |
+
|
| 17 |
+
# Copy frontend source
|
| 18 |
+
COPY frontend/ ./
|
| 19 |
+
|
| 20 |
+
# Set build-time environment variable for API URL
|
| 21 |
+
ARG VITE_API_BASE_URL=/api
|
| 22 |
+
ENV VITE_API_BASE_URL=$VITE_API_BASE_URL
|
| 23 |
+
|
| 24 |
+
# Build frontend
|
| 25 |
+
RUN npm run build
|
| 26 |
+
|
| 27 |
+
# ============================================
|
| 28 |
+
# Stage 2: Build Backend
|
| 29 |
+
# ============================================
|
| 30 |
+
FROM maven:3.9.6-eclipse-temurin-17 AS backend-builder
|
| 31 |
+
|
| 32 |
+
WORKDIR /app/backend
|
| 33 |
+
|
| 34 |
+
# Copy pom.xml first for dependency caching
|
| 35 |
+
COPY backend/pom.xml ./
|
| 36 |
+
|
| 37 |
+
# Download dependencies
|
| 38 |
+
RUN mvn dependency:go-offline -B
|
| 39 |
+
|
| 40 |
+
# Copy backend source
|
| 41 |
+
COPY backend/src ./src
|
| 42 |
+
|
| 43 |
+
# Build backend (skip tests for faster build)
|
| 44 |
+
RUN mvn clean package -DskipTests
|
| 45 |
+
|
| 46 |
+
# ============================================
|
| 47 |
+
# Stage 3: Production Runtime
|
| 48 |
+
# ============================================
|
| 49 |
+
FROM eclipse-temurin:17-jre-jammy
|
| 50 |
+
|
| 51 |
+
WORKDIR /app
|
| 52 |
+
|
| 53 |
+
# Install nginx for serving frontend
|
| 54 |
+
RUN apt-get update && \
|
| 55 |
+
apt-get install -y nginx && \
|
| 56 |
+
rm -rf /var/lib/apt/lists/*
|
| 57 |
+
|
| 58 |
+
# Copy built frontend from frontend-builder stage
|
| 59 |
+
COPY --from=frontend-builder /app/frontend/dist /usr/share/nginx/html
|
| 60 |
+
|
| 61 |
+
# Copy nginx configuration
|
| 62 |
+
COPY frontend/nginx.conf /etc/nginx/conf.d/default.conf
|
| 63 |
+
|
| 64 |
+
# Copy built backend JAR
|
| 65 |
+
COPY --from=backend-builder /app/backend/target/*.jar /app/backend.jar
|
| 66 |
+
|
| 67 |
+
# Create a startup script
|
| 68 |
+
RUN cat > /app/start.sh << 'EOF'
|
| 69 |
+
#!/bin/bash
|
| 70 |
+
|
| 71 |
+
# Start nginx in background
|
| 72 |
+
nginx
|
| 73 |
+
|
| 74 |
+
# Start Spring Boot application in foreground
|
| 75 |
+
exec java -jar /app/backend.jar
|
| 76 |
+
EOF
|
| 77 |
+
|
| 78 |
+
RUN chmod +x /app/start.sh
|
| 79 |
+
|
| 80 |
+
# Hugging Face Spaces expects the app to run on port 7860
|
| 81 |
+
EXPOSE 7860
|
| 82 |
+
|
| 83 |
+
# Set environment variables
|
| 84 |
+
ENV SERVER_PORT=7860
|
| 85 |
+
ENV SPRING_PROFILES_ACTIVE=prod
|
| 86 |
+
|
| 87 |
+
# Start both nginx and Spring Boot
|
| 88 |
+
CMD ["/app/start.sh"]
|