Unmask / Dockerfile
PixelNavigation's picture
Updated the docker file to support static + copy dynamic
c73181c
Raw History Blame Contribute Delete
2.32 kB
# ---------- Stage 1: Build Next.js / React frontend ----------
FROM node:18 AS frontend-builder
WORKDIR /frontend
# Install deps
COPY frontend/package*.json ./
RUN npm install
# Copy source
COPY frontend/ .
# Build (Next.js, CRA, or Vite)
RUN npm run build
# Try Next.js static export if script or config supports it (ignore failure)
RUN npm run export || true
# Normalize build output into /frontend_build
# Priority: out (next export) > dist (vite) > build (CRA) > .next (Next.js server build + public)
RUN set -eux; \
mkdir -p /frontend_build; \
if [ -d out ]; then \
echo "Using Next.js static export (out)"; cp -R out/* /frontend_build/; \
elif [ -d dist ]; then \
echo "Using Vite dist"; cp -R dist/* /frontend_build/; \
elif [ -d build ]; then \
echo "Using CRA build"; cp -R build/* /frontend_build/; \
elif [ -d .next ]; then \
echo "Using Next.js server build (.next) (NOTE: For full static hosting, enable next export)"; \
cp -R .next /frontend_build/.next; \
[ -d public ] && cp -R public /frontend_build/public || true; \
else \
echo "No recognized frontend build output (out/dist/build/.next) found." >&2; exit 1; \
fi
# ---------- Stage 2: Backend (Flask + Gunicorn) ----------
FROM python:3.10-slim
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential git wget curl ffmpeg libglib2.0-0 libsm6 libxext6 libxrender1 \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Writable cache locations (avoid /.cache PermissionError)
ENV HF_HOME=/tmp/.cache/huggingface \
TORCH_HOME=/tmp/.cache/torch \
TIMM_CACHE_DIR=/tmp/.cache/timm \
XDG_CACHE_HOME=/tmp/.cache \
HF_HUB_CACHE=/tmp/.cache/huggingface \
TRANSFORMERS_CACHE=/tmp/.cache/huggingface \
NO_ALBUMENTATIONS_UPDATE=1
RUN mkdir -p /tmp/.cache/huggingface /tmp/.cache/torch /tmp/.cache/timm
# Backend deps
COPY backend/requirements.txt ./backend/requirements.txt
RUN pip install --no-cache-dir -r backend/requirements.txt
# Copy backend
COPY backend/ ./backend
# Copy normalized frontend build into static assets
COPY --from=frontend-builder /frontend_build ./backend/static
WORKDIR /app/backend
EXPOSE 7860
CMD ["gunicorn", "app:app", "--bind", "0.0.0.0:7860", "--workers", "2", "--timeout", "180"]