FROM node:18-alpine

LABEL maintainer="ImmichFrame"
LABEL description="Lightweight digital photo frame for Immich"

WORKDIR /app

# Copy package files first for better caching
COPY package.json ./

# Install dependencies
RUN npm install --production && npm cache clean --force

# Copy application
COPY server.js ./
COPY public/ ./public/

# Expose port
EXPOSE 3000

# Health check
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
  CMD wget -qO- http://localhost:3000/api/config || exit 1

# Run as non-root
RUN addgroup -g 1001 -S appgroup && \
    adduser -S appuser -u 1001 -G appgroup
USER appuser

CMD ["node", "server.js"]
