FROM node:latest AS build

WORKDIR /build

# Copy source files
COPY src src
COPY public public
COPY package.json package.json
COPY package-lock.json package-lock.json

# Install dependencies & build
RUN npm install
RUN npm run build

# Final image
FROM node:latest AS final
WORKDIR /app

EXPOSE 3000

# Install serve for serving
RUN npm install -g serve

# Copy build
COPY --from=build /build/build/ /app/

ENTRYPOINT [ "serve", "-s", "/app" ]