# Build image with:
# docker build -t django-tests tests
#
# Run tests for example with:
# docker run --rm -ti --security-opt=label:disable -v $PWD:/django:ro django-tests /bin/django-runtests -v2 auth_tests # admin_views

FROM fedora
RUN mkdir /django-requirements && echo -e '#!/bin/bash		\n \
	r () {							\n \
		echo "# Reading $1" >&2				\n \
		while read i ; do				\n \
			s="${i#-r }"				\n \
			if [ "$i" != "$s" ] ; then		\n \
				r "$s"				\n \
				echo "# Back to $1" >&2		\n \
			elif [ "$i" == "${i/##/}" ] ; then	\n \
				echo "python-$i"		\n \
				echo "python-${i,,}"		\n \
			fi					\n \
		done < "$1"					\n \
	}							\n \
	readarray -t p < <( r "$1")				\n \
	EXTRA="python-devel gcc redhat-rpm-config"		\n \
	dnf install -y --setopt=strict=0 $EXTRA "${p[@]}" && dnf clean all'	\
		> /django-requirements/dnf-install-python-requirements
ADD requirements/* /django-requirements/
RUN ( cd /django-requirements && bash ./dnf-install-python-requirements py2.txt )
RUN pip install -r /django-requirements/py2.txt
RUN ( echo '#!/bin/bash' ; echo 'cd /django/tests && PYTHONPATH=.. ./runtests.py "$@"' ) > /bin/django-runtests
RUN chmod a+x /bin/django-runtests
ENV PYTHONDONTWRITEBYTECODE 1
USER nobody
