aboutsummaryrefslogtreecommitdiff
path: root/tests/docker
diff options
context:
space:
mode:
authorAlex Bennée <alex.bennee@linaro.org>2018-06-12 21:28:45 +0100
committerAlex Bennée <alex.bennee@linaro.org>2018-06-20 22:13:39 +0100
commit7b882245f48dca6e1cf9087b24e41275793be88f (patch)
tree121409039586d3b36d40a995330b1a90977814cc /tests/docker
parentcff5477330429cfb154bf00ec8224bdceb8f8bed (diff)
docker: docker.py adding age check command
This is useful for querying if an image is too old. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Diffstat (limited to 'tests/docker')
-rwxr-xr-xtests/docker/docker.py46
1 files changed, 36 insertions, 10 deletions
diff --git a/tests/docker/docker.py b/tests/docker/docker.py
index e4f37820e0..b279836154 100755
--- a/tests/docker/docker.py
+++ b/tests/docker/docker.py
@@ -32,6 +32,7 @@ except ImportError:
from io import StringIO
from shutil import copy, rmtree
from pwd import getpwuid
+from datetime import datetime,timedelta
FILTERED_ENV_NAMES = ['ftp_proxy', 'http_proxy', 'https_proxy']
@@ -190,6 +191,9 @@ class Docker(object):
except subprocess.CalledProcessError:
return None
+ def get_image_creation_time(self, info):
+ return json.loads(info)[0]["Created"]
+
def get_image_dockerfile_checksum(self, tag):
resp = self.inspect_tag(tag)
labels = json.loads(resp)[0]["Config"].get("Labels", {})
@@ -461,11 +465,14 @@ class CheckCommand(SubCommand):
def args(self, parser):
parser.add_argument("tag",
help="Image Tag")
- parser.add_argument("dockerfile",
- help="Dockerfile name")
+ parser.add_argument("dockerfile", default=None,
+ help="Dockerfile name", nargs='?')
+ parser.add_argument("--checktype", choices=["checksum", "age"],
+ default="checksum", help="check type")
+ parser.add_argument("--olderthan", default=60, type=int,
+ help="number of minutes")
def run(self, args, argv):
- dockerfile = open(args.dockerfile, "rb").read()
tag = args.tag
dkr = Docker()
@@ -474,13 +481,32 @@ class CheckCommand(SubCommand):
print("Image does not exist")
return 1
- if dkr.image_matches_dockerfile(tag, dockerfile):
- if not args.quiet:
- print("Image is up to date")
- return 0
- else:
- print("Image needs updating")
- return 1
+ if args.checktype == "checksum":
+ if not args.dockerfile:
+ print("Need a dockerfile for tag:%s" % (tag))
+ return 1
+
+ dockerfile = open(args.dockerfile, "rb").read()
+
+ if dkr.image_matches_dockerfile(tag, dockerfile):
+ if not args.quiet:
+ print("Image is up to date")
+ return 0
+ else:
+ print("Image needs updating")
+ return 1
+ elif args.checktype == "age":
+ timestr = dkr.get_image_creation_time(info).split(".")[0]
+ created = datetime.strptime(timestr, "%Y-%m-%dT%H:%M:%S")
+ past = datetime.now() - timedelta(minutes=args.olderthan)
+ if created < past:
+ print ("Image created @ %s more than %d minutes old" %
+ (timestr, args.olderthan))
+ return 1
+ else:
+ if not args.quiet:
+ print ("Image less than %d minutes old" % (args.olderthan))
+ return 0
def main():