From c66a2ba12d312561302d8ab938f3b1902070a130 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Tue, 30 May 2017 19:19:31 +0200 Subject: [PATCH 1/5] move repo command to /usr/local --- Dockerfile | 9 ++++++--- android-env-vars.sh | 1 - 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7575032..4d72965 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,10 @@ FROM ubuntu:16.04 MAINTAINER Michael Stucki +ENV \ +# Extra include PATH, it may not include /usr/local/(s)bin on some systems + PATH=$PATH:/usr/local/bin/ + RUN sed -i 's/main$/main universe/' /etc/apt/sources.list \ && export DEBIAN_FRONTEND=noninteractive \ && apt-get update \ @@ -63,9 +67,8 @@ RUN \ useradd --gid $hostgid --uid $hostuid --non-unique build && \ rsync -a /etc/skel/ /home/build/ -RUN mkdir /home/build/bin -RUN curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > /home/build/bin/repo -RUN chmod a+x /home/build/bin/repo +RUN curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > /usr/local/bin/repo \ + && chmod a+x /usr/local/bin/repo # Add sudo permission RUN echo "build ALL=NOPASSWD: ALL" > /etc/sudoers.d/build diff --git a/android-env-vars.sh b/android-env-vars.sh index ff569ee..141f7d1 100644 --- a/android-env-vars.sh +++ b/android-env-vars.sh @@ -1,4 +1,3 @@ -export PATH=/home/build/bin:$PATH export USE_CCACHE=1 export CCACHE_DIR=/srv/ccache export CCACHE_COMPRESS=1 From 3047d501cdb1ad05c8fca11af021e7272fea69cd Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Tue, 30 May 2017 19:24:02 +0200 Subject: [PATCH 2/5] remove android-env-vars.sh --- Dockerfile | 10 ++++++---- android-env-vars.sh | 3 --- startup.sh | 4 ++-- 3 files changed, 8 insertions(+), 9 deletions(-) delete mode 100644 android-env-vars.sh diff --git a/Dockerfile b/Dockerfile index 4d72965..b613c24 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,13 @@ FROM ubuntu:16.04 MAINTAINER Michael Stucki + ENV \ +# ccache specifics + CCACHE_SIZE=50G \ + CCACHE_DIR=/srv/ccache \ + USE_CCACHE=1 \ + CCACHE_COMPRESS=1 \ # Extra include PATH, it may not include /usr/local/(s)bin on some systems PATH=$PATH:/usr/local/bin/ @@ -79,10 +85,6 @@ RUN chmod a+x /home/build/startup.sh # Fix ownership RUN chown -R build:build /home/build -# Set global variables -ADD android-env-vars.sh /etc/android-env-vars.sh -RUN echo "source /etc/android-env-vars.sh" >> /etc/bash.bashrc - VOLUME /home/build/android VOLUME /srv/ccache diff --git a/android-env-vars.sh b/android-env-vars.sh deleted file mode 100644 index 141f7d1..0000000 --- a/android-env-vars.sh +++ /dev/null @@ -1,3 +0,0 @@ -export USE_CCACHE=1 -export CCACHE_DIR=/srv/ccache -export CCACHE_COMPRESS=1 diff --git a/startup.sh b/startup.sh index be5f50a..701a16f 100644 --- a/startup.sh +++ b/startup.sh @@ -1,9 +1,9 @@ #!/bin/sh # Initialize ccache if needed -if [ ! -f /srv/ccache/ccache.conf ]; then +if [ ! -f ${CCACHE_DIR}/ccache.conf ]; then echo "Initializing ccache in /srv/ccache..." - CCACHE_DIR=/srv/ccache ccache -M 50G + ccache -M ${CCACHE_SIZE} fi export USER="build" From 919db8dcee4d3452a0dc6b2a43abfd3f662acaa9 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Tue, 30 May 2017 19:38:12 +0200 Subject: [PATCH 3/5] fix user permission specific problems and add comments --- Dockerfile | 4 ++-- run.sh | 3 +++ startup.sh | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index b613c24..3f4756c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -88,7 +88,7 @@ RUN chown -R build:build /home/build VOLUME /home/build/android VOLUME /srv/ccache -CMD /home/build/startup.sh - USER build WORKDIR /home/build/android + +CMD /home/build/startup.sh diff --git a/run.sh b/run.sh index 4d2904f..ec14b45 100755 --- a/run.sh +++ b/run.sh @@ -30,6 +30,9 @@ while [[ $# > 0 ]]; do done # Create shared folders +# Although Docker would create non-existing directories on the fly, +# we need to have them owned by the user (and not root), to be able +# to write in them, which is a necessity for startup.sh mkdir -p $SOURCE mkdir -p $CCACHE diff --git a/startup.sh b/startup.sh index 701a16f..59e2c4b 100644 --- a/startup.sh +++ b/startup.sh @@ -6,7 +6,9 @@ if [ ! -f ${CCACHE_DIR}/ccache.conf ]; then ccache -M ${CCACHE_SIZE} fi -export USER="build" +# in Docker, the USER variable is unset by default +# but some programs (like jack toolchain) rely on it +export USER="$(whoami)" # Launch screen session screen -s /bin/bash From cd99304c1daab7ad91b6509123d115f9f4997dc5 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Tue, 6 Jun 2017 11:27:31 +0200 Subject: [PATCH 4/5] stop "docker rm" spitting lineageos out --- run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.sh b/run.sh index ec14b45..32681d1 100755 --- a/run.sh +++ b/run.sh @@ -53,7 +53,7 @@ elif [[ $FORCE_BUILD = 1 ]] || ! echo "$IMAGE_EXISTS" | grep -q "$TAG"; then # After successful build, delete existing containers IS_EXISTING=$(docker inspect -f '{{.Id}}' $CONTAINER 2>/dev/null) || true if [[ -n $IS_EXISTING ]]; then - docker rm $CONTAINER + docker rm $CONTAINER >/dev/null fi fi From c685d7b0fc13e57e8b207307be039f8ca7da1948 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Tue, 6 Jun 2017 11:44:19 +0200 Subject: [PATCH 5/5] make checks easier --- run.sh | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/run.sh b/run.sh index 32681d1..d520482 100755 --- a/run.sh +++ b/run.sh @@ -36,13 +36,12 @@ done mkdir -p $SOURCE mkdir -p $CCACHE +command -v docker >/dev/null \ + || { echo "command 'docker' not found."; exit 1; } + # Build image if needed -IMAGE_EXISTS=$(docker images $REPOSITORY) -if [ $? -ne 0 ]; then - echo "docker command not found" - exit $? -elif [[ $FORCE_BUILD = 1 ]] || ! echo "$IMAGE_EXISTS" | grep -q "$TAG"; then - echo "Building Docker image $REPOSITORY:$TAG..." +if [[ $FORCE_BUILD = 1 ]] || ! docker inspect $REPOSITORY:$TAG &>/dev/null; then + docker build \ --pull \ -t $REPOSITORY:$TAG \ @@ -51,8 +50,7 @@ elif [[ $FORCE_BUILD = 1 ]] || ! echo "$IMAGE_EXISTS" | grep -q "$TAG"; then . # After successful build, delete existing containers - IS_EXISTING=$(docker inspect -f '{{.Id}}' $CONTAINER 2>/dev/null) || true - if [[ -n $IS_EXISTING ]]; then + if docker inspect $CONTAINER &>/dev/null; then docker rm $CONTAINER >/dev/null fi fi