FROM registry.yandex.net/extmaps/nanny-cars-python3-base:latest
MAINTAINER Sergey Kulik <skulik@yandex-team.ru>

ENV PROJECT_ROOT=/opt/www/cars

RUN apt-get clean
RUN rm -rf /var/lib/apt/lists/*

RUN echo 'Acquire::By-Hash "yes";' >> /etc/apt/apt.conf
RUN echo 'Acquire::CompressionTypes::Order:: "gz";' >> /etc/apt/apt.conf

RUN touch /etc/apt/apt.conf.d/99fixbadproxy \
    && echo 'Acquire::http::Pipeline-Depth 0;' >> /etc/apt/apt.conf.d/99fixbadproxy \
    && echo 'Acquire::http::No-Cache true;' >> /etc/apt/apt.conf.d/99fixbadproxy \
    && echo 'Acquire::BrokenProxy true;' >> /etc/apt/apt.conf.d/99fixbadproxy

RUN apt-get update --option Acquire::https::proxy=${HTTPS_PROXY:='False'} \
    && apt-get install -y postgresql --option Acquire::https::proxy=${HTTPS_PROXY:='False'}

COPY ./ ${PROJECT_ROOT}/

# try to not upgrade pip due to Python 3.4 end of life
# force update colorama due to distutils hard dependencies
RUN cd ${PROJECT_ROOT} \
    && pip3 install --upgrade pip \
    && pip3 install --index-url=https://pypi.yandex-team.ru/simple --ignore-installed --force-reinstall --no-cache-dir colorama==0.4.1 \
    && pip3 install --index-url=https://pypi.yandex-team.ru/simple git+https://github.yandex-team.ru/common-python/python-blackbox.git@13c6a93033371b126858f2c01de4212837eb004b \
    && pip3 install --index-url=https://pypi.yandex-team.ru/simple .

RUN python3 ${PROJECT_ROOT}/manage.py collectstatic --noinput --verbosity=0
RUN python3 ${PROJECT_ROOT}/manage.py compilemessages

# Install package the second time to update include freshly built localization files.
RUN cd ${PROJECT_ROOT} \
    && pip3 install --upgrade --force-reinstall --no-deps .
