FROM registry.centos.org/centos/centos:7

ARG repo=https://pagure.io/pagure.git
ARG branch=master

ENV REPO=$repo
ENV BRANCH=$branch

RUN yum -y install \
    epel-release

ADD ./fedora-infra-tags.repo /etc/yum.repos.d/infra-tags.repo
ADD ./fedora-infra-tags-stg.repo /etc/yum.repos.d/infra-tags-stg.repo

RUN yum -y install \
    yum-utils \
    rpm-build \
    python-setuptools \
    python-coverage \
    python-mock \
    python-docutils \
    python-enum \
    python-flask \
    python-flake8 \
    python2-pytest-xdist \
    python2-fedora-messaging \
    python2-pip \
    redis \
    which \
    git
#    git \
#    repoSpanner \
#    repoSpanner-bridge

RUN pip install pip --upgrade
RUN pip install setuptools --upgrade
RUN pip install pagure-messages

RUN cd / \
    && GIT_TRACE=1 GIT_CURL_VERBOSE=1 git clone -b $BRANCH $REPO \
    && chmod +x /pagure/dev/containers/runtests_py2.sh

# Install all the requirements from the spec file and replace the macro
# %{python_pkgversion} by empty string which thus installs all the py2
# version of the dependencies.
RUN cd /pagure && \
    yum install --enablerepo=epel-testing -y \
    `rpmspec -q --requires /pagure/files/pagure.spec | \
    sed -e "s|%{python_pkgversion}||"` && \
    yum clean all && \
    localedef -i en_US -f UTF-8 en_US.UTF-8

# The old version of setuptools in CentOS7 does not support restrictions on
# the requirements file, so drop them
RUN \
    sed -i -e "s|;python_version<\"3.4\"||" /pagure/requirements.txt && \
    sed -i -e "s|;python_version<=\"2.7\"||" /pagure/requirements.txt && \
    sed -i -e "s|python3-openid;python_version>=\"3.0\"||" \
       /pagure/requirements.txt && \
    sed -i "/^email_validator.*/d" /pagure/requirements.txt && \
    sed -i -e 's|"alembic-3"|"alembic"|' /pagure/tests/test_alembic.py && \
    cd /pagure && python setup.py build


WORKDIR /pagure
ENTRYPOINT ["/pagure/dev/containers/runtests_py2.sh"]
CMD []
