ARG PYTHON_VERSION=2.7.18
ARG PYENV_ROOT="/opt/pyenv"

FROM registry.yandex.net/spirit/pyenv:1.0 AS cxoracle

RUN pip install -i https://pypi.yandex-team.ru/simple/ wheel
RUN pip wheel -i https://pypi.yandex-team.ru/simple/ yb-cx_Oracle==7.1.3.2 -w /

########################################

FROM registry.yandex.net/ubuntu:trusty AS base

ARG PYTHON_VERSION
ARG PYENV_ROOT
ENV PYENV_ROOT=$PYENV_ROOT

ENV PATH="$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH"

COPY --from=registry.yandex.net/spirit/pyenv:1.0 $PYENV_ROOT $PYENV_ROOT
RUN pyenv global $PYTHON_VERSION

RUN sed -e s/'archive.ubuntu'/'ru.archive.ubuntu'/g -i /etc/apt/sources.list
COPY docker/darkspirit/base/mirror.list /etc/apt/sources.list.d/

RUN apt-get update && P2P_WAIT_TIMEOUT=10 DEBIAN_FRONTEND=noninteractive apt-get install -y --force-yes \
  oracleclient=19.3.0.0.0-yb1 \
  python-lxml \
  yandex-balance-liquibase \
  && apt-get clean

# install yb-python-cxoracle into pyenv environment
COPY --from=cxoracle /yb_cx_Oracle-7.1.3.2-cp27-cp27mu-linux_x86_64.whl .
RUN pip install -i https://pypi.yandex-team.ru/simple/ --no-index ./yb_cx_Oracle-7.1.3.2-cp27-cp27mu-linux_x86_64.whl \
    && rm -f ./yb_cx_Oracle-7.1.3.2-cp27-cp27mu-linux_x86_64.whl

# зависимости, необходимые для запуска тестов (версии можно сверять с requirements_dev.txt)
RUN groupadd -r yb && useradd -r -g yb yb

RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
ENV NLS_LANG=AMERICAN_AMERICA.UTF8

RUN pip install -i https://pypi.yandex-team.ru/simple pytest-runner==5.2

COPY requirements.txt requirements-deploy.txt /
RUN pip install -i https://pypi.yandex-team.ru/simple/ -r /requirements.txt
# Зависимости, которые не получается поставить на greed*
RUN pip install -i https://pypi.yandex-team.ru/simple/ -r /requirements-deploy.txt

COPY tnsnames.ora /

RUN bash -c 'source /etc/oraprofile && cat /tnsnames.ora > $ORACLE_HOME/network/admin/tnsnames.ora && rm /tnsnames.ora'
RUN bash -c 'source /etc/oraprofile && echo $ORACLE_HOME > /etc/ld.so.conf.d/oracle.conf && ldconfig'
