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

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

RUN apt-get -y install zip libffi-dev gcc locales locales-all

# Add Supervisord
RUN apt-get -y install supervisor

# Set locale
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
ADD        . /var/app

RUN        rm -rf env
RUN        python3.11 -m venv env
ENV        PATH "/var/app/env/bin:$PATH"

RUN        pip install --upgrade pip
RUN        pip install -I -r /var/app/requirements.txt

RUN        chown -R worker:worker /var/app
RUN        chown -R worker:worker /var/run/

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

USER worker
EXPOSE 9001
CMD ["/usr/bin/supervisord", "-c", "/var/app/conf/supervisord.conf"]


#################################
### Build image for lint-and-test ###
#################################
FROM base AS lint-and-test

RUN pip install -I -r /var/app/requirements-dev.txt
RUN chmod 755 /var/app/lint-and-test.sh

ENTRYPOINT ["bash", "/var/app/lint-and-test.sh"]
