FROM registry.yandex.net/ubuntu:trusty
# Push To registry.yandex.net/travel/travel-ubuntu-trusty

COPY apt/yandex-rasp-trusty-stable.list /etc/apt/sources.list.d/yandex-rasp-trusty-stable.list

# Устанавливаем бинарные зависимости
RUN apt-get update \
    && apt-get install -y --force-yes \
        gettext-base \
        gcc \
        git \
        python2.7 \
        python-pip \
        python3-pip \
        python-virtualenv \
        python-setuptools \
        yandex-push-client \
        yandex-logrotate \
        yandex-lockf \
        nginx-full=1.8.1-1.yandex.72 \
        tcpdump \
        lsof \
        telnet \
        htop \
        iotop \
        mc \
        ncdu \
        dnsutils \
        iptables \
        atop \
        screen \
        tmux \
        strace

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

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

# Генерим необходимые локали
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:16.9
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/

# Juggler
RUN apt-get install -y --force-yes juggler-client=2.3.1805312013 \
    && rm /etc/cron.d/juggler-client
COPY juggler/ /etc/juggler/

# 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==3.3.3 && 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

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

CMD run-parts /bin/pre_start/ && exec supervisord -c /etc/supervisor/supervisord.conf
