# Build Image for Gitlab CI

FROM nvcr.io/nvidia/nvhpc:22.11-devel-cuda_multi-ubuntu20.04

MAINTAINER Sean Treichler <sean@nvidia.com>

ENV DEBIAN_FRONTEND noninteractive

RUN dpkg --add-architecture i386 && \
    apt-get update -qq && \
    apt-get install -qq apt-transport-https ca-certificates software-properties-common wget && \
    add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
    add-apt-repository ppa:pypy/ppa -y && \
    apt-get update -qq && \
    apt-get install -qq \
      curl \
      libpython3-dev python3-pip pypy3 \
      gdb vim && \
    apt-get clean

RUN pip3 install --upgrade 'pip>=22,<23' && \
    pip3 install --upgrade 'setuptools>=62,<63' 'setuptools_rust>=1.3,<1.4' && \
    pip3 install cffi github3.py 'numpy>=1.22,<1.23' 'cryptography>=37,<38' 'pandas>=1.4,<1.5' daff tabulate

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

# TODO: build Terra so we can run regent tests too
# RUN git clone https://github.com/terralang/terra.git && \
#     cd terra/build && \
#     cmake -DCMAKE_INSTALL_PREFIX=/usr/local/terra12 .. && \
#     make install -j8 && \
#     rm -rf terra

# delete a bunch of stuff we don't need (yet) - NOTE: this is only useful
#  if you use docker-squash on the resulting image (docker build --squash
#  only squashes the new layers we add here); see instructions below
RUN rm -rf /opt/nvidia/hpc_sdk/Linux_x86_64/22.11/comm_libs/ && \
    rm -rf /opt/nvidia/hpc_sdk/Linux_x86_64/22.11/math_libs/ && \
    rm -rf /opt/nvidia/hpc_sdk/Linux_x86_64/22.11/profilers/ && \
    rm -rf /opt/nvidia/hpc_sdk/Linux_x86_64/22.11/examples/

# process to squash the image:
# pip3 install docker-squash
# ~/.local/bin/docker-squash -t registry.gitlab.com/stanfordlegion/legion/gitlab-ci-hpcsdk:YYMMDD-squash registry.gitlab.com/stanfordlegion/legion/gitlab-ci-hpcsdk:YYMMDD
# docker tag registry.gitlab.com/stanfordlegion/legion/gitlab-ci-hpcsdk:YYMMDD-squash registry.gitlab.com/stanfordlegion/legion/gitlab-ci-hpcsdk:YYMMDD
