qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: famz@redhat.com, cota@braap.org, berrange@redhat.com,
	f4bug@amsat.org, richard.henderson@linaro.org, balrogg@gmail.com,
	aurelien@aurel32.net, agraf@suse.de
Cc: qemu-devel@nongnu.org, "Alex Bennée" <alex.bennee@linaro.org>
Subject: [Qemu-devel] [PATCH v1 7/8] docker: docker.py add check sub-command
Date: Mon, 18 Jun 2018 14:07:08 +0100	[thread overview]
Message-ID: <20180618130709.19730-8-alex.bennee@linaro.org> (raw)
In-Reply-To: <20180618130709.19730-1-alex.bennee@linaro.org>

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>

---
  - fix prints to be "modern"
  - PEP8 fixes
  - split inspect into function
---
 tests/docker/docker.py | 38 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)

diff --git a/tests/docker/docker.py b/tests/docker/docker.py
index 325915a6f9..c157ff826a 100755
--- a/tests/docker/docker.py
+++ b/tests/docker/docker.py
@@ -179,8 +179,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", "")
 
@@ -442,6 +448,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]))
-- 
2.17.1

  parent reply	other threads:[~2018-06-18 13:07 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-18 13:07 [Qemu-devel] [PATCH v1 0/8] Docker tweaks for TCG testing Alex Bennée
2018-06-18 13:07 ` [Qemu-devel] [PATCH v1 1/8] docker: Add "cc" subcommand Alex Bennée
2018-06-18 13:07 ` [Qemu-devel] [PATCH v1 2/8] docker: extend "cc" command to accept compiler Alex Bennée
2018-06-18 13:07 ` [Qemu-devel] [PATCH v1 3/8] docker: allow "cc" command to run in user context Alex Bennée
2018-06-18 13:07 ` [Qemu-devel] [PATCH v1 4/8] docker: Makefile.include introduce DOCKER_SCRIPT Alex Bennée
2018-06-18 13:07 ` [Qemu-devel] [PATCH v1 5/8] docker: docker.py use "ps" to probe usage Alex Bennée
2018-06-18 15:00   ` Philippe Mathieu-Daudé
2018-06-18 13:07 ` [Qemu-devel] [PATCH v1 6/8] docker: docker.py don't conflate checksums for extra_files Alex Bennée
2018-06-18 16:01   ` Philippe Mathieu-Daudé
2018-06-18 13:07 ` Alex Bennée [this message]
2018-06-18 13:07 ` [Qemu-devel] [PATCH v1 8/8] docker: docker.py adding age check command Alex Bennée
2018-06-18 16:06   ` Philippe Mathieu-Daudé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180618130709.19730-8-alex.bennee@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=agraf@suse.de \
    --cc=aurelien@aurel32.net \
    --cc=balrogg@gmail.com \
    --cc=berrange@redhat.com \
    --cc=cota@braap.org \
    --cc=f4bug@amsat.org \
    --cc=famz@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).