├── .dockerignore ├── .gitignore ├── CHANGELOG.md ├── Dockerfile ├── LICENSE ├── README.md ├── run.sh └── startup.sh /.dockerignore: -------------------------------------------------------------------------------- 1 | .git/ 2 | android/ 3 | ccache/ 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /android 2 | /ccache 3 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | All notable changes to this project will be documented in this file. 3 | This project adheres to [Semantic Versioning](http://semver.org/). 4 | 5 | ## [Unreleased][unreleased] 6 | ### Added 7 | - Rename the project from "docker-cyanogenmod" to "docker-lineageos" 8 | - Change all references of "CyanogenMod" to "LineageOS", see http://lineageos.org/ 9 | - Rename user "cmbuild" to "build" 10 | - Adjust LineageOS version to cm-14.1 11 | 12 | ## [0.6.0] - 2016-08-20 13 | ### Added 14 | - Switch build OS to Ubuntu 16.04 15 | - Add -r switch in run.sh to force a rebuild of the Docker image 16 | - Add -u switch in run.sh to enable USB inside the container 17 | - If build fails, don't remove intermediate containers 18 | - Added bash completion, wget and nano 19 | - Simplier home creation 20 | 21 | ## [0.5.0] - 2016-03-14 22 | ### Added 23 | - Install maven (now required for building CyanogenMod) 24 | - Remove workaround for running as non-root (no longer needed) 25 | - Remove workaround for ischroot (no longer needed) 26 | - Remove a permission fix (no longer needed) 27 | - build: Sync package list with CyanogenMod Wiki 28 | 29 | ### Fixed 30 | - build: Always pull Ubuntu image during Docker build to be sure it's up 31 | to date 32 | 33 | ## [0.4.0] - 2016-01-22 34 | ### Added 35 | - Adjust CyanogenMod version to cm-13.0 36 | - Install liblz4-tool + bc (required for building CyanogenMod) 37 | 38 | ## [0.3.1] - 2015-04-03 39 | ### Fixed 40 | - Fix check if build is needed 41 | - After successful build, delete existing containers 42 | 43 | ## [0.3.0] - 2015-03-31 44 | ### Added 45 | - Don't run as root. Shared folders are now created with uid/gid 1000. 46 | This is the uid of the default user on most systems, it should allow 47 | you to run "repo sync" etc. on the host machine (outside of the 48 | Docker container). NOTE: Ownership of existing folders 49 | (host machine: android/ + ccache/) will be fixed automatically on the 50 | first run. If you notice any problems, try to fix the ownership 51 | manually or remove the two folders on the host machine. 52 | - Move ccache initialization to startup.sh. This fixes a major problem 53 | with ccache being initialized before the volume is mounted. 54 | The contents of /srv/ccache were therefore empty and 55 | CCACHE_MAXSIZE=50G was not set. The result was that ccache could only 56 | use up to 1 GB of cache data (default value). Thanks to a bigger 57 | cache, builds gets finished a lot faster thank before. 58 | - Small Docker improvements. Add the CM version to the Docker image 59 | tag. Use cached images during "docker build". Be more verbose. 60 | - Add this CHANGELOG.md file based on 61 | https://github.com/olivierlacan/keep-a-changelog/ 62 | 63 | ## [0.2.0] - 2015-01-20 64 | ### Added 65 | - Add changes to build CyanogenMod 12.0 66 | - Add FORCE_BUILD flag 67 | - Install rsync 68 | 69 | ### Fixed 70 | - Fix issues with SELinux 71 | 72 | ## [0.1.0] - 2014-09-17 73 | ### Added 74 | - Initial release 75 | 76 | [unreleased]: https://github.com/stucki/docker-cyanogenmod/compare/v0.3.1...HEAD 77 | [0.3.1]: https://github.com/stucki/docker-cyanogenmod/compare/v0.3.0...v0.3.1 78 | [0.3.0]: https://github.com/stucki/docker-cyanogenmod/compare/v0.2.0...v0.3.0 79 | [0.2.0]: https://github.com/stucki/docker-cyanogenmod/compare/v0.1.0...v0.2.0 80 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Build environment for LineageOS 2 | 3 | FROM debian:buster 4 | MAINTAINER Caleb Xu 5 | 6 | ENV \ 7 | # ccache specifics 8 | CCACHE_SIZE=50G \ 9 | CCACHE_DIR=/srv/ccache \ 10 | USE_CCACHE=1 \ 11 | CCACHE_COMPRESS=1 \ 12 | # Configure Jack 13 | ANDROID_JACK_VM_ARGS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4G" \ 14 | # Extra include PATH, it may not include /usr/local/(s)bin on some systems 15 | PATH=$PATH:/usr/local/bin/ 16 | 17 | RUN sed -i 's/main$/main contrib non-free/' /etc/apt/sources.list \ 18 | && export DEBIAN_FRONTEND=noninteractive \ 19 | && apt-get update -y \ 20 | && apt-get clean -y \ 21 | && apt-get install -y locales \ 22 | && locale-gen --purge en_US.UTF-8 \ 23 | && echo -e 'LANG="en_US.UTF-8"\nLANGUAGE="en_US:en"\n' > /etc/default/locale \ 24 | && apt-get update -y \ 25 | && apt-get upgrade -y \ 26 | && apt-get install -y \ 27 | # Install build dependencies (source: https://wiki.cyanogenmod.org/w/Build_for_bullhead) 28 | bison \ 29 | build-essential \ 30 | curl \ 31 | flex \ 32 | git \ 33 | gnupg \ 34 | gperf \ 35 | kmod \ 36 | liblz4-tool \ 37 | libncurses5-dev \ 38 | libncursesw6 \ 39 | libsdl1.2-dev \ 40 | libwxgtk3.0-dev \ 41 | libxml2 \ 42 | libxml2-utils \ 43 | lzop \ 44 | maven \ 45 | openjdk-11-jdk-headless \ 46 | pngcrush \ 47 | procps \ 48 | python \ 49 | schedtool \ 50 | squashfs-tools \ 51 | xsltproc \ 52 | zip \ 53 | zlib1g-dev \ 54 | # For 64-bit systems 55 | g++-multilib \ 56 | gcc-multilib \ 57 | lib32ncurses5-dev \ 58 | lib32readline6-dev \ 59 | lib32z1-dev \ 60 | # Install additional packages which are useful for building Android 61 | android-tools-adb \ 62 | android-tools-fastboot \ 63 | bash-completion \ 64 | bc \ 65 | bsdmainutils \ 66 | ccache \ 67 | file \ 68 | git \ 69 | imagemagick \ 70 | nano \ 71 | rsync \ 72 | sudo \ 73 | tig \ 74 | tmux \ 75 | vim \ 76 | wget \ 77 | && rm -rf /var/lib/apt/lists/* 78 | 79 | ARG hostuid=1000 80 | ARG hostgid=1000 81 | 82 | ADD startup.sh /home/build/startup.sh 83 | RUN groupadd --gid $hostgid --force build \ 84 | && useradd --gid $hostgid --uid $hostuid --non-unique build \ 85 | && rsync -a /etc/skel/ /home/build/ \ 86 | && curl https://storage.googleapis.com/git-repo-downloads/repo > /usr/local/bin/repo \ 87 | && chmod a+x /usr/local/bin/repo \ 88 | && git config --system protocol.version 2 \ 89 | && echo "build ALL=NOPASSWD: ALL" > /etc/sudoers.d/build \ 90 | && chmod a+x /home/build/startup.sh \ 91 | && chown -R build:build /home/build 92 | 93 | VOLUME /home/build/android 94 | VOLUME /srv/ccache 95 | 96 | USER build 97 | WORKDIR /home/build/android 98 | 99 | CMD /home/build/startup.sh 100 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Michael Stucki 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | docker-android 2 | ================== 3 | 4 | Create a [Docker] based environment to build Android ROMs. 5 | 6 | This Dockerfile will create a docker container which is based on Debian Stretch. 7 | It will install the "repo" utility and any other build dependencies which are required to compile most Android ROMs. Some ROM distributions may have additional dependencies that need to be fulfilled. 8 | 9 | The main working directory is a shared folder on the host system, so the Docker container can be removed at any time. 10 | 11 | **NOTE:** Remember that Android ROMs are huge projects. It will consume a large amount of disk space (~80 GB) and it can easily take hours to build. 12 | 13 | ### How to run/build 14 | 15 | **NOTES:** 16 | * You will need to [install Docker][Docker_Installation] to proceed! 17 | * If an image does not exist, ```docker build``` is executed first 18 | 19 | ``` 20 | git clone https://github.com/alebcay/docker-android.git 21 | cd docker-android 22 | ./run.sh 23 | ``` 24 | 25 | The `run.sh` script accepts the following switches: 26 | 27 | * -u|--enable-usb - runs the container in privileged mode (this way you can use adb right from the container) 28 | * -r|--rebuild - force rebuild the image from scratch 29 | * -ws|--with-su - Sets the WITH_SU environment variable to true (your builds will include the su binary) 30 | 31 | The container uses "tmux" to run the shell. This means that you will be able to open additional shells using [tmux shortcuts](https://gist.github.com/andreyvit/2921703). 32 | 33 | ### Credits 34 | Based on [Michael Stucki's](https://github.com/stucki/) [docker-lineageos](https://github.com/stucki/docker-lineageos). This project builds off of `docker-lineageos` in the following ways: 35 | - Configures `backports` and `sid` repositories 36 | - Upgrades `git` to `>= 2.18` and configures it to take advantage of [Git protocol version 2](https://opensource.googleblog.com/2018/05/introducing-git-protocol-version-2.html) 37 | - Installs `libncursesw6`, needed by some newer Clang-based toolchains 38 | - Uses `tmux` instead of `screen` 39 | - Configures locales correctly to display Unicode characters so that custom ROM build scripts display properly 40 | 41 | [Docker]: https://www.docker.io/ 42 | [LineageOS]: http://lineageos.org/ 43 | [Docker_Installation]: https://www.docker.io/gettingstarted/ 44 | [Screen_Shortcuts]: http://www.pixelbeat.org/lkdb/screen.html 45 | [CyanogenMod_Building_Basics]: https://web-beta.archive.org/web/20161224192643/http://wiki.cyanogenmod.org/w/Development 46 | [LineageOS_Build_Nexus5]: https://wiki.lineageos.org/devices/hammerhead/build 47 | [Discussion thread @ XDA developers]: http://forum.xda-developers.com/showthread.php?t=2650345 48 | [dotcloud/docker#2224]: https://github.com/dotcloud/docker/issues/2224 49 | -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | cd $(dirname $0) 6 | 7 | SOURCE=$(pwd)/android 8 | CCACHE=$(pwd)/ccache 9 | CONTAINER_HOME=/home/build 10 | CONTAINER=aosp 11 | REPOSITORY=alebcay/androidbuild 12 | TAG=pie 13 | FORCE_BUILD=0 14 | PRIVILEGED= 15 | ENVIRONMENT= 16 | 17 | while [[ $# > 0 ]]; do 18 | key="$1" 19 | case $key in 20 | -r|--rebuild) 21 | FORCE_BUILD=1 22 | ;; 23 | -u|--enable-usb) 24 | PRIVILEGED="--privileged -v /dev/bus/usb:/dev/bus/usb" 25 | ;; 26 | -ws|--with-su) 27 | ENVIRONMENT="-e WITH_SU=true" 28 | ;; 29 | *) 30 | shift # past argument or value 31 | ;; 32 | esac 33 | shift 34 | done 35 | 36 | # Create shared folders 37 | # Although Docker would create non-existing directories on the fly, 38 | # we need to have them owned by the user (and not root), to be able 39 | # to write in them, which is a necessity for startup.sh 40 | mkdir -p $SOURCE 41 | mkdir -p $CCACHE 42 | 43 | command -v docker >/dev/null \ 44 | || { echo "command 'docker' not found."; exit 1; } 45 | 46 | # Build image if needed 47 | if [[ $FORCE_BUILD = 1 ]] || ! docker inspect $REPOSITORY:$TAG &>/dev/null; then 48 | 49 | docker build \ 50 | --pull \ 51 | -t $REPOSITORY:$TAG \ 52 | --build-arg hostuid=$(id -u) \ 53 | --build-arg hostgid=$(id -g) \ 54 | . 55 | 56 | # After successful build, delete existing containers 57 | if docker inspect $CONTAINER &>/dev/null; then 58 | docker rm $CONTAINER >/dev/null 59 | fi 60 | fi 61 | 62 | # With the given name $CONTAINER, reconnect to running container, start 63 | # an existing/stopped container or run a new one if one does not exist. 64 | IS_RUNNING=$(docker inspect -f '{{.State.Running}}' $CONTAINER 2>/dev/null) || true 65 | if [[ $IS_RUNNING == "true" ]]; then 66 | docker attach $CONTAINER 67 | elif [[ $IS_RUNNING == "false" ]]; then 68 | docker start -i $CONTAINER 69 | else 70 | docker run $PRIVILEGED -e LANG=C.UTF-8 -h docker-android -v $SOURCE:$CONTAINER_HOME/android:Z -v $CCACHE:/srv/ccache:Z -i -t $ENVIRONMENT --name $CONTAINER $REPOSITORY:$TAG 71 | fi 72 | 73 | exit $? 74 | -------------------------------------------------------------------------------- /startup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Initialize ccache if needed 4 | if [ ! -f ${CCACHE_DIR}/ccache.conf ]; then 5 | echo "Initializing ccache in /srv/ccache..." 6 | ccache -M ${CCACHE_SIZE} 7 | fi 8 | 9 | # in Docker, the USER variable is unset by default 10 | # but some programs (like jack toolchain) rely on it 11 | export USER="$(whoami)" 12 | 13 | # Launch tmux session 14 | tmux new-session /bin/bash 15 | --------------------------------------------------------------------------------