# Defines a production image for the Argus API server
# with an optional all-plugins target
# Needs the repository root directory as its context:
#
# If you're in the same directory as this Dockerfile try:
#   docker build -f Dockerfile ..
#
# If you're in the repository root try:
#   docker build -f docker/Dockerfile .

FROM python:3.13-trixie AS base
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y --no-install-recommends tini build-essential

ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

# Install some dev requirements that aren't part of the minimal dependencies:
RUN pip install "psycopg[binary]" django-extensions python-dotenv gunicorn

# Make an unprivileged user to run the server
RUN useradd --system argus
# Ensure this user has privileges to collect static resources in /static
RUN mkdir -p /static && chown argus /static
ENV STATIC_ROOT=/static

COPY . /src
RUN pip install '/src' && rm -rf /src

# Install API backend settings suitable for Docker deployment
RUN mkdir /extrapython
COPY docker/dockersettings.py /extrapython/
ENV PYTHONPATH=/extrapython
ENV DJANGO_SETTINGS_MODULE=dockersettings

ENV PORT=8000
EXPOSE 8000
COPY docker/cmd-argus.sh /cmd-argus.sh
COPY docker/cmd-dbqueue.sh /cmd-dbqueue.sh
USER argus
ENTRYPOINT ["/usr/bin/tini", "-v", "--"]
CMD ["/cmd-argus.sh"]

# ── all-plugins target ──────────────────────────────
# Includes all Sikt-maintained notification and ticket plugins
FROM base AS all-plugins
USER root
RUN pip install \
    argus-ticket-github \
    argus-ticket-gitlab \
    argus-ticket-jira \
    argus-ticket-rt \
    argus-notification-msteams
USER argus
