FROM registry.yandex.net/tools/raw-ubuntu:18.04
ARG MODE=release

ENV REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
RUN locale-gen ru_RU.UTF-8 && update-locale LANG=ru_RU.UTF-8

EXPOSE 80
CMD uwsgi --ini=/src/uwsgiconf.ini

ADD https://crls.yandex.net/allCAs.pem /etc/allCAs.pem
RUN chown www-data:www-data /etc/allCAs.pem

COPY deps/debian-build.txt /deps/
RUN apt-get update -qq \
    && cat /deps/debian-build.txt | xargs apt-get install -y \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

COPY deps/python-main.txt /deps/
RUN pip3 install --disable-pip-version-check -i https://pypi.yandex-team.ru/simple/ -r /deps/python-main.txt

COPY deps/python-dev.txt /deps/
RUN if [ "$MODE" = "dev" ]; then \
        pip3 install --disable-pip-version-check -i https://pypi.yandex-team.ru/simple/ -r /deps/python-dev.txt; \
    fi

COPY /frontend/ /frontend/
WORKDIR /frontend

RUN chmod +x /opt/nodejs/8/bin/npm && ln -s /opt/nodejs/8/bin/npm /usr/local/bin/npm && ln -s /opt/nodejs/8/bin/node /usr/local/bin/node
RUN npm install --registry=https://npm.yandex-team.ru
RUN npm run build -- --production
RUN npm prune --production
RUN mkdir /static && mv bundles/* /static/ && rm -rf /frontend
WORKDIR /

COPY setup.py uwsgiconf.ini pytest.ini src/
COPY backend/ src/intranet/yasanta/backend/
RUN touch src/intranet/__init__.py
RUN touch src/intranet/yasanta/__init__.py

RUN if [ "$MODE" = "dev" ]; then \
        pip3 install -e /src/; \
    else \
        pip3 install /src/; \
    fi
