├── .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 | 7 | ## [0.8.0] - 2018-11-19 8 | ### Added 9 | - Update build dependencies 10 | - Adjust LineageOS version to lineage-15.1 11 | 12 | ## [0.7.0] - 2017-08-05 13 | ### Added 14 | - Rename the project from "docker-cyanogenmod" to "docker-lineageos" 15 | - Change all references of "CyanogenMod" to "LineageOS", see http://lineageos.org/ 16 | - Rename user "cmbuild" to "build" 17 | - Adjust LineageOS version to cm-14.1 18 | 19 | ## [0.6.0] - 2016-08-20 20 | ### Added 21 | - Switch build OS to Ubuntu 16.04 22 | - Add -r switch in run.sh to force a rebuild of the Docker image 23 | - Add -u switch in run.sh to enable USB inside the container 24 | - If build fails, don't remove intermediate containers 25 | - Added bash completion, wget and nano 26 | - Simplier home creation 27 | 28 | ## [0.5.0] - 2016-03-14 29 | ### Added 30 | - Install maven (now required for building CyanogenMod) 31 | - Remove workaround for running as non-root (no longer needed) 32 | - Remove workaround for ischroot (no longer needed) 33 | - Remove a permission fix (no longer needed) 34 | - build: Sync package list with CyanogenMod Wiki 35 | 36 | ### Fixed 37 | - build: Always pull Ubuntu image during Docker build to be sure it's up 38 | to date 39 | 40 | ## [0.4.0] - 2016-01-22 41 | ### Added 42 | - Adjust CyanogenMod version to cm-13.0 43 | - Install liblz4-tool + bc (required for building CyanogenMod) 44 | 45 | ## [0.3.1] - 2015-04-03 46 | ### Fixed 47 | - Fix check if build is needed 48 | - After successful build, delete existing containers 49 | 50 | ## [0.3.0] - 2015-03-31 51 | ### Added 52 | - Don't run as root. Shared folders are now created with uid/gid 1000. 53 | This is the uid of the default user on most systems, it should allow 54 | you to run "repo sync" etc. on the host machine (outside of the 55 | Docker container). NOTE: Ownership of existing folders 56 | (host machine: android/ + ccache/) will be fixed automatically on the 57 | first run. If you notice any problems, try to fix the ownership 58 | manually or remove the two folders on the host machine. 59 | - Move ccache initialization to startup.sh. This fixes a major problem 60 | with ccache being initialized before the volume is mounted. 61 | The contents of /srv/ccache were therefore empty and 62 | CCACHE_MAXSIZE=50G was not set. The result was that ccache could only 63 | use up to 1 GB of cache data (default value). Thanks to a bigger 64 | cache, builds gets finished a lot faster thank before. 65 | - Small Docker improvements. Add the CM version to the Docker image 66 | tag. Use cached images during "docker build". Be more verbose. 67 | - Add this CHANGELOG.md file based on 68 | https://github.com/olivierlacan/keep-a-changelog/ 69 | 70 | ## [0.2.0] - 2015-01-20 71 | ### Added 72 | - Add changes to build CyanogenMod 12.0 73 | - Add FORCE_BUILD flag 74 | - Install rsync 75 | 76 | ### Fixed 77 | - Fix issues with SELinux 78 | 79 | ## [0.1.0] - 2014-09-17 80 | ### Added 81 | - Initial release 82 | 83 | [unreleased]: https://github.com/stucki/docker-cyanogenmod/compare/v0.3.1...HEAD 84 | [0.3.1]: https://github.com/stucki/docker-cyanogenmod/compare/v0.3.0...v0.3.1 85 | [0.3.0]: https://github.com/stucki/docker-cyanogenmod/compare/v0.2.0...v0.3.0 86 | [0.2.0]: https://github.com/stucki/docker-cyanogenmod/compare/v0.1.0...v0.2.0 87 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Build environment for LineageOS 2 | 3 | FROM ubuntu:16.04 4 | MAINTAINER Michael Stucki 5 | 6 | 7 | ENV \ 8 | # ccache specifics 9 | CCACHE_SIZE=50G \ 10 | CCACHE_DIR=/srv/ccache \ 11 | USE_CCACHE=1 \ 12 | CCACHE_COMPRESS=1 \ 13 | # Extra include PATH, it may not include /usr/local/(s)bin on some systems 14 | PATH=$PATH:/usr/local/bin/ 15 | 16 | RUN sed -i 's/main$/main universe/' /etc/apt/sources.list \ 17 | && export DEBIAN_FRONTEND=noninteractive \ 18 | && apt-get update \ 19 | && apt-get upgrade -y \ 20 | && apt-get install -y \ 21 | # Install build dependencies (source: https://wiki.cyanogenmod.org/w/Build_for_bullhead) 22 | bc \ 23 | bison \ 24 | build-essential \ 25 | ccache \ 26 | curl \ 27 | flex \ 28 | g++-multilib \ 29 | gcc-multilib \ 30 | git \ 31 | gnupg \ 32 | gperf \ 33 | imagemagick \ 34 | lib32ncurses5-dev \ 35 | lib32readline-dev \ 36 | lib32z1-dev \ 37 | liblz4-tool \ 38 | libncurses5-dev \ 39 | libsdl1.2-dev \ 40 | libssl-dev \ 41 | libwxgtk3.0-dev \ 42 | libxml2 \ 43 | libxml2-utils \ 44 | lzop \ 45 | pngcrush \ 46 | rsync \ 47 | schedtool \ 48 | squashfs-tools \ 49 | xsltproc \ 50 | zip \ 51 | zlib1g-dev \ 52 | # Install Java Development Kit 53 | openjdk-8-jdk \ 54 | # Install additional packages which are useful for building Android 55 | android-tools-adb \ 56 | android-tools-fastboot \ 57 | bash-completion \ 58 | bsdmainutils \ 59 | file \ 60 | nano \ 61 | screen \ 62 | sudo \ 63 | tig \ 64 | vim \ 65 | wget \ 66 | && rm -rf /var/lib/apt/lists/* 67 | 68 | ARG hostuid=1000 69 | ARG hostgid=1000 70 | 71 | RUN \ 72 | groupadd --gid $hostgid --force build && \ 73 | useradd --gid $hostgid --uid $hostuid --non-unique build && \ 74 | rsync -a /etc/skel/ /home/build/ 75 | 76 | RUN curl https://storage.googleapis.com/git-repo-downloads/repo > /usr/local/bin/repo \ 77 | && chmod a+x /usr/local/bin/repo 78 | 79 | # Add sudo permission 80 | RUN echo "build ALL=NOPASSWD: ALL" > /etc/sudoers.d/build 81 | 82 | ADD startup.sh /home/build/startup.sh 83 | RUN chmod a+x /home/build/startup.sh 84 | 85 | # Fix ownership 86 | RUN chown -R build:build /home/build 87 | 88 | VOLUME /home/build/android 89 | VOLUME /srv/ccache 90 | 91 | USER build 92 | WORKDIR /home/build/android 93 | 94 | CMD /home/build/startup.sh 95 | -------------------------------------------------------------------------------- /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-lineageos 2 | ================== 3 | 4 | Create a [Docker] based environment to build [LineageOS]. 5 | 6 | This Dockerfile will create a docker container which is based on Ubuntu 16.04. 7 | It will install the "repo" utility and any other build dependencies which are required to compile LineageOS (formerly known as CyanogenMod). 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 LineageOS is a huge project. 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/stucki/docker-lineageos.git 21 | cd docker-lineageos 22 | ./run.sh 23 | ``` 24 | 25 | The `run.sh` script accepts the following switches: 26 | 27 | | Switch | Alternative | Description | 28 | |---|---|---| 29 | | `-u` | `--enable-usb` | Runs the container in privileged mode (this way you can use adb right from the container) | 30 | | `-r` | `--rebuild` | Force rebuild the image from scratch | 31 | | `-ws` | `--with-su` | Sets the WITH_SU environment variable to true (your builds will include the su binary) | 32 | 33 | The container uses "screen" to run the shell. This means that you will be able to open additional shells using [screen keyboard shortcuts][Screen_Shortcuts]. 34 | 35 | ### ADB in the container 36 | If you're on Linux and want to use adb from within the container running with `-u` might not be enough. Make sure you have the [Android udev rules](https://github.com/M0Rf30/android-udev-rules/blob/master/51-android.rules) installed on your host system so you can access your device without needing superuser permissions. 37 | 38 | ### How to build LineageOS for your device 39 | 40 | ``` 41 | repo init -u git://github.com/lineageos/android.git -b lineage-15.1 42 | repo sync -c -j 16 43 | source build/envsetup.sh 44 | breakfast # example: breakfast grouper 45 | brunch # example: brunch grouper 46 | ``` 47 | 48 | ### Links 49 | 50 | For further information, check the following links: 51 | 52 | * [CyanogenMod Building Basics][Cyanogenmod_Building_Basics] 53 | * [Build Instructions for Google Nexus 5][LineageOS_Build_Nexus5] (example device, search the wiki for other devices) 54 | 55 | ### More information 56 | 57 | * [Discussion thread @ XDA developers] 58 | 59 | ================== 60 | 61 | [Docker]: https://www.docker.io/ 62 | [LineageOS]: http://lineageos.org/ 63 | [Docker_Installation]: https://www.docker.io/gettingstarted/ 64 | [Screen_Shortcuts]: http://www.pixelbeat.org/lkdb/screen.html 65 | [CyanogenMod_Building_Basics]: https://web-beta.archive.org/web/20161224192643/http://wiki.cyanogenmod.org/w/Development 66 | [LineageOS_Build_Nexus5]: https://wiki.lineageos.org/devices/hammerhead/build 67 | [Discussion thread @ XDA developers]: http://forum.xda-developers.com/showthread.php?t=2650345 68 | [dotcloud/docker#2224]: https://github.com/dotcloud/docker/issues/2224 69 | -------------------------------------------------------------------------------- /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=lineageos 11 | REPOSITORY=stucki/lineageos 12 | TAG=lineage-15.1 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 -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/sh 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 screen session 14 | screen -s /bin/bash 15 | --------------------------------------------------------------------------------