diff --git a/Dockerfile b/Dockerfile index 9813841..340070c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,16 @@ 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/ + RUN sed -i 's/main$/main universe/' /etc/apt/sources.list \ && export DEBIAN_FRONTEND=noninteractive \ && apt-get update \ @@ -64,9 +74,8 @@ RUN \ useradd --gid $hostgid --uid $hostuid --non-unique build && \ rsync -a /etc/skel/ /home/build/ -RUN mkdir /home/build/bin -RUN curl https://storage.googleapis.com/git-repo-downloads/repo > /home/build/bin/repo -RUN chmod a+x /home/build/bin/repo +RUN curl https://storage.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 @@ -77,14 +86,10 @@ 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 -CMD /home/build/startup.sh - USER build WORKDIR /home/build/android + +CMD /home/build/startup.sh diff --git a/android-env-vars.sh b/android-env-vars.sh deleted file mode 100644 index ff569ee..0000000 --- a/android-env-vars.sh +++ /dev/null @@ -1,4 +0,0 @@ -export PATH=/home/build/bin:$PATH -export USE_CCACHE=1 -export CCACHE_DIR=/srv/ccache -export CCACHE_COMPRESS=1 diff --git a/run.sh b/run.sh index 45f6840..b6d20de 100755 --- a/run.sh +++ b/run.sh @@ -34,16 +34,18 @@ 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 +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 \ @@ -52,9 +54,8 @@ 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 + if docker inspect $CONTAINER &>/dev/null; then + docker rm $CONTAINER >/dev/null fi fi diff --git a/startup.sh b/startup.sh index be5f50a..59e2c4b 100644 --- a/startup.sh +++ b/startup.sh @@ -1,12 +1,14 @@ #!/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" +# 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