# Dockerfile

ARG         AWS_ACCOUNT=086679231553

FROM        086679231553.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 -y update
RUN         apt-get -y install zip libffi-dev gcc

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

# Add SNOWFLAKE_HOME location
RUN         mkdir /var/.snowflake

RUN         pip install --upgrade pip && \
            pip install uwsgi
RUN         useradd uwsgi -s /bin/false
RUN         chown -R uwsgi:uwsgi /var/.snowflake

# Add application and install requirements
COPY        requirements.txt ./
RUN         pip install -r requirements.txt

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

# Remove tests
RUN         rm -rf /var/app/tests

# Add startup script
COPY        uwsgi-start.sh /
COPY        sound_recordings/ ./sound_recordings
COPY        application.py uwsgi.ini ./

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

COPY        spec/ ./spec
COPY        dev.py application.py ./

# Enables prints in python to flush to stdout
ENV         PYTHONUNBUFFERED 1

EXPOSE      5701

# Start dev server
ENTRYPOINT  ["/var/venv/bin/python"]
CMD         ["dev.py", "2>&1"]

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

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

COPY        scripts/lint-and-test.sh docker-compose.yaml dev.py application.py setup.cfg ./
COPY        spec/ ./spec
COPY        tests/ ./tests

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

########################################
### Build image for test-integration ###
########################################

FROM base AS test-integration

# Install dev/test requirements
COPY        scripts/test-integration.sh requirements-dev.txt ./
RUN         pip install -r requirements-dev.txt

ENTRYPOINT [ "scripts/test-integration.sh" ]

