FROM registry.yandex.net/corp-education/python-3.9-build:latest as builder

ENV PYTHONUNBUFFERED 1

RUN python3 -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"

COPY ./requirements /requirements
RUN pip3 install -U pip \
  && pip3 install --no-cache-dir -r /requirements/production.txt \
  && rm -rf /requirements

FROM registry.yandex.net/corp-education/python-3.9:latest as backend
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"

COPY ./compose/production/django/start /start
RUN sed -i 's/\r$//g' /start
RUN chmod +x /start

COPY ./compose/production/django/celery/worker/start /start-celeryworker
RUN sed -i 's/\r$//g' /start-celeryworker
RUN chmod +x /start-celeryworker

COPY ./compose/production/django/celery/beat/start /start-celerybeat
RUN sed -i 's/\r$//g' /start-celerybeat
RUN chmod +x /start-celerybeat

COPY ./compose/production/django/celery/flower/start /start-flower
RUN sed -i 's/\r$//g' /start-flower
RUN chmod +x /start-flower

ADD "https://storage.yandexcloud.net/cloud-certs/CA.pem" /app/.postgres/root.crt
RUN chmod 0600 /app/.postgres/root.crt

COPY . /app

WORKDIR /app
