# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# This builds a docker image containing all the tools we need to run our
# test suite in CI, including rust, kotlin, and swift.

FROM circleci/rust:buster

MAINTAINER Ryan Kelly "rfkelly@mozilla.com"

ENV \
    # Some APT packages like 'tzdata' wait for user input on install by default.
    # https://stackoverflow.com/questions/44331836/apt-get-install-tzdata-noninteractive
    DEBIAN_FRONTEND=noninteractive

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

RUN sudo apt-get update -qq \
    && sudo apt-get install -qy --no-install-recommends \
        clang \
        libcurl4 \
        openjdk-11-jdk-headless \
        python3 \
        git \
        curl \
        unzip \
        # Swift dependencies
        libtinfo5 \
        libncurses5 \
        # For `cc` crates; see https://github.com/jwilm/alacritty/issues/1440.
        # <TODO: Is this still true?>.
        g++ \
        python3-pip \
    && sudo apt-get clean

RUN rustup update \
    # This specific version of Rust is required for compatibility with mozilla-central
    && rustup install 1.43.0 \
    && rustup default 1.43.0

RUN mkdir -p /tmp/setup-swift \
    && cd /tmp/setup-swift \
    && curl -o swift.tar.gz https://swift.org/builds/swift-5.2.4-release/ubuntu1804/swift-5.2.4-RELEASE/swift-5.2.4-RELEASE-ubuntu18.04.tar.gz \
    # XXX TODO: should check a sha256sum or something here...
    && tar -xzf swift.tar.gz \
    && sudo mv swift-5.2.4-RELEASE-ubuntu18.04 /opt/swift \
    && echo "export PATH=\"\$PATH:/opt/swift/usr/bin\"" >> /home/circleci/.bashrc \
    && echo "export PATH=\"\$PATH:/opt/swift/usr/bin\"" >> /home/circleci/.profile \
    && cd ../ \
    && rm -rf ./setup-swift

RUN mkdir -p /tmp/setup-kotlin \
    && cd /tmp/setup-kotlin \
    && curl -o sdk.install.sh https://get.sdkman.io \
    # XXX TODO: should check a sha256sum or something here...
    && bash ./sdk.install.sh \
    && . /home/circleci/.sdkman/bin/sdkman-init.sh \
    && sdk install kotlin \
    && echo ". /home/circleci/.sdkman/bin/sdkman-init.sh" >> /home/circleci/.profile \
    && cd ../ \
    && rm -rf ./setup-kotlin

RUN mkdir -p /tmp/setup-jna \
    && cd /tmp/setup-jna \
    && curl -o jna.jar https://repo1.maven.org/maven2/net/java/dev/jna/jna/5.6.0/jna-5.6.0.jar \
    # XXX TODO: should check a sha256sum or something here...
    && sudo mv jna.jar /opt \
    && echo "export CLASSPATH=\"\$CLASSPATH:/opt/jna.jar\"" >> /home/circleci/.bashrc \
    && echo "export CLASSPATH=\"\$CLASSPATH:/opt/jna.jar\"" >> /home/circleci/.profile \
    && cd ../ \
    && rm -rf ./setup-jna
