FROM ubuntu:16.04

LABEL maintainer="Reuben N. S. Rowe (r.n.s.rowe@kent.ac.uk)"

ARG DEBIAN_FRONTEND=noninteractive

ENV TERM linux

RUN apt-get update && apt-get install -y --no-install-recommends apt-utils
RUN apt-get update && apt-get install -y --no-install-recommends \
  camlp4-extra \
  git \
  libpcre3-dev \
  m4 \
  ocaml \
  ocaml-native-compilers \
  opam \
  patchutils \
  pkg-config \
  rlwrap \
  software-properties-common \
  rsync \
&& rm -rf /var/lib/apt/lists/*

RUN apt-get update && apt-get install -y --no-install-recommends curl && \
  (curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash) && \
  apt-get update && \
  apt-get install -y --no-install-recommends git-lfs && \
  apt-get remove -y curl && \
  rm -rf /var/lib/apt/lists/*

RUN useradd -m rotor

USER rotor

RUN opam init --auto-setup --comp 4.04.2

WORKDIR /home/rotor
RUN git clone https://gitlab.com/trustworthy-refactoring/refactorer && \
  cd refactorer && \
  eval `opam config env` && \
  opam pin add rotor . && \
  make && \
  opam install -y rotor

RUN opam switch rotor-testbed --alias-of 4.04.2 && \
  opam install -y jbuilder.1.0+beta11 ocaml-migrate-parsetree octavius re

WORKDIR /home/rotor
RUN eval `opam config env`; \
  mkdir testbeds && \
  mkdir testbeds/jane-street && \
  tar -xzf ./refactorer/test/jane-street/js-testbed.tar.gz -C jane-street && \
  cd testbeds/jane-street && \
  jbuilder build

RUN opam switch 4.04.2

ENV JANE_STREET_PATH /home/rotor/testbeds/jane-street

WORKDIR /home/rotor/refactorer