#
# Docker Focal image to build Android
#
FROM ubuntu:20.04

ENV DEBIAN_FRONTEND=noninteractive
ENV USER=jenkins
ENV GROUP=jenkins
ENV host_uid=5001
ENV host_gid=5001
ENV HOME /home/$USER

ENV USE_CCACHE 1
ENV CCACHE_DIR /home/$USER/.ccache
ENV TZ=Etc/UTC

# Keep the dependency list as short as reasonable
# First set of packages comes from AOSP requirements
# source.android.com/source/initializing.html
# Second set of packages comes from NXP
# Third set is missing patches from NXP
RUN apt-get update && \
    apt-get install -y \
	git-core gnupg flex bison gperf build-essential zip curl \
	zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev \
	x11proto-core-dev libx11-dev lib32z-dev libgl1-mesa-dev libxml2-utils \
	xsltproc unzip libncurses5 ccache \
	\
	uuid uuid-dev liblz-dev liblzo2-2 liblzo2-dev \
	lzop u-boot-tools mtd-utils sudo \
	openjdk-8-jdk device-tree-compiler gdisk m4 libz-dev libssl-dev \
	\
	bc locales wget python-is-python3 python3-setuptools python3-dev swig cpio rsync xxd && \
    apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Set up locales
RUN locale-gen en_US.UTF-8 && \
    update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LC_ALL en_US.UTF-8

# Replace the 'sh' alias to 'bash' instead of 'dash'.
RUN rm /bin/sh && ln -s bash /bin/sh

# Install repo
ADD https://storage.googleapis.com/git-repo-downloads/repo /usr/local/bin/
RUN chmod 755 /usr/local/bin/repo

# Add your user to sudoers to be able to install other packages in the container.
RUN echo "${USER} ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/${USER} && \
    chmod 0440 /etc/sudoers.d/${USER}

# Set the arguments for host_id and user_id to be able to save the build artifacts
# outside the container, on host directories, as docker volumes.
RUN groupadd -g $host_gid $GROUP && \
    useradd -g $host_gid -m -s /bin/bash -u $host_uid $USER

# Builds should run as a normal user.
USER $USER
