# BUILD redisfab/redisai:{{VERSION}}-gpu-{{REDIS_ARCH}}-{{REDIS_OSNICK}}-test

ARG PACK={{REDIS_PACK}}

# OSNICK=bionic|centos7|centos6
ARG OSNICK=bionic

# ARCH=x64|arm64v8|arm32v7
ARG ARCH=x64

# OS=ubuntu18.04|ubuntu16.04|centos7
ARG OS=ubuntu18.04

#----------------------------------------------------------------------------------------------
FROM redisfab/redis:{{REDIS_VERSION}}-{{REDIS_ARCH}}-{{REDIS_OSNICK}} AS redis
FROM nvidia/cuda:{{REDIS_CUDA_VERSION}}-devel-ubuntu18.04 AS builder

ARG PACK

SHELL ["/bin/bash", "-c"]

{% include "templates/gpu.yml" %}

ENV LANG=en_US.UTF-8
RUN apt-get update
RUN apt-get install -y locales && \
    sed -i -e "s/# $LANG.*/$LANG UTF-8/" /etc/locale.gen && \
    dpkg-reconfigure --frontend=noninteractive locales && \
    update-locale LANG=$LANG

WORKDIR /build
ADD ./ /build
COPY --from=redis /usr/local/ /usr/local/
COPY ./opt/ opt/
COPY ./tests/flow/tests_setup/test_requirements.txt tests/flow/tests_setup/
COPY ./tests/flow/tests_setup/Install_RedisGears.sh tests/flow/tests_setup/
COPY ./get_deps.sh .

RUN apt-get -q install -y git

RUN VENV=venv FORCE=1 ./opt/readies/bin/getpy3

RUN set -e ;\
	. venv/bin/activate ;\
	./opt/system-setup.py

ARG DEPS_ARGS=""
RUN set -e ;\
	. venv/bin/activate ;\
	if [[ -z $DEPS_ARGS ]]; then \
	VERBOSE=1 ./get_deps.sh gpu ;\
	else \
	env $DEPS_ARGS ./get_deps.sh gpu ;\
	fi

ARG BUILD_ARGS=""
RUN set -e ;\
	. venv/bin/activate ;\
	bash -l -c "make -C opt build GPU=1 $BUILD_ARGS SHOW=1"

RUN set -e ;\
	if [[ $PACK == 1 ]]; then \
		. venv/bin/activate ;\
		bash -l -c "make -C opt pack GPU=1 VERBOSE=1" ;\
	fi

RUN git remote set-url origin https://github.com/RedisAI/RedisAI

CMD ["bash", "-c", ". ./venv/bin/activate; make -C opt test GPU=1 SHOW=1"]
