# Dockerfile

FROM       centos:centos7

WORKDIR    /var/app

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

# Add IUS repositories
RUN        yum -y install https://centos7.iuscommunity.org/ius-release.rpm

# Install Python 3.4 and wsgi dependencies
RUN        yum -y install gcc python34u python34u-libs python34u-devel python34u-pip

# Install ows-analytics dependencies
RUN        yum -y install make patch glibc-static libstdc++-static ncurses-devel ncurses-static openssl openssl-devel

# Install pipenv and uwsgi
RUN        pip3 install pipenv
RUN        pip3 install uwsgi

# Install awscli for retrieving env secrets in /uwsgi-start.sh
# (done outside pipfile.lock to avoid dependency hell)
RUN        pip3 install awscli

# Explicitly set locale and related env vars to use en_US.UTF-8
RUN        localedef -c -f UTF-8 -i en_US en_US.UTF-8
ENV        LC_ALL=en_US.UTF-8
ENV        LANG=en_US.UTF-8

# Configure uwsgi
RUN        useradd uwsgi -s /bin/false
RUN        mkdir /var/log/uwsgi
RUN        chown -R uwsgi:uwsgi /var/log/uwsgi

# Add application and install requirements
ADD        . /var/app
RUN        if [ -f /var/app/Pipfile.lock ]; then pipenv install --ignore-pipfile --system; fi

ADD        datadog.repo /etc/yum.repos.d/
RUN        yum makecache fast
RUN        yum remove datadog-agent-base
RUN        yum -y install datadog-agent; exit 0

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

ENV CURRENT_COMMIT_HASH=@GIT_COMMIT@

EXPOSE     8080
