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

RUN while read line; do \
      if [ x"$(echo "$line" | cut -d: -f 4)" != x"9000" ]; then \
        continue; \
      fi; \
      new-user.sh --passwd "$line"; \
      user=$(echo "$line" | cut -d: -f 1); \
      sudo -i -u $user ccache -p; \
    done </home-data/passwd

# We create ccache directory as tcwg-buildslave, because otherwise
# "docker run -v ccache-volume:/home/tcwg-buildslave/.ccache" will create
# it owned by root:root, which will break builds.  We set ccache size:
# - 50G is a bare minimum to ccache the gnu/llvm builds
# - The aa64/amd64 build machines have enough disk to support 50G
# - TK1s have small disk, so try to get by with 10G.
RUN sudo -i -u tcwg-buildslave mkdir -p /home/tcwg-buildslave/.ccache \
#if ARCH_amd64 || ARCH_arm64
 && sudo -i -u tcwg-buildslave ccache -M 50G
#else
 && sudo -i -u tcwg-buildslave ccache -M 10G
#endif

#if ARCH_armhf
# On 32-bits, the git clone of some big base-artifacts repositories
# leads to an out-of-memory issue. When limiting threads to 2 threads,
# the memory allocation remain acceptable for armhf.
RUN sudo -i -u tcwg-buildslave git config --global pack.threads 2
#endif

#if ARCH_amd64
# Install wine.
RUN \
 apt-get update \
 && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
 wine-stable \
 && apt-get clean \
 && rm -rf \
 /var/lib/apt/lists/* \
 /tmp/* \
 /var/tmp/*
#endif

#if DISTRO_focal
# Add llvm 11 to get llvm-objdump with support for --disassemble-symbols.
# We need this in bmk-scripts.git/symbol_md5sum.sh.
RUN \
 apt-get update \
 && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
 llvm-11 \
 && apt-get clean \
 && rm -rf \
 /var/lib/apt/lists/* \
 /tmp/* \
 /var/tmp/* \
 # This will override llvm-objdump installed by tcwg-base's llvm package.
 && ln -s `which llvm-objdump-11` /usr/local/bin/llvm-objdump
#endif

EXPOSE 22
#if ARCH_amd64 || ARCH_arm64
CMD ["/usr/sbin/sshd", "-D"]
#else
CMD ["linux32", "/usr/sbin/sshd", "-D"]
#endif
