FROM python:3.12-slim

ARG PUID
ARG PGID
ARG ENV

ENV PYTHONUNBUFFERED 1

#RUN groupadd -g ${PGID} -o custom_user
#RUN useradd -m -u ${PUID} -g ${PGID} -o -s /bin/bash custom_user

# install requirements debian dependencies
RUN apt update && apt install -y curl inotify-tools mariadb-client ca-certificates gnupg wget lsb-release

# install lastest version of postgresql-client
RUN install -d /usr/share/postgresql-common/pgdg
RUN curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc
RUN echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list
RUN apt update && apt install -y postgresql-client-16

# install node 20
RUN mkdir -p /etc/apt/keyrings
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
RUN apt update && apt install nodejs -y
RUN npm install -g yarn

# clean apt cache
RUN find /var/cache/apt/archives /var/lib/apt/lists -not -name lock -type f -delete

# Setup python requirements
WORKDIR /app/requirements
COPY ./requirements/* ./
RUN python -m pip install --upgrade pip
RUN pip install -r ${ENV}.txt

#USER custom_user

# Setup node dependencies
WORKDIR /app/frontend
COPY ./frontend/package.json ./package.json
RUN yarn install

WORKDIR /app


