ARG         AWS_ACCOUNT=086679231553

FROM        ${AWS_ACCOUNT}.dkr.ecr.us-east-1.amazonaws.com/docker-parent-images:python311 AS base

ENV APP_DIR /var/app

WORKDIR ${APP_DIR}

USER root

# Update and install common packages
RUN         apt update
RUN         apt upgrade -y

RUN         apt install -y which curl git tar zip openssl
RUN         apt install -y default-jre build-essential supervisor

ADD         . ${APP_DIR}

# Explicitly set locale and related env vars to use not default POSIX, but en_US.UTF-8
RUN         apt install -y locales
RUN         locale-gen en_US.UTF-8
ENV         LC_ALL=en_US.UTF-8
ENV         LANG=en_US.UTF-8

RUN         pip3.11 install setuptools
RUN         pip3.11 install -r requirements.txt
RUN         pip3.11 install -e .

# Add tmp workspace
RUN         mkdir /tmp/activity_workspace
RUN         chmod 755 /tmp/activity_workspace


# Build main image
FROM base as main

COPY --from=base ${APP_DIR} ${APP_DIR}

# Run supervisord
ENTRYPOINT  ["/usr/bin/supervisord", "-c", "conf/activity_detector_supervisor.conf"]
EXPOSE      9001

# Build tests image
FROM base as tests

COPY --from=base ${APP_DIR} ${APP_DIR}

RUN  pip3.11 --no-cache-dir install -r requirements-test.txt
