FROM ubuntu:bionic

LABEL maintainer="Allegro.pl Sp. z o.o. opensource@allegro.pl"
LABEL authors="Allegro.pl Sp. z o.o. and Contributors opensource@allegro.pl"
LABEL description="Helper image to build deb package for Ralph."

ARG GIT_USER_NAME='root'
ARG GIT_USER_EMAIL='root@localhost'

ENV DEBIAN_FRONTEND=noninteractive
ENV SHELL=/bin/bash
ENV TERM=xterm
ENV EDITOR=nano
ENV RALPH_DIR=/opt/ralph

# The way we've pinned versions in requirement.txt files isn't compatible with chnages
# in pip's dependency resolver (pip 20.2: https://pip.pypa.io/en/latest/user_guide/#changes-to-the-pip-dependency-resolver-in-20-3-2020).
# Until it's fixed on our side we need to fix to specific pip version.
# To do this we need newer version of dh-virtualenv (upgrade-pip-to option added in version 1.2).
RUN apt-get update && \
    apt-get -y install software-properties-common && \
    add-apt-repository ppa:jyrki-pulliainen/dh-virtualenv

RUN apt-get update && \
    apt-get -y install build-essential debhelper devscripts equivs dh-virtualenv \
    # Newer version of mysqlclient-dev fails to install.
    # Fixed version should be removed once this problem is fixed in Ubuntu.
    libmysqlclient-dev=5.7.21-1ubuntu1 libmysqlclient20=5.7.21-1ubuntu1 \
    python3 python3-dev libffi-dev nodejs npm git-buildpackage vim-tiny git && \
    rm -rf /var/lib/apt/lists/* && \
    git config --global user.name "$GIT_USER_NAME" && \
    git config --global user.email "$GIT_USER_EMAIL"

COPY . $RALPH_DIR

WORKDIR $RALPH_DIR
ENTRYPOINT ["make", "-f", "Makefile.docker"]
