diff options
author | Alex Bennée <alex.bennee@linaro.org> | 2018-06-08 16:20:48 +0100 |
---|---|---|
committer | Alex Bennée <alex.bennee@linaro.org> | 2018-06-20 22:13:39 +0100 |
commit | f97da1f71700a3417953fa85bf1394307e5dd013 (patch) | |
tree | 35e33d9b13f198cba13606b8f33526ec66a8e48b /tests | |
parent | f9172822e7a07db346e21d461e2a61ffcee7c77e (diff) |
docker: docker.py add check sub-command
This command allows you to check if we need to re-build a docker
image. If the image isn't in the repository or the checksums don't
match then we return false and some text (for processing in
makefiles).
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/docker/docker.py | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/tests/docker/docker.py b/tests/docker/docker.py index 6a9f2f224b..e4f37820e0 100755 --- a/tests/docker/docker.py +++ b/tests/docker/docker.py @@ -184,8 +184,14 @@ class Docker(object): stderr=subprocess.STDOUT, **kwargs) + def inspect_tag(self, tag): + try: + return self._output(["inspect", tag]) + except subprocess.CalledProcessError: + return None + def get_image_dockerfile_checksum(self, tag): - resp = self._output(["inspect", tag]) + resp = self.inspect_tag(tag) labels = json.loads(resp)[0]["Config"].get("Labels", {}) return labels.get("com.qemu.dockerfile-checksum", "") @@ -447,6 +453,36 @@ class CcCommand(SubCommand): return Docker().command("run", cmd, args.quiet) +class CheckCommand(SubCommand): + """Check if we need to re-build a docker image out of a dockerfile. + Arguments: <tag> <dockerfile>""" + name = "check" + + def args(self, parser): + parser.add_argument("tag", + help="Image Tag") + parser.add_argument("dockerfile", + help="Dockerfile name") + + def run(self, args, argv): + dockerfile = open(args.dockerfile, "rb").read() + tag = args.tag + + dkr = Docker() + info = dkr.inspect_tag(tag) + if info is None: + 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 + + def main(): parser = argparse.ArgumentParser(description="A Docker helper", usage="%s <subcommand> ..." % os.path.basename(sys.argv[0])) |