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

USER root

# Update and install common packages
RUN apt-get -y update \
  && apt-get -y upgrade \
  && apt-get -y install gcc \
  && apt-get -y clean \
  && rm -rf /var/lib/apt/lists/*

USER worker

# Create and configure virtualenv
WORKDIR /var/venv
ENV VIRTUAL_ENV=/var/venv
RUN python3.13 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
RUN /var/venv/bin/pip install --upgrade pip setuptools requests-futures

# Add application and install requirements
WORKDIR /var/app
COPY --chown=worker . /var/app
RUN /var/venv/bin/pip install -I -r /var/app/requirements.txt
RUN /var/venv/bin/pip install .
ENV PYTHONPATH=/var/app

# Explicitly set locale and related env vars to use not default POSIX, but en_US.utf8
ENV LC_ALL=en_US.utf8
ENV LANG=en_US.utf8

RUN mkdir /tmp/elasticsearch_export && \
 mkdir /tmp/feed_workspace && \
 chmod 755 /tmp/feed_workspace && \
 chmod -R 755 /var/app/scripts/

#
FROM base AS deploy

USER root

RUN /var/venv/bin/pip install supervisor

RUN mkdir /efs && \
    chown -R worker:worker /efs

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

USER worker
ENTRYPOINT ["/var/venv/bin/supervisord", "-c", "conf/supervisor.conf"]
EXPOSE 9001

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

# Install dev/test requirements
RUN /var/venv/bin/pip install -I -r /var/app/requirements-test.txt
USER       worker
ENTRYPOINT ["scripts/unit-lint.sh"]

#################################
### Build image for exec jobs ###
#################################
FROM base AS exec

USER worker
ENV RELOAD=bool_value
ENV WAIT_UNTIL_COMPLETE=bool_value

ENTRYPOINT ["scripts/exec.sh"]
