FROM node:22-alpine AS node

WORKDIR /app

COPY package*.json ./
RUN npm ci

COPY src ./src
COPY index.html .
COPY vite.config.* .
COPY tsconfig.* .

RUN npm run build

FROM python:3.12-bookworm as python

RUN apt-get update && apt-get install --no-install-recommends -y \
	build-essential \
	libpq-dev \
	&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
	&& rm -rf /var/lib/apt/lists/*

COPY requirements/* .
RUN pip install --no-cache-dir --requirement local.txt

WORKDIR /app

COPY manage.py manage.py
COPY config config
COPY apps apps

COPY --from=node /app/build ./build

COPY ./compose/prod/start /start
RUN sed -i 's/\r$//g' /start
RUN chmod +x /start

ENTRYPOINT ["/start"]