diff mbox series

[v7,50/54] docker: docker.py add check sub-command

Message ID 20180615194705.28019-51-alex.bennee@linaro.org
State New
Headers show
Series fix building of tests/tcg - last chance to review! | expand

Commit Message

Alex Bennée June 15, 2018, 7:47 p.m. UTC
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
---
 tests/docker/docker.py | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

-- 
2.17.1

Comments

Philippe Mathieu-Daudé June 18, 2018, 3:06 p.m. UTC | #1
On 06/15/2018 04:47 PM, Alex Bennée wrote:
> 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>


Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


> 

> ---

>   - fix prints to be "modern"

>   - PEP8 fixes

> ---

>  tests/docker/docker.py | 25 +++++++++++++++++++++++++

>  1 file changed, 25 insertions(+)

> 

> diff --git a/tests/docker/docker.py b/tests/docker/docker.py

> index 2593a12d04..3666197a16 100755

> --- a/tests/docker/docker.py

> +++ b/tests/docker/docker.py

> @@ -442,6 +442,31 @@ 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()

> +        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]))

>
diff mbox series

Patch

diff --git a/tests/docker/docker.py b/tests/docker/docker.py
index 2593a12d04..3666197a16 100755
--- a/tests/docker/docker.py
+++ b/tests/docker/docker.py
@@ -442,6 +442,31 @@  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()
+        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]))