FROM node:20-alpine AS server-deps
WORKDIR /app/server
COPY server/package.json ./
RUN npm install --production

FROM nginx:alpine AS runtime
RUN apk add --no-cache nodejs npm
COPY --from=server-deps /app/server/node_modules /app/server/node_modules
COPY server/index.js /app/server/
COPY client/ /usr/share/nginx/html/
COPY nginx/nginx.conf /etc/nginx/nginx.conf
RUN rm -f /etc/nginx/conf.d/default.conf
EXPOSE 8000
ENTRYPOINT ["/bin/sh", "-c", "node /app/server/index.js & exec nginx -g 'daemon off;'"]