## 1. Builder
# Use nodejs 16
FROM node:16-alpine AS builder

# Load repository into container
WORKDIR /frontend
COPY . .

# Setup development environment
RUN apk add --no-cache git

# Install and compress node_modules
RUN rm -rf node_modules
RUN mkdir node_modules
RUN npm ci

# Build templates
RUN npm run build
RUN cp package.json ./build/
RUN cp -r node_modules ./build/
RUN ls -lh ./build

## 2. Regroup
FROM node:16-alpine
RUN apk add --no-cache ca-certificates

# Bring data over from builder
WORKDIR /frontend
COPY --from=builder /frontend/build /frontend
ENV NODE_ENV=production

# Entry point
CMD ["/usr/local/bin/node", "index.js"]
