DigitalDB / Dockerfile
Mr-Thop's picture
Change Py files
3b4afe7
Raw
History Blame Contribute Delete
2.3 kB
# ── Stage 1: Build React frontend ────────────────────────────────────────────
FROM node:18-alpine AS frontend-build
# Build args for DB credentials (set as HF Space Secrets)
ARG DB_HOST
ARG DB_PORT
ARG DB_USER
ARG DB_PASSWORD
ARG DB_NAME
# Make them available as env vars for the Python scripts
ENV DB_HOST=$DB_HOST
ENV DB_PORT=$DB_PORT
ENV DB_USER=$DB_USER
ENV DB_PASSWORD=$DB_PASSWORD
ENV DB_NAME=$DB_NAME
RUN apk add --no-cache python3 py3-pip
WORKDIR /app/frontend
COPY frontend/package.json frontend/package-lock.json ./
RUN npm install --legacy-peer-deps
# Copy frontend source first
COPY frontend/ ./
# Copy Python scripts next to frontend so relative paths work correctly
COPY requirements.txt ./requirements.txt
COPY download_images.py ./download_images.py
COPY create_logo.py ./create_logo.py
# Install Python dependencies
RUN pip3 install --no-cache-dir --break-system-packages -r ./requirements.txt
# Ensure images directory exists (force recreate in case of stale file)
RUN rm -rf ./public/images && mkdir -p ./public/images
# Run logo generation (saves to frontend/public/images/)
RUN python3 ./create_logo.py
# Run image download (saves to frontend/public/images/)
RUN python3 ./download_images.py || echo "Image download partial - continuing"
# Verify images were created
RUN ls -la ./public/images/ || echo "No images found"
# Build React app (public/images/ is included automatically)
ENV REACT_APP_API_URL=/api
ENV CI=false
RUN npm run build
# ── Stage 2: Production image ─────────────────────────────────────────────────
FROM node:18-alpine
WORKDIR /app
# Copy backend deps and install
COPY package*.json ./
RUN npm install --omit=dev --legacy-peer-deps
# Copy backend source (explicitly exclude .env)
COPY src/ ./src/
# Copy built frontend from stage 1
COPY --from=frontend-build /app/frontend/build ./frontend/build
# Hugging Face Spaces requires port 7860
# These are set here so dotenv cannot override them
ENV PORT=7860
ENV NODE_ENV=production
EXPOSE 7860
CMD ["node", "src/server.js"]