FROM registry.yandex.net/rtc-base/focal:stable
# Push To registry.yandex.net/travel/travel-ubuntu-focal-deploy

# Устанавливаем бинарные зависимости

RUN apt-get update
RUN apt-get install -y \
        gettext-base \
        gcc \
        virtualenv \
        python3-pip \
        python-setuptools \
        yandex-push-client \
        yandex-lockf \
        nginx=1.14.2-1.yandex.79-2 \
        telnet \
        iotop \
        mc \
        ncdu

# Отключаем ошибки отправки почты в сron
RUN apt-get remove postfix -y

# pip
RUN mkdir -p /root/.pip
COPY pip.conf /root/.pip/

# Ставим новейший pip
RUN pip -q install --upgrade \
    pip~=20.0.2 \
    setuptools==45.2.0

# pip2 (если нужен)
#RUN curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
#RUN python2 get-pip.py

# Генерим необходимые локали
RUN locale-gen ru_RU.UTF-8 \
    && locale-gen en_US.UTF-8 \
    && locale-gen tr_TR.UTF-8 \
    && locale-gen en_GB.UTF-8 \
    && update-locale
ENV LANG=ru_RU.UTF-8

# Устанавливаем solomon-agent
RUN apt-get install -y yandex-solomon-agent-bin=1:18.0
COPY solomon /etc/solomon

# jaeger-agent
COPY jaeger-agent /etc/jaeger-agent

# Bins
# cron-hack
# bin/docker-entrypoint.sh
# geobase
# bin/prepare-geobase.sh
COPY bin/* /bin/

# push-client
COPY statbox-push-client/*.yaml /etc/yandex/statbox-push-client/
COPY statbox-push-client/testing/* /etc/yandex/statbox-push-client/testing/
COPY statbox-push-client/production/* /etc/yandex/statbox-push-client/production/

# Supervisor
RUN pip install supervisor==4.1.0 && mkdir /var/log/supervisor
COPY supervisor/supervisord.conf /etc/supervisor/supervisord.conf
COPY supervisor/conf.d/* /etc/supervisor/conf.d/
RUN mkdir -p /var/log/supervisor/apps/

# nginx
COPY nginx/nginx.conf /etc/nginx/
COPY nginx/listen /etc/nginx/
COPY nginx/conf.d/* /etc/nginx/conf.d/
RUN install -d /var/log/nginx
# dorblu при старте надеется найти access.log
RUN touch /var/log/nginx/access.log

# pre start hooks
RUN mkdir /bin/pre_start
COPY pre_start/* /bin/pre_start/
RUN chmod +x /bin/pre_start/*

# Logrotate
COPY logrotate/* /etc/logrotate.d/
COPY cron/* /etc/cron.d/
RUN chmod 644 /etc/cron.d/*
RUN mkdir /var/log/logrotate
RUN if [ -e /etc/cron.daily/logrotate ]; then rm /etc/cron.daily/logrotate; fi;

# juggler_checks (зависят от python3-requests)
RUN pip3 install requests
COPY juggler_checks/ /juggler_checks/

COPY etc/bash.bashrc /etc/
COPY etc/bashrc.d/* /etc/bashrc.d/
COPY root/* /root/
COPY /unistat_aggregator /unistat_aggregator

COPY /jaeger/jaeger-agent /bin/jaeger-agent
RUN chmod +x /bin/jaeger-agent

# prepare /etc/nginx/auth/allow_yandex_only
RUN mkdir -p /etc/nginx/auth/ && \
    /bin/generate-allow-yandex-only

RUN chmod +x /bin/set-env.py
RUN chmod +x /bin/export-env.sh

# cron fix
RUN sed -i '/session    required     pam_loginuid.so/c\#session    required   pam_loginuid.so' /etc/pam.d/cron

# cron-hack
ENTRYPOINT ["/bin/docker-entrypoint.sh"]

CMD /bin/bash -c "source /bin/export-env.sh && run-parts /bin/pre_start/ && exec supervisord -c /etc/supervisor/supervisord.conf"
