# This is nrao:notification
FROM python:3.10-slim-buster as base
ARG WS_VERSION=unknown-version

# Environment variables
ENV PIP_NO_CACHE_DIR false
ENV CAPO_PROFILE docker
ENV CAPO_PATH /home/ssa/capo

# Get postgres/mysql development stuff in the image
RUN apt update \
    && apt install -y --no-install-recommends \
    gcc \
    libmariadb-dev-compat \
    libpq-dev \
    && rm -rf /var/lib/apt/lists

# Create vlapipe group and create vlapipe user placed in vlapipe group
RUN addgroup --gid 6000 vlapipe && \
    useradd --create-home --comment "" --gid 6000 --uid 6000 vlapipe

# Create almapipe group and create almapipe user placed in almapipe group
RUN addgroup --gid 9233 almapipe && \
    useradd --create-home --comment "" --gid 9233 --uid 9233 almapipe

# Switch to appuser and set ownership of docker.properties to vlapipe and the vlapipe group
USER vlapipe
WORKDIR /home/ssa/capo
COPY --chown=vlapipe:vlapipe docker.properties docker.properties

USER root
WORKDIR /code/
RUN chown vlapipe . && chgrp vlapipe .
RUN apt update -y && apt install -y curl -y nano

# package installation
USER vlapipe
WORKDIR /packages/
ENV PATH "${PATH}:/home/vlapipe/.local/bin"
COPY --chown=vlapipe:vlapipe ./shared ./shared
COPY --chown=vlapipe:vlapipe ./apps/cli ./apps/cli
COPY --chown=vlapipe:vlapipe ./services/notification/requirements.txt ./requirements.txt
RUN SETUPTOOLS_SCM_PRETEND_VERSION=${WS_VERSION} pip install --user -r requirements.txt

# Copy service directory to /code in the image
# set ownership of content to vlapipe and the vlapipe group
WORKDIR /code
COPY --chown=vlapipe:vlapipe ./services/notification ./

FROM base as prod
ARG DEPLOY_ENV
ARG WS_VERSION=unknown-version

# Switch to vlapipe
ENV PYTHONPATH "${PYTHONPATH}:/home/vlapipe/.local"
RUN SETUPTOOLS_SCM_PRETEND_VERSION=${WS_VERSION} pip install -e .
CMD pserve --reload ${DEPLOY_ENV}.ini

FROM base as dev
ARG WS_VERSION=unknown-version
# Python library installation
RUN SETUPTOOLS_SCM_PRETEND_VERSION=${WS_VERSION} pip install -e .
CMD ["pserve", "--reload", "dev.ini"]