diff --git a/Dockerfile b/Dockerfile index 39f4492..42a053c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,11 +9,8 @@ RUN sed -i 's/main$/main universe/' /etc/apt/sources.list RUN apt-get -qq update RUN apt-get install -y software-properties-common bsdmainutils curl file screen -RUN add-apt-repository ppa:nilarimogard/webupd8 -RUN apt-get -qq update - RUN apt-get install -y android-tools-adb android-tools-fastboot -RUN apt-get install -y bison build-essential curl flex git-core gnupg gperf libesd0-dev libncurses5-dev libsdl1.2-dev libwxgtk2.8-dev libxml2 libxml2-utils lzop openjdk-6-jdk openjdk-6-jre pngcrush schedtool squashfs-tools xsltproc zip zlib1g-dev +RUN apt-get install -y bison build-essential flex git-core gnupg gperf libesd0-dev libncurses5-dev libsdl1.2-dev libwxgtk2.8-dev libxml2 libxml2-utils lzop openjdk-6-jdk openjdk-6-jre pngcrush schedtool squashfs-tools xsltproc zip zlib1g-dev RUN apt-get install -y g++-multilib gcc-multilib lib32ncurses5-dev lib32readline-gplv2-dev lib32z1-dev RUN apt-get install -y tig diff --git a/README.md b/README.md index 2b15a18..e420de7 100644 --- a/README.md +++ b/README.md @@ -10,23 +10,17 @@ The main working directory is a shared folder on the host system, so the Docker **NOTE:** Remember that CyanogenMod is a huge project. It will consume a large amount of disk space (~80 GB) and it can easily take hours to build. -### How to build +### How to run/build **NOTES:** * You will need to [install Docker][Docker_Installation] to proceed! +* If an image does not exists, ```docker build``` is executed first * When running ```docker build```, the whole folder incl. the "android" working directory is transferred to the Docker daemon. The only way to work around this currently is to move the "android" folder away, then rebuild, and move it back into place again. For more information, see [dotcloud/docker#2224]. ``` git clone https://github.com/stucki/docker-cyanogenmod.git cd docker-cyanogenmod -./build.sh -``` - -### How to run - -``` -cd docker-cyanogenmod ./run.sh ``` diff --git a/build.sh b/build.sh deleted file mode 100755 index 6100a81..0000000 --- a/build.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -cd $(dirname $0) - -SOURCE=$(pwd)/android - -# Create a shared folder which will be used as working directory. -test -d $SOURCE || mkdir $SOURCE - -docker build --no-cache --rm -t stucki/cyanogenmod . - -exit $? diff --git a/run.sh b/run.sh index faa0efa..b34098f 100755 --- a/run.sh +++ b/run.sh @@ -3,13 +3,32 @@ cd $(dirname $0) SOURCE=$(pwd)/android +CONTAINER_HOME=/home/cmbuild CONTAINER=cyanogenmod REPOSITORY=stucki/cyanogenmod -# Create a shared folder which will be used as working directory. -test -d $SOURCE || mkdir $SOURCE +# Create a shared folder which will be used as working directory if it +# does not already exists. +mkdir -p $SOURCE -# Try to start an existing/stopped container with the given name $CONTAINER. Otherwise, run a new one. -docker start -i $CONTAINER 2>/dev/null || docker run -v $SOURCE:/home/cmbuild/android -i -t --name $CONTAINER $REPOSITORY sh -c "screen -s /bin/bash" +# Build image if needed +IMAGE_EXISTS=$(docker images -q $REPOSITORY) +if [ $? -ne 0 ]; then + echo "docker command not found" + exit $? +elif [[ -z $IMAGE_EXISTS ]]; then + docker build --no-cache --rm -t $REPOSITORY . +fi + +# With the given name $CONTAINER, reconnect to running container, start +# an existing/stopped container or run a new one if one does not exists. +IS_RUNNING=$(docker inspect -f '{{.State.Running}}' $CONTAINER 2>/dev/null) +if [[ $IS_RUNNING == "true" ]]; then + docker attach $CONTAINER +elif [[ $IS_RUNNING == "false" ]]; then + docker start -i $CONTAINER +else + docker run -v $SOURCE:$CONTAINER_HOME/android -i -t --name $CONTAINER $REPOSITORY sh -c "screen -s /bin/bash"; +fi exit $?