FROM registry.yandex.net/mail/mail-xenial-common:latest

RUN wget --quiet -O - http://mirror.yandex.ru/mirrors/postgresql/ACCC4CF8.asc | apt-key add -
RUN echo "deb http://mirror.yandex.ru/mirrors/postgresql/ xenial-pgdg main" >> /etc/apt/sources.list.d/pgdg.list

RUN apt-get update && apt-get install -y nginx=1.14.2-1.yandex.15 lua-cjson
RUN ln -sf /usr/lib/x86_64-linux-gnu/lua/ /usr/local/lib/lua
RUN apt-get autoremove -y && apt-get clean

COPY etc /etc
COPY entrypoint.sh /entrypoint.sh
COPY bin /opt/bin

RUN mkdir -p /etc/nginx/ssl && \
    openssl req -x509 -nodes -days 365 -newkey rsa:4096 \
    -subj "/C=RU/ST=Moscow/L=Moscow/O=Yandex/OU=SWAT/CN=localhost.msup.yandex.ru" \
    -keyout /etc/nginx/ssl/ohio.pem -out /etc/nginx/ssl/ohio.pem

RUN mv /opt/bin/bin /opt/bin/ohio
RUN chmod u+x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
CMD ["supervisord", "-n", "-c", "/etc/supervisor/supervisord.conf"]