FROM registry.yandex.net/tools/raw-ubuntu:20.04

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

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

RUN apt-get update \
    && apt-get install -y \
                        python3-pip \
                        postgresql-client \
                        libpq-dev \
                        wget

RUN pip3 install pgcli

RUN mkdir -p ~/.postgresql && \
        wget "https://crls.yandex.net/allCAs.pem" -O ~/.postgresql/root.crt && \
        chmod 0600 ~/.postgresql/root.crt

RUN apt-get update \
    && apt-get install -y postgresql-client-12

COPY alembic.ini /

COPY /stackbot/src/stackbot.bot /stackbot
COPY /stackbot/alembic/stackbot.alembic /stackbot-db

COPY /entrypoints/shell.sh /usr/local/bin/shell
COPY /entrypoints/celery.sh /usr/local/bin/stackbot_celery
COPY /entrypoints/dbshell.sh /usr/local/bin/dbshell
COPY /entrypoints/start.sh /

RUN chmod +x /usr/local/bin/stackbot_celery
RUN chmod +x /usr/local/bin/shell
RUN chmod +x /usr/local/bin/dbshell

CMD bash start.sh
