From ae71c4c41b9242fd65fe680f237ae1214d2ddc46 Mon Sep 17 00:00:00 2001 From: Budleigh Salterton driving a Miura Date: Thu, 31 Mar 2016 21:51:28 +0200 Subject: [PATCH] Add -f switch, dont remove containers --- CHANGELOG.md | 3 +++ run.sh | 28 +++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) mode change 100644 => 100755 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md old mode 100644 new mode 100755 index a5a2f4f..6ddef3f --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased][unreleased] +### Added +- Use -f to force rebuild the source. +- If build fails don't remove intermediate containers ## [0.5.0] - 2016-03-14 ### Added diff --git a/run.sh b/run.sh index 6a359a8..653df21 100755 --- a/run.sh +++ b/run.sh @@ -2,14 +2,31 @@ cd $(dirname $0) -SOURCE=$(pwd)/android -CCACHE=$(pwd)/ccache +SOURCE=$(readlink -f $(pwd)/android) +CCACHE=$(readlink -f $(pwd)/ccache) CONTAINER_HOME=/home/cmbuild CONTAINER=cyanogenmod REPOSITORY=stucki/cyanogenmod TAG=cm-13.0 FORCE_BUILD=0 + +while [[ $# > 0 ]] +do +key="$1" + +case $key in + -r|--rebuild) + FORCE_BUILD=1 + ;; + *) + shift # past argument or value + ;; +esac +shift + +done + # Create shared folders mkdir -p $SOURCE mkdir -p $CCACHE @@ -26,14 +43,19 @@ elif [[ $FORCE_BUILD = 1 ]] || ! echo "$IMAGE_EXISTS" | grep -q "$TAG"; then echo "Building Docker image $REPOSITORY:$TAG..." docker build -t $REPOSITORY:$TAG . + OK=$? # After successful build, delete existing containers IS_EXISTING=$(docker inspect -f '{{.Id}}' $CONTAINER 2>/dev/null) - if [[ -n "$IS_EXISTING" ]]; then + if [[ $OK -eq 0 ]] && [[ -n "$IS_EXISTING" ]]; then docker rm $CONTAINER fi fi +if [[ $OK -ne 0 ]]; then + exit 1; +fi + # With the given name $CONTAINER, reconnect to running container, start # an existing/stopped container or run a new one if one does not exist. IS_RUNNING=$(docker inspect -f '{{.State.Running}}' $CONTAINER 2>/dev/null)