# Frontend Dockerfile - Vite React App
FROM node:20-alpine

WORKDIR /app

# Copy package files first (for better caching when only code changes)
COPY package*.json ./

# Install dependencies to a cache location (will be copied to volume on start)
RUN npm ci && cp -r node_modules /node_modules_cache

# Copy entrypoint script
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh

# Copy source code
COPY . .

# Expose Vite dev server port
EXPOSE 5173

# Use entrypoint to initialize node_modules volume if empty
ENTRYPOINT ["docker-entrypoint.sh"]

# Run Vite dev server (accessible from outside container)
CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0"]
