clean-unit-test-docker: script to clean old images

Since Docker images created by build-unit-test-docker now have
a date-stamp and content hash as part of their tag, a system's
Docker image repository could grow quite large if not cleaned up.
Add a script that easily identifies old Docker images created by
that script and removes them (anything older than the current ISO
week).

Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I316e71ba0b336035e33ebee223f7faf702eaeb2c
diff --git a/scripts/clean-unit-test-docker b/scripts/clean-unit-test-docker
new file mode 100755
index 0000000..696dee6
--- /dev/null
+++ b/scripts/clean-unit-test-docker
@@ -0,0 +1,14 @@
+#!/bin/bash -e
+
+# Removes docker images created by 'build-unit-test-docker' which are older
+# than the current week.
+#   - Images start with 'openbmc/ubuntu-unit-test'.
+#   - Image tags contain YYYY-Www where:
+#       * YYYY is the 4 digit year. (date format %Y)
+#       * W is the literal 'W'
+#       * ww is the two digit ISO week. (date format %V)
+
+docker image ls \
+        "openbmc/ubuntu-unit-test*" \
+        --format "{{.Repository}}:{{.Tag}}" |
+    grep -v "$(date '+%Y-W%V')" | xargs -r docker image rm || true