FROM nvidia/cuda:12.2.0-runtime-ubuntu22.04 AS requirements
RUN apt-get update
RUN apt-get upgrade -y
RUN apt install -y python3-pip
ENV TOKENIZERS_PARALLELISM=false
COPY requirements.txt /requirements.txt
RUN pip3 install -r /requirements.txt
RUN rm -rf /requirements.txt

FROM requirements AS sia-test
COPY ./ /root/sia/
WORKDIR /root/sia/
RUN mkdir -p /root/model
CMD ["python3", "-m", "unittest", "discover", "-v", "-p", "*test.py"]

FROM node:20-alpine AS web-test
WORKDIR /app
COPY web/package*.json ./
RUN npm install
COPY web .
RUN npm test

FROM node:20-alpine AS web-build
WORKDIR /app
COPY web/package*.json ./
RUN npm install
COPY web .
RUN npm run build

FROM requirements
COPY ./ /root/sia/
COPY --from=web-build /app/dist /root/sia/static/
WORKDIR /root/sia

ENTRYPOINT ["python3", "-m", "sia"]