# Dockerfile

ARG         AWS_ACCOUNT=086679231553

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

WORKDIR     /var/app

USER        root

# Install common packages
RUN         apt update -y
RUN         apt install -y zip libffi-dev gcc

# Install Supervisord
RUN         apt install -y supervisor

# Explicitly set locale and related env vars to use en_US.UTF-8
RUN         apt install -y locales
RUN         localedef -c -f UTF-8 -i en_US en_US.UTF-8
ENV         LC_ALL=en_US.UTF-8
ENV         LANG=en_US.UTF-8

# Create and configure virtualenv
ENV         VIRTUAL_ENV=/var/venv
RUN         python3.11 -m venv ${VIRTUAL_ENV}
ENV         PATH="$VIRTUAL_ENV/bin:$PATH"

# Install requirements
COPY        reqs.pip ./
RUN         pip install --upgrade pip setuptools
RUN         pip install -I -r reqs.pip

# Add application
ADD         . /var/app

# Install local application
RUN         pip install .

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


#######################################
### Build image for live deployment ###
#######################################
FROM        base AS deploy

RUN         apt purge gcc -y

# Remove tests, scripts, etc.
RUN         rm -rf /var/app/tests/ /var/app/.flake8 /var/app/scripts

# Run supervisord
USER        worker
ENTRYPOINT  ["/usr/bin/supervisord", "-c", "conf/supervisor.conf"]

EXPOSE 9001


#################################
### Build image for unit-lint ###
#################################
FROM        base AS unit-lint

# Install test requirements
RUN         pip install -r reqs-test.pip

ENTRYPOINT  ["scripts/unit-lint.sh"]
