I will focus on the creation of a container dedicated to android development. With respect to my previous entry on the topic this setup simplifies the directory sharing between the host and the container.
My updated requirements are:
- the dev tools will be installed only on the container
- the source code should be accessible both from the host and the guest
- we setup a local mirror for the android repo to save space as I am working on several versions/platforms
This time we consider the use of a privileged container to ease the directory sharing process between host and container.
Here is what my setup looks like on a ubuntu system:
Container setup
# - Install and configure lxd (one time operation)
sudo apt-get install lxd
sudo lxd init
# - Create a new environment
# for example ubuntu version 16.04 and I call the container ubuntu-1604
lxc launch ubuntu:16.04 ubuntu-1604
# - Create a directory that will contain the code shared
# between the host and the containers (one time operation)
mkdir ${HOME}/projects
# - Mount the project folder as the container user (ubuntu by default) home
lxc config device add ubuntu-1604 projects disk source=/home/projects path=/home/ubuntu
# - Create a directory that will contain the android mirror
# !!! This directory shouldn't be user specific (i.e. have the username is the path)
# !!! as the the container user might be different from the host user
sudo mkdir /home/aosp-mirror
# - Mount the project folder as the container user (ubuntu by default) home
lxc config device add ubuntu-1604 aosp-mirror disk source=/home/aosp-mirror path=/home/aosp-mirror
# - Make the container a priviledged container
# This is required in order to have the correct uid mapping between your guest container and your host system.
# cf previous blog entry for alternative
lxc config set ubuntu-1604 security.privileged true
# - Restart the container to apply the changes
lxd restart ubuntu-1604
The next steps consist in: cloning the android mirror from the container repo sync a version to work on and use reference to the local mirror to save space
Android mirror setup
# Cloning the mirror
cd /home/aosp-mirror
repo init -u https://android.googlesource.com/mirror/manifest --mirror
repo sync
# Sync a working dir against the local repo.
# Use --reference to link the git refs to the mirror
# (optional) Sync only a branch (-c option). Might be dangerous if you want to commit code later on.
cd ~
mkdir aosp-working-dir
cd !$
repo init --reference=/home/aosp-mirror -u /home/aosp-mirror/platform/manifest.git -b android-5.0.1_r1
repo sync -j$(nproc) -c
One advantage of this lxc setup is that the local git references can be resolved both from the host and the container.