# Copyright (C) 2019 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Creates an image that can check out / build / test the perfetto source. The
# image is used by the Kokoro continuous integration jobs, but is also suitable
# for local development.

FROM debian:buster

RUN set -ex; \
    export DEBIAN_FRONTEND=noninteractive; \
    echo deb http://deb.debian.org/debian buster-backports main > \
            /etc/apt/sources.list.d/backports.list; \
    apt-get update; \
    apt-get -y install python3 python3-pip git curl sudo lz4 tar ccache tini \
                       libpulse0 libgl1 libxml2 libc6-dev-i386 libtinfo5 \
                       gnupg2 pkg-config zip g++ zlib1g-dev unzip \
                       python3-distutils clang-8 gcc-7 g++-7; \
    update-alternatives --install /usr/bin/python python /usr/bin/python3.7 1; \
    gcc-7 --version; \
    g++-7 --version; \
    clang-8 --version; \
    clang++-8 --version; \
    pip3 install --quiet protobuf pandas; \
    groupadd -g 1337 perfetto; \
    useradd -d /ci/ramdisk -u 1337 -g perfetto perfetto; \
    apt-get -y autoremove; \
    rm -rf /var/lib/apt/lists/* /usr/share/man/* /usr/share/doc/*;

RUN set -ex; \
    curl -LO https://github.com/bazelbuild/bazel/releases/download/2.2.0/bazel-2.2.0-installer-linux-x86_64.sh; \
    chmod +x bazel-*-installer-linux-x86_64.sh; \
    ./bazel-*-installer-linux-x86_64.sh; \
    rm bazel-*-installer-linux-x86_64.sh; \
    bazel version;

COPY testrunner.sh /ci/testrunner.sh
COPY init.sh /ci/init.sh
RUN chmod -R a+rx /ci/

VOLUME [ "/ci/cache", "/ci/ramdisk", "/ci/artifacts" ]
ENTRYPOINT [ "tini", "-g", "--" ]
CMD [ "bash", "/ci/init.sh" ]

