############
# build ui #
############

FROM node:lts-alpine AS build-ui

# some dir for our code
WORKDIR /app

# install dependencies
COPY ui/package*.json ui/yarn*.lock ./
RUN  yarn --production=false

# copy code
COPY ui .
RUN  yarn build


##############
# webservice #
##############

FROM antonapetrov/uvicorn-gunicorn:python3.9-alpine3.13 AS production

RUN set -ex; \
  # prerequisites
  apk add --no-cache \
    libmagic \
  ;

# env setup
ENV \
  PRODUCTION_MODE="true" \
  APP_MODULE="ovdashboard_api:app"

# install API
COPY api /usr/src/ovdashboard_api
RUN set -ex; \
  pip3 --no-cache-dir install /usr/src/ovdashboard_api;

# install UI
COPY --from=build-ui /app/dist /html