Keep Docker builds from thrashing on same server 11/43511/2
authorTrevor Bramwell <tbramwell@linuxfoundation.org>
Thu, 28 Sep 2017 18:54:23 +0000 (11:54 -0700)
committerTrevor Bramwell <tbramwell@linuxfoundation.org>
Fri, 29 Sep 2017 18:05:16 +0000 (11:05 -0700)
There is a possiblity of multiple docker builds of a docker repo being
scheduled on the same host:

1) Patch is merged
2) Docker build is triggered
3) New patch is merged before the Docker build/push finishes triggering
   a second build
4) First build fails as second build starts by cleaning image from
   first build

Reintroducing the check for builds in progress, but specific to the
Docker repo, should allow mulitiple Docker builds on a node to run,
while keeping multiple builds on a per-repo basis from thrashing each
other.

JIRA: RELENG-315

Change-Id: I74c01850a036c831b93a8cd5fa8522337abb9ff4
Signed-off-by: Trevor Bramwell <tbramwell@linuxfoundation.org>
jjb/releng/opnfv-docker.sh

index 954d7c8..298d2af 100644 (file)
@@ -17,6 +17,17 @@ echo "Starting opnfv-docker for $DOCKER_REPO_NAME ..."
 echo "--------------------------------------------------------"
 echo
 
+count=30 # docker build jobs might take up to ~30 min
+while [[ -n `ps -ef| grep 'docker build' | grep $DOCKER_REPO_NAME | grep -v grep` ]]; do
+    echo "Build or cleanup of $DOCKER_REPO_NAME in progress. Waiting..."
+    sleep 60
+    count=$(( $count - 1 ))
+    if [ $count -eq 0 ]; then
+        echo "Timeout. Aborting..."
+        exit 1
+    fi
+done
+
 # Remove previous running containers if exist
 if [[ -n "$(docker ps -a | grep $DOCKER_REPO_NAME)" ]]; then
     echo "Removing existing $DOCKER_REPO_NAME containers..."