Skip to content

Update 4.4-kitkat branch to include configuring uid fix #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 46 commits into
base: 4.4-kitkat
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
08e8505
lollipop: Update to use OpenJDK 7
kylemanna Mar 2, 2015
a4a7756
test: lollipop: Add initial script
kylemanna Mar 3, 2015
bf49b4a
Merge branch '4.4-kitkat' into 5.0-lollipop
kylemanna Apr 22, 2015
f2cb2e7
tests: Update script to call bash for lollipop
kylemanna Apr 22, 2015
66505f7
README: Clean-up some of the description a bit
kylemanna Aug 16, 2015
4d16a0f
Dockerfile: Add "aosp" group
jcfr Apr 19, 2016
9934955
Add convenience Makefile to easily rebuild image
jcfr Apr 19, 2016
ee01698
Dockerfile: Prefer COPY instead of ADD
jcfr Apr 19, 2016
6cbbd6c
Dockerfile: Fix ownership of .gitconfig and .ssh
jcfr Apr 19, 2016
d91e17d
Dockerfile: Change ownership of /tmp/cache and /aosp directories
jcfr Apr 19, 2016
d47f14d
utils/aosp: trim trailing slash of directories
jcfr Apr 19, 2016
d7f0c4f
utils/aosp: Refactor code to display status message and remove chmod …
jcfr Apr 19, 2016
2ee12e4
Dockerfile: install latest version of JDK
jcfr Apr 20, 2016
91ae4a8
utils/aosp: Update script and Dockerfile to work with any host user u…
jcfr Apr 20, 2016
a5daaab
docker_entrypoint: Default to 'bash' if no arguments are provided
jcfr Apr 20, 2016
f1b7f6a
utils/aosp: If no AOSP_VOL is set, create aosp volume in current home
jcfr Apr 20, 2016
4fd3a9d
Merge pull request #11 from jcfr/support-current-user-with-arbitrary-…
kylemanna Apr 21, 2016
0a678c7
README: Add shields
kylemanna Apr 21, 2016
b0aba84
utils: Fix harmless entrypoint msg typo
kylemanna Oct 12, 2016
fe5e5d7
marshmallow: Test on marshmallow android-6.0.1_r72
kylemanna Oct 13, 2016
92b0003
nougat: First pass at building 7.0
kylemanna Oct 13, 2016
e6d066e
README: Add nougat as working
kylemanna Oct 13, 2016
c2764be
entrypoint: Preserve ENV variables
kylemanna Oct 13, 2016
4ac164b
README: Fix image layers badger
kylemanna Oct 13, 2016
9e4c52f
README: Fix pre-formatted code
kylemanna Oct 15, 2016
ab9f751
utils/aosp: Only pass UID and GID arguments if NOT root
kylemanna Oct 15, 2016
ecca921
Dockerfile: Install graphviz to enable product-graph
kylemanna Jan 1, 2017
edfe0db
aosp: Check that SSH_AUTH_SOCK points to a socket
kylemanna Jan 2, 2017
48da94b
README: Add macOS warning
kylemanna Jan 9, 2017
2b4eec3
Update to MM r79 for MM test
robbyoconnor Jul 13, 2017
b2de320
Merge pull request #24 from robbyoconnor/update-to-r79
kylemanna Jul 13, 2017
0c22eae
Add docker compose file and update README
robbyoconnor Jul 13, 2017
f677aef
Merge pull request #25 from robbyoconnor/add-docker-compose
kylemanna Jul 14, 2017
df8a6fb
Update MM to release 80
robbyoconnor Jul 15, 2017
a1beead
Merge pull request #27 from robbyoconnor/master
kylemanna Jul 15, 2017
3a961ec
CCache doesn't seem to be working -- add this in the entrypoint
robbyoconnor Jul 15, 2017
9e0d100
store ccache volume in the source directory
robbyoconnor Jul 15, 2017
de429a4
Merge pull request #29 from robbyoconnor/master
kylemanna Jul 16, 2017
e494ee9
MM now uses release 80.
robbyoconnor Jul 19, 2017
dd9995a
Merge pull request #33 from robbyoconnor/patch-1
kylemanna Jul 19, 2017
9e3ce45
Revert "nougat: First pass at building 7.0"
jcormier Oct 17, 2017
5e79e22
Make sure we tag image as 4.4-kitkat
jcormier Oct 17, 2017
eebafe2
aosp should default to 4.4-kitkat in the 4.4-kitkat branch
jcormier Oct 17, 2017
4a911ca
Revert "Dockerfile: install latest version of JDK"
jcormier Oct 17, 2017
df86c9d
Revert "lollipop: Update to use OpenJDK 7"
jcormier Oct 17, 2017
10488db
Add jdk-6u45-linux-x64.bin file so webupd8team java install works... …
jcormier Oct 17, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ RUN echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886 && \
echo oracle-java6-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selections

# http://www.webupd8.org/2012/11/oracle-sun-java-6-installer-available.html
# Java 6 is no longer supported by Oracle. The binaries are no longer available for download, but if you have an Oracle account, you can still download it after logging in.
# The Oracle Java 6 installer in this article will continue to work only if you manually download Oracle JDK 6 (version 6u45), place it in the /var/cache/oracle-jdk6-installer/ folder on your computer, then install "oracle-java6-installer" as explained below in this article.
# http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase6-419409.html
# http://download.oracle.com/otn/java/jdk/6u45-b06/jdk-6u45-linux-x64.bin
COPY utils/jdk-6u45-linux-x64.bin /var/cache/oracle-jdk6-installer/

# /bin/sh points to Dash by default, reconfigure to use bash until Android
# build becomes POSIX compliant
RUN echo "dash dash/sh boolean false" | debconf-set-selections && \
Expand All @@ -23,26 +30,22 @@ RUN apt-get update && \
lib32readline-gplv2-dev lib32z1-dev libesd0-dev libncurses5-dev \
libsdl1.2-dev libwxgtk2.8-dev libxml2-utils lzop \
oracle-java6-installer oracle-java6-set-default \
pngcrush schedtool xsltproc zip zlib1g-dev && \
pngcrush schedtool xsltproc zip zlib1g-dev graphviz && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ADD https://commondatastorage.googleapis.com/git-repo-downloads/repo /usr/local/bin/
RUN chmod 755 /usr/local/bin/*

# All builds will be done by user aosp
RUN useradd --create-home aosp
ADD gitconfig /home/aosp/.gitconfig
ADD ssh_config /home/aosp/.ssh/config
RUN chown aosp:aosp /home/aosp/.gitconfig
COPY gitconfig /root/.gitconfig
COPY ssh_config /root/.ssh/config

# The persistent data will be in these two directories, everything else is
# considered to be ephemeral
VOLUME ["/tmp/ccache", "/aosp"]

# Improve rebuild performance by enabling compiler cache
ENV USE_CCACHE 1
ENV CCACHE_DIR /tmp/ccache

# Work in the build directory, repo is expected to be init'd here
USER aosp
WORKDIR /aosp

COPY utils/docker_entrypoint.sh /root/docker_entrypoint.sh
ENTRYPOINT ["/root/docker_entrypoint.sh"]
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
DOCKER = docker
IMAGE = kylemanna/aosp:4.4-kitkat

aosp: Dockerfile
$(DOCKER) build -t $(IMAGE) .

all: aosp

.PHONY: all
70 changes: 51 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
Android Open Source Project Docker Build Environment
====================================================

[![Docker Stars](https://img.shields.io/docker/stars/kylemanna/aosp.svg)](https://hub.docker.com/r/kylemanna/aosp/)
[![Docker Pulls](https://img.shields.io/docker/pulls/kylemanna/aosp.svg)](https://hub.docker.com/r/kylemanna/aosp/)
[![ImageLayers](https://images.microbadger.com/badges/image/kylemanna/aosp.svg)](https://microbadger.com/#/images/kylemanna/aosp)

Minimal build environment for AOSP with handy automation wrapper scripts.

Developers can use the Docker image to build directly while running the
distribution of choice, without having to worry about breaking the AOSP build
due to package updates as is sometimes common on rolling distributions like
Arch Linux.
distribution of choice, without having to worry about breaking the delicate
AOSP build due to package updates as is sometimes common on bleeding edge
rolling distributions like Arch Linux.

Production build servers and integration test servers should also use the same
Docker image and environment. This eliminate most surprises in breakages by
Docker image and environment. This eliminates most surprise breakages by
by empowering developers and production builds to use the exact same
environment. The hope is that breakages will be caught earlier by the devs.

This only works (well) on Linux. Running this via `boot2docker` will result in
a very painful performacne hit due to VirtualBox's `vboxsf` shared folder
service which works terrible for **very** large builds like AOSP. It might
work, but consider youself warned. If you're aware of another way to get
around this, send a pull request!
environment. The devs will catch the issues with build environment first.

For *Mac OS X* and *Windows* users, consider
[kylemanna/vagrant-aosp](https://github.com/kylemanna/vagrant-aosp) as a good
virtual machine to enable development.
This works well on Linux. Running this via `boot2docker` (and friends) will
result in a very painful performacne hit due to VirtualBox's `vboxsf` shared
folder service which works terrible for **very** large file shares like AOSP.
It might work, but consider yourself warned. If you're aware of another way to
get around this, send a pull request!


Quickstart
Expand All @@ -44,11 +44,12 @@ For the terribly impatient.
initializes the repo, fetches all source code, and builds.
5. In parallel you are expected to be drinking because I save you some time.

mkdir nougat ; cd nougat
export AOSP_VOL=$PWD
curl -O https://raw.githubusercontent.com/kylemanna/docker-aosp/master/tests/build-nougat.sh
bash ./build-nougat.sh

mkdir kitkat ; cd kitkat
export AOSP_VOL=$PWD
curl -O https://raw.githubusercontent.com/kylemanna/docker-aosp/master/tests/build-kitkat.sh
bash ./build-kitkat.sh
This takes about 2 hours to download and build on i5-2500k with 100Mb/s network connection.

How it Works
------------
Expand All @@ -69,10 +70,41 @@ Docker container. For example to run `repo sync` in the Docker container:

The `aosp` wrapper doesn't work well with setting up environments, but with
some bash magic, this can be side stepped with short little scripts. See
`tests/build-kitkat.sh` for an example of a complete fetch and build of AOSP.
`tests/build-nougat.sh` for an example of a complete fetch and build of AOSP.

[Docker Compose][]
------

A [Docker Compose][] file is provided in the root of this repository, you can tweak it as need be:

```yaml
version: "2"

services:
aosp:
image: kylemanna/aosp:latest
volumes:
- /tmp/ccache:/ccache
- ~/aosp:/aosp
```
Example run: `docker-compose run --rm aosp repo sync -j4` -- your android build directory will be in `~/aosp`.

Issues
------

There are some known issues with using Docker Toolbox on macOS and current
virtualization technologies resulting in unusual user ID assignments and very
poor performing virtualization file sharing implementations with things like
VirtualBox. It's recommended to run this image completely in a virtual machine
with enough space to fit the entire build (80GB+) as opposed to mapping the
build to the local macOS file system via VirtualBox or similar.

Tested
------

* Android Kitkat `android-4.4.4_r2.0.1`
* Android Lollipop `android-5.0.2_r1`
* Android Marshmallow `android-6.0.1_r80`
* Android Nougat `android-7.0.0_r14`

[Docker Compose]: https://docs.docker.com/compose
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: "2"

services:
aosp:
image: kylemanna/aosp:latest
volumes:
- ~/aosp/ccache:/tmp/ccache
- ~/aosp:/aosp
- ~/.gitconfig:/root/.gitconfig
55 changes: 55 additions & 0 deletions tests/build-lollipop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash
#
# Test script file that maps itself into a docker container and runs
#
# Example invocation:
#
# $ AOSP_VOL=$PWD/build ./build-lollipop.sh
#
set -ex

if [ "$1" = "docker" ]; then
TEST_BRANCH=${TEST_BRANCH:-android-5.0.2_r1}
TEST_URL=${TEST_URL:-https://android.googlesource.com/platform/manifest}

cpus=$(grep ^processor /proc/cpuinfo | wc -l)

repo init --depth 1 -u "$TEST_URL" -b "$TEST_BRANCH"

# Use default sync '-j' value embedded in manifest file to be polite
repo sync

prebuilts/misc/linux-x86/ccache/ccache -M 10G

source build/envsetup.sh
lunch aosp_arm-eng
make -j $cpus
else
aosp_url="https://raw.githubusercontent.com/kylemanna/docker-aosp/master/utils/aosp"
args="bash run.sh docker"
export AOSP_EXTRA_ARGS="-v $(cd $(dirname $0) && pwd -P)/$(basename $0):/usr/local/bin/run.sh:ro"
export AOSP_IMAGE="kylemanna/aosp:5.0-lollipop"

#
# Try to invoke the aosp wrapper with the following priority:
#
# 1. If AOSP_BIN is set, use that
# 2. If aosp is found in the shell $PATH
# 3. Grab it from the web
#
if [ -n "$AOSP_BIN" ]; then
$AOSP_BIN $args
elif [ -x "../utils/aosp" ]; then
../utils/aosp $args
elif [ -n "$(type -P aosp)" ]; then
aosp $args
else
if [ -n "$(type -P curl)" ]; then
bash <(curl -s $aosp_url) $args
elif [ -n "$(type -P wget)" ]; then
bash <(wget -q $aosp_url -O -) $args
else
echo "Unable to run the aosp binary"
fi
fi
fi
55 changes: 55 additions & 0 deletions tests/build-marshmallow.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash
#
# Test script file that maps itself into a docker container and runs
#
# Example invocation:
#
# $ AOSP_VOL=$PWD/build ./build-marshmallow.sh
#
set -ex

if [ "$1" = "docker" ]; then
TEST_BRANCH=${TEST_BRANCH:-android-6.0.1_r80}
TEST_URL=${TEST_URL:-https://android.googlesource.com/platform/manifest}

cpus=$(grep ^processor /proc/cpuinfo | wc -l)

repo init --depth 1 -u "$TEST_URL" -b "$TEST_BRANCH"

# Use default sync '-j' value embedded in manifest file to be polite
repo sync

prebuilts/misc/linux-x86/ccache/ccache -M 10G

source build/envsetup.sh
lunch aosp_arm-eng
make -j $cpus
else
aosp_url="https://raw.githubusercontent.com/kylemanna/docker-aosp/master/utils/aosp"
args="bash run.sh docker"
export AOSP_EXTRA_ARGS="-v $(cd $(dirname $0) && pwd -P)/$(basename $0):/usr/local/bin/run.sh:ro"
export AOSP_IMAGE="kylemanna/aosp:6.0-marshmallow"

#
# Try to invoke the aosp wrapper with the following priority:
#
# 1. If AOSP_BIN is set, use that
# 2. If aosp is found in the shell $PATH
# 3. Grab it from the web
#
if [ -n "$AOSP_BIN" ]; then
$AOSP_BIN $args
elif [ -x "../utils/aosp" ]; then
../utils/aosp $args
elif [ -n "$(type -P aosp)" ]; then
aosp $args
else
if [ -n "$(type -P curl)" ]; then
bash <(curl -s $aosp_url) $args
elif [ -n "$(type -P wget)" ]; then
bash <(wget -q $aosp_url -O -) $args
else
echo "Unable to run the aosp binary"
fi
fi
fi
41 changes: 34 additions & 7 deletions utils/aosp
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,48 @@
set -e

# Override from environment
AOSP_IMAGE=${AOSP_IMAGE:-kylemanna/aosp}
AOSP_VOL=${AOSP_VOL:-/vol0}

AOSP_IMAGE=${AOSP_IMAGE:-kylemanna/aosp:4.4-kitkat}
AOSP_ARGS=${AOSP_ARGS:---rm -it}

AOSP_VOL=${AOSP_VOL:-~/aosp-root}
AOSP_VOL=${AOSP_VOL%/} # Trim trailing slash if needed
AOSP_VOL_AOSP=${AOSP_VOL_AOSP:-$AOSP_VOL/aosp}
AOSP_VOL_AOSP=${AOSP_VOL_AOSP%/} # Trim trailing slash if needed
AOSP_VOL_CCACHE=${AOSP_VOL_CCACHE:-$AOSP_VOL/ccache}
AOSP_VOL_CCACHE=${AOSP_VOL_CCACHE%/} # Trim trailing slash if needed

# Convenience function
function aosp_create_dir_if_needed {
directory=$1
msg="aosp: Checking if $directory exists"
echo "$msg"
if [ ! -d "$directory" ]; then
echo "$msg - unexistent"
msg="Creating $directory"
echo "$msg"
mkdir -p $directory
fi
echo "$msg - ok"
}

if [ ! -d "$AOSP_VOL_AOSP" -o ! -d "$AOSP_VOL_CCACHE" ]; then
sudo mkdir -p $AOSP_VOL_AOSP $AOSP_VOL_CCACHE
sudo chmod 777 $AOSP_VOL_AOSP $AOSP_VOL_CCACHE
# Create AOSP_VOL_AOSP
aosp_create_dir_if_needed $AOSP_VOL_AOSP
aosp_create_dir_if_needed $AOSP_VOL_CCACHE

uid=$(id -u)

# Set uid and gid to match host current user as long as NOT root
if [ $uid -ne "0" ]; then
AOSP_HOST_ID_ARGS="-e USER_ID=$uid -e GROUP_ID=$(id -g)"
fi

if [ -n "$SSH_AUTH_SOCK" ]; then
if [ -S "$SSH_AUTH_SOCK" ]; then
SSH_AUTH_ARGS="-v $SSH_AUTH_SOCK:/tmp/ssh_auth -e SSH_AUTH_SOCK=/tmp/ssh_auth"
fi

docker run $AOSP_ARGS $SSH_AUTH_ARGS $AOSP_EXTRA_ARGS \
echo ""

docker run $AOSP_ARGS $AOSP_HOST_ID_ARGS $SSH_AUTH_ARGS $AOSP_EXTRA_ARGS \
-v "$AOSP_VOL_AOSP:/aosp" -v "$AOSP_VOL_CCACHE:/tmp/ccache" \
$AOSP_IMAGE $@
52 changes: 52 additions & 0 deletions utils/docker_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash
set -e

# This script designed to be used a docker ENTRYPOINT "workaround" missing docker
# feature discussed in docker/docker#7198, allow to have executable in the docker
# container manipulating files in the shared volume owned by the USER_ID:GROUP_ID.
#
# It creates a user named `aosp` with selected USER_ID and GROUP_ID (or
# 1000 if not specified).

# Example:
#
# docker run -ti -e USER_ID=$(id -u) -e GROUP_ID=$(id -g) imagename bash
#

# Reasonable defaults if no USER_ID/GROUP_ID environment variables are set.
if [ -z ${USER_ID+x} ]; then USER_ID=1000; fi
if [ -z ${GROUP_ID+x} ]; then GROUP_ID=1000; fi

# ccache
export CCACHE_DIR=/tmp/ccache
export USE_CCACHE=1

msg="docker_entrypoint: Creating user UID/GID [$USER_ID/$GROUP_ID]" && echo $msg
groupadd -g $GROUP_ID -r aosp && \
useradd -u $USER_ID --create-home -r -g aosp aosp
echo "$msg - done"

msg="docker_entrypoint: Copying .gitconfig and .ssh/config to new user home" && echo $msg
cp /root/.gitconfig /home/aosp/.gitconfig && \
chown aosp:aosp /home/aosp/.gitconfig && \
mkdir -p /home/aosp/.ssh && \
cp /root/.ssh/config /home/aosp/.ssh/config && \
chown aosp:aosp -R /home/aosp/.ssh &&
echo "$msg - done"

msg="docker_entrypoint: Creating /tmp/ccache and /aosp directory" && echo $msg
mkdir -p /tmp/ccache /aosp
chown aosp:aosp /tmp/ccache /aosp
echo "$msg - done"

echo ""

# Default to 'bash' if no arguments are provided
args="$@"
if [ -z "$args" ]; then
args="bash"
fi

# Execute command as `aosp` user
export HOME=/home/aosp
exec sudo -E -u aosp $args
Binary file added utils/jdk-6u45-linux-x64.bin
Binary file not shown.