Agromind-backend / backend /Dockerfile
gh-action-hf-auto
auto: sync backend from github@32fb9685
8a6248c
# Backend Dockerfile (HF Spaces compatible)
FROM node:20-alpine as base
WORKDIR /app
# Install dependencies for native modules + wget for healthcheck
RUN apk add --no-cache python3 make g++ wget
# Copy package files
COPY package*.json ./
# ========================
# Development stage
# ========================
FROM base as development
RUN npm ci
COPY . .
EXPOSE 7860
CMD ["npm", "run", "dev"]
# ========================
# Production stage
# ========================
FROM base as production
ENV NODE_ENV=production
# Install production dependencies only
RUN npm ci --omit=dev
# Copy source files
COPY . .
# Create non-root user (uid 1000 required by HF Spaces)
RUN set -ex && \
if ! getent group 1000 > /dev/null 2>&1; then \
addgroup -g 1000 -S nodejs; \
fi && \
GROUP_NAME=$(getent group 1000 | cut -d: -f1) && \
if ! getent passwd 1000 > /dev/null 2>&1; then \
adduser -D -u 1000 -G ${GROUP_NAME} nodejs; \
fi && \
chown -R 1000:1000 /app
USER 1000
# EXPOSE is informational (HF ignores it but safe to keep)
EXPOSE 7860
# Healthcheck probes backend on port 7860
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:7860/health || exit 1
CMD ["node", "server.js"]