# Dockerfile

ARG         AWS_ACCOUNT=086679231553

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

WORKDIR     /var/app

USER        root

# Update and install common packages
RUN         apt-get update && apt-get -y upgrade
RUN         apt-get -y install zip libffi-dev gcc

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

RUN         pip install --upgrade pip setuptools

RUN         apt-get -y install --upgrade pip

RUN         mkdir /var/.snowflake

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


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

# Setup UWSGI
RUN         apt-get -y install uwsgi
RUN         useradd uwsgi -s /bin/false
RUN         pip install uwsgi==2.0.23

# Add startup script
ADD         uwsgi-start.sh /
RUN         chmod +x /uwsgi-start.sh
ENTRYPOINT  ["/uwsgi-start.sh"]

EXPOSE      8080


###########################
### Build image for dev ###
###########################
FROM        base AS dev

# httpretty install complains about some unicode error without this
ENV         LC_ALL=en_US.utf-8
ENV         LC_CTYPE=en_US.UTF-8

COPY        requirements-dev.txt .
RUN         pip install -r /var/app/requirements-dev.txt

# Enables prints in python to flush to stdout
ENV         PYTHONUNBUFFERED 1
# Start dev server
ENTRYPOINT  ["/var/venv/bin/python"]
CMD         ["dev.py", "2>&1"]


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

# Install dev/test requirements
COPY        requirements-dev.txt .
RUN         pip install -r /var/app/requirements-dev.txt

# Copy files requireed to run linting and unit tests
COPY        scripts/lint-and-test.sh ./scripts/lint-and-test.sh

ENTRYPOINT ["scripts/lint-and-test.sh"]


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

# Copy files required to integration tests
COPY        tests tests/
COPY        scripts/integration.sh ./scripts/integration.sh

ENTRYPOINT ["scripts/integration.sh"]
