FROM node:22-alpine AS node

WORKDIR /app

COPY site/package*.json ./

RUN npm ci

COPY site/ ./

RUN npm run build

FROM python:3.12.0-slim AS python

LABEL org.opencontainers.image.title="Dynavera - An Agentic Approach to Role-Specific Trainers"
LABEL org.opencontainers.image.source="https://git.cs.bham.ac.uk/projects-2025-26/vxn217"
LABEL org.opencontainers.image.description="Dynavera (Final Year Project)"

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

WORKDIR /app

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

COPY requirements/django.txt .
RUN pip install --no-cache-dir -r django.txt

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

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

RUN mkdir -p /app/static

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

ENTRYPOINT ["/start"]