ARG        AWS_ACCOUNT=086679231553

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

WORKDIR    /var/app

USER        root
# Update and install common packages
RUN        apt-get update && apt-get -y upgrade

# Create and configure virtualenv and uwsgi
ENV        VIRTUAL_ENV /var/venv
RUN        python3.13 -m venv $VIRTUAL_ENV
ENV        PATH "$VIRTUAL_ENV/bin:$PATH"
RUN        python -m pip install --upgrade pip setuptools wheel

# Add application and install requirements
COPY       requirements.txt ./

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

RUN         apt-get -y install uwsgi

RUN         apt-get -y install gcc \
            && pip install uwsgi===2.0.28 \
            && apt-get -y remove --purge gcc \
            && apt-get -y clean \
            && rm -rf /var/lib/apt/lists/*


ENV PYTHONPATH=/var/app

FROM       base AS deploy

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

WORKDIR /var/app/accounting/

CMD ["python", "producer.py"]

#################################
### 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-dev.txt

USER       worker

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