FROM node:12 AS frontend_builder

WORKDIR /usr/src/app

# Add package.json and run npm install
# Its important to copy in package.json first to avoid caching issues
COPY frontend/package*.json ./
RUN npm ci

# Copy rest of the project and build
COPY frontend/ .
RUN npm run build

# Create new container using the tiny node-alpine linux image to use for our deployment
FROM node:12-alpine

# Open a port in the firewall
EXPOSE 8080

WORKDIR /usr/src/app

# Prepare backend
COPY backend/ .
RUN npm ci

# Copy our build result
COPY --from=frontend_builder /usr/src/app/build build

CMD [ "npm", "start" ]
