# PROD Dockerfile

ARG         AWS_ACCOUNT=437795906767

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

WORKDIR     /var/app

# Update and install common packages
RUN         yum -y update
RUN         yum -y install curl git tar zip

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

RUN         pip install --upgrade pip
RUN         pip install gunicorn
RUN         useradd gunicorn -s /bin/false

# Install requirements
COPY         ./requirements.txt /var/app/
RUN         if [ -f /var/app/requirements.txt ]; then pip install --no-cache-dir -I -r /var/app/requirements.txt; fi

# Add application
COPY         . /var/app

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

# Setup environment
ENV         LC_ALL=en_US.utf-8
ENV         LC_CTYPE=en_US.UTF-8

# Add startup script
RUN         mv /var/app/gunicorn-start.sh / && chmod +x /gunicorn-start.sh

USER        gunicorn

EXPOSE      8080

ENTRYPOINT  ["/gunicorn-start.sh"]
