# Copied from the ubuntu-16.04 dockerfile from https://base-images.ocamllabs.io/
# e.g. https://base-images.ocamllabs.io/job/2021-03-05/151207-ocluster-build-a8c0eb
# Autogenerated by OCaml-Dockerfile scripts
FROM ubuntu:xenial
LABEL distro_style="apt"
RUN apt-get -y update
RUN DEBIAN_FRONTEND=noninteractive apt-get -y upgrade
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install build-essential curl git libcap-dev sudo
RUN git config --global user.email "docker@example.com"
RUN git config --global user.name "Docker"
RUN curl -fOL https://github.com/projectatomic/bubblewrap/releases/download/v0.4.1/bubblewrap-0.4.1.tar.xz
RUN tar xf bubblewrap-0.4.1.tar.xz
RUN cd bubblewrap-0.4.1 && ./configure --prefix=/usr/local && make && sudo make install
RUN rm -rf bubblewrap-0.4.1.tar.xz bubblewrap-0.4.1
RUN git clone -b 2.0 git://github.com/ocaml/opam /tmp/opam
RUN sh -c "cd /tmp/opam && make cold && mkdir -p /usr/local/bin && cp /tmp/opam/opam /usr/local/bin/opam-2.0 && chmod a+x /usr/local/bin/opam-2.0 && rm -rf /tmp/opam"
RUN git clone -b master git://github.com/ocaml/opam /tmp/opam
RUN sh -c "cd /tmp/opam && make cold && mkdir -p /usr/local/bin && cp /tmp/opam/opam /usr/local/bin/opam-master && chmod a+x /usr/local/bin/opam-master && rm -rf /tmp/opam"
FROM ubuntu:xenial
COPY --from=0 [ "/usr/local/bin/bwrap", "/usr/bin/bwrap" ]
COPY --from=0 [ "/usr/local/bin/opam-2.0", "/usr/bin/opam-2.0" ]
COPY --from=0 [ "/usr/local/bin/opam-master", "/usr/bin/opam-2.1" ]
RUN ln /usr/bin/opam-2.0 /usr/bin/opam
RUN ln -fs /usr/share/zoneinfo/Europe/London /etc/localtime
RUN apt-get -y update
RUN DEBIAN_FRONTEND=noninteractive apt-get -y upgrade
RUN echo 'Acquire::Retries "5";' > /etc/apt/apt.conf.d/mirror-retry
RUN apt-get -y update
RUN DEBIAN_FRONTEND=noninteractive apt-get -y upgrade
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install build-essential curl git rsync sudo unzip nano libcap-dev libx11-dev
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
RUN echo 'opam ALL=(ALL:ALL) NOPASSWD:ALL' > /etc/sudoers.d/opam
RUN chmod 440 /etc/sudoers.d/opam
RUN chown root:root /etc/sudoers.d/opam
RUN adduser --uid 1000 --disabled-password --gecos '' opam
RUN passwd -l opam
RUN chown -R opam:opam /home/opam
USER opam
ENV HOME="/home/opam"
WORKDIR /home/opam
RUN mkdir .ssh
RUN chmod 700 .ssh
RUN echo 'wrap-build-commands: []' > ~/.opamrc-nosandbox
RUN echo 'wrap-install-commands: []' >> ~/.opamrc-nosandbox
RUN echo 'wrap-remove-commands: []' >> ~/.opamrc-nosandbox
RUN echo 'required-tools: []' >> ~/.opamrc-nosandbox
RUN echo '#!/bin/sh' > /home/opam/opam-sandbox-disable
RUN echo 'cp ~/.opamrc-nosandbox ~/.opamrc' >> /home/opam/opam-sandbox-disable
RUN echo 'echo --- opam sandboxing disabled' >> /home/opam/opam-sandbox-disable
RUN chmod a+x /home/opam/opam-sandbox-disable
RUN sudo mv /home/opam/opam-sandbox-disable /usr/bin/opam-sandbox-disable
RUN echo 'wrap-build-commands: ["%{hooks}%/sandbox.sh" "build"]' > ~/.opamrc-sandbox
RUN echo 'wrap-install-commands: ["%{hooks}%/sandbox.sh" "install"]' >> ~/.opamrc-sandbox
RUN echo 'wrap-remove-commands: ["%{hooks}%/sandbox.sh" "remove"]' >> ~/.opamrc-sandbox
RUN echo '#!/bin/sh' > /home/opam/opam-sandbox-enable
RUN echo 'cp ~/.opamrc-sandbox ~/.opamrc' >> /home/opam/opam-sandbox-enable
RUN echo 'echo --- opam sandboxing enabled' >> /home/opam/opam-sandbox-enable
RUN chmod a+x /home/opam/opam-sandbox-enable
RUN sudo mv /home/opam/opam-sandbox-enable /usr/bin/opam-sandbox-enable
RUN git config --global user.email "docker@example.com"
RUN git config --global user.name "Docker"
COPY --chown=opam:opam [ ".", "/home/opam/opam-repository" ]
RUN opam-sandbox-disable
RUN opam init -k local -a /home/opam/opam-repository --bare
RUN rm -rf .opam/repo/default/.git
COPY [ "Dockerfile", "/Dockerfile.opam" ]
