FROM linaro/ci-#{ARCH}-tcwg-base-ubuntu:#{DISTRO}

#if ARCH_amd64
# Install static user-mode QEMU for running SVE LLVM buildbots via QEMU
# on x86_64 machines.  We bind-mount qemu-aarch64-static binary inside
# the aarch64 tcwg-llvmbot container, and all specify it as container
# entrypoint.  This allows us to run aarch64 container with SVE support.
# We do this only for Focal, since Bionic's QEMU version has no SVE support.
RUN apt-get update \
 && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
 qemu-user-static \
 && apt-get clean \
 && rm -rf \
 /var/lib/apt/lists/* \
 /tmp/* \
 /var/tmp/*
#endif

COPY docker-stats docker-wrapper tcwg-build.sh /usr/local/bin/
COPY docker-wrapper /usr/local/bin/docker

COPY run.sh start.sh /

# Allow privileged containers to access services on the bare machine.
# See run_on_bare_machine and run.sh for details.
COPY run_on_bare_machine /usr/local/bin/
RUN ln -sf /usr/local/bin/run_on_bare_machine /usr/sbin/sysctl \
 && ln -sf /usr/local/bin/run_on_bare_machine /usr/bin/systemctl \
 && ln -sf /usr/local/bin/run_on_bare_machine /usr/bin/timedatectl \
 && ln -sf /usr/local/bin/run_on_bare_machine /usr/sbin/reboot

# These are compatibility links for prepare-board.sh to find cpupower in the same
# place when running "start_board" on bare machine and inside host container.
# These are for TK1s and TX1s.
RUN true \
 && ln -s /usr/lib/linux-tools/4.18.0-13-generic /usr/lib/linux-tools/3.10.40 \
 && ln -s /usr/lib/linux-tools/4.18.0-13-generic /usr/lib/linux-tools/4.4.38-tegra

ENV TINI_VERSION v0.18.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-#{ARCH} /sbin/tini
RUN chmod +x /sbin/tini

#if ARCH_amd64 || ARCH_arm64
ENTRYPOINT ["/sbin/tini", "--", "/run.sh"]
#else
ENTRYPOINT ["/sbin/tini", "--", "linux32", "/run.sh"]
#endif
CMD ["start.sh"]
