瀏覽代碼

[ci skip] try to free up disk space between continuous runs (#3714)

We rely on docker's built-in caching to save on build times.  We never
clear out this cache, so assuming people keep making changes to the
test implementations, we'll eventually run out of disk space.  This
happened most recently in the Citrine environment after 6 or so runs.

With this change, we'll try to clear out docker's cache when we notice
that the available disk space is uncomfortably low.  Currently the script
assumes that 20G is enough space to handle a full run.
Michael Hixson 7 年之前
父節點
當前提交
b98c259e8c
共有 1 個文件被更改,包括 14 次插入12 次删除
  1. 14 12
      toolset/continuous/tfb-shutdown.sh

+ 14 - 12
toolset/continuous/tfb-shutdown.sh

@@ -2,16 +2,18 @@
 
 set -e
 
-sudo service docker restart
-docker ps -aq | xargs --no-run-if-empty docker stop
-docker ps -aq | xargs --no-run-if-empty docker rm -f
-ssh techempower@$TFB_DATABASE_HOST << \EOF
+docker_clean() {
   sudo service docker restart
-  docker ps -aq | xargs --no-run-if-empty docker stop
-  docker ps -aq | xargs --no-run-if-empty docker rm -f
-EOF
-ssh techempower@$TFB_CLIENT_HOST << \EOF
-  sudo service docker restart
-  docker ps -aq | xargs --no-run-if-empty docker stop
-  docker ps -aq | xargs --no-run-if-empty docker rm -f
-EOF
+  docker ps --all --quiet | xargs --no-run-if-empty docker stop
+  docker ps --all --quiet | xargs --no-run-if-empty docker rm --force
+
+  # https://stackoverflow.com/a/38183298/359008
+  FREE=`df -k --output=avail /var/lib/docker | tail -n1`   # df -k not df -h
+  if [[ $FREE -lt 20971520 ]]; then                        # 20G = 20*1024*1024k
+    docker system prune --all --force
+  fi
+}
+
+docker_clean
+ssh techempower@$TFB_DATABASE_HOST "$(typeset -f docker_clean); docker_clean"
+ssh techempower@$TFB_CLIENT_HOST "$(typeset -f docker_clean); docker_clean"