qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: famz@redhat.com, riku.voipio@linaro.org,
	"Alex Bennée" <alex.bennee@linaro.org>
Subject: [Qemu-devel] [PATCH v2 1/3] tests/docker/docker.py: docker_dir outside build
Date: Wed,  8 Jun 2016 17:35:50 +0100	[thread overview]
Message-ID: <1465403752-30348-2-git-send-email-alex.bennee@linaro.org> (raw)
In-Reply-To: <1465403752-30348-1-git-send-email-alex.bennee@linaro.org>

Instead of letting the build_image create the temporary working dir we
move the creation to the build command. This is preparation for the
later patches where additional files can be added to the build context
before the build step is run.

We also ensure we remove the build context after we are done (mkdtemp
doesn't do this automatically for you).

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---
v2
  - new for v2
---
 tests/docker/docker.py | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/tests/docker/docker.py b/tests/docker/docker.py
index 0151362..ae40bb3 100755
--- a/tests/docker/docker.py
+++ b/tests/docker/docker.py
@@ -20,7 +20,7 @@ import atexit
 import uuid
 import argparse
 import tempfile
-from shutil import copy
+from shutil import copy, rmtree
 
 def _text_checksum(text):
     """Calculate a digest string unique to the text content"""
@@ -87,20 +87,20 @@ class Docker(object):
         labels = json.loads(resp)[0]["Config"].get("Labels", {})
         return labels.get("com.qemu.dockerfile-checksum", "")
 
-    def build_image(self, tag, dockerfile, df_path, quiet=True, argv=None):
+    def build_image(self, tag, docker_dir, dockerfile, quiet=True, argv=None):
         if argv == None:
             argv = []
-        tmp_dir = tempfile.mkdtemp(prefix="docker_build")
 
-        tmp_df = tempfile.NamedTemporaryFile(dir=tmp_dir, suffix=".docker")
+        tmp_df = tempfile.NamedTemporaryFile(dir=docker_dir, suffix=".docker")
         tmp_df.write(dockerfile)
 
         tmp_df.write("\n")
         tmp_df.write("LABEL com.qemu.dockerfile-checksum=%s" %
                      _text_checksum(dockerfile))
         tmp_df.flush()
+
         self._do(["build", "-t", tag, "-f", tmp_df.name] + argv + \
-                 [tmp_dir],
+                 [docker_dir],
                  quiet=quiet)
 
     def image_matches_dockerfile(self, tag, dockerfile):
@@ -164,10 +164,15 @@ class BuildCommand(SubCommand):
         if dkr.image_matches_dockerfile(tag, dockerfile):
             if not args.quiet:
                 print "Image is up to date."
-            return 0
+        else:
+            # Create a docker context directory for the build
+            docker_dir = tempfile.mkdtemp(prefix="docker_build")
+
+            dkr.build_image(tag, docker_dir, dockerfile,
+                            quiet=args.quiet, argv=argv)
+
+            rmtree(docker_dir)
 
-        dkr.build_image(tag, dockerfile, args.dockerfile,
-                        quiet=args.quiet, argv=argv)
         return 0
 
 class CleanCommand(SubCommand):
-- 
2.7.4

  reply	other threads:[~2016-06-08 16:35 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-08 16:35 [Qemu-devel] [PATCH v2 0/3] Support building qemu-user powered docker test images Alex Bennée
2016-06-08 16:35 ` Alex Bennée [this message]
2016-06-12  6:39   ` [Qemu-devel] [PATCH v2 1/3] tests/docker/docker.py: docker_dir outside build Fam Zheng
2016-06-08 16:35 ` [Qemu-devel] [PATCH v2 2/3] tests/docker/docker.py: support --include-executable Alex Bennée
2016-06-12  6:47   ` Fam Zheng
2016-06-13  9:24     ` Alex Bennée
2016-06-13 12:24   ` Riku Voipio
2016-06-08 16:35 ` [Qemu-devel] [PATCH v2 3/3] add debian-bootstrap.docker target (and pre script) Alex Bennée
2016-06-12  7:05   ` Fam Zheng
2016-06-13  9:23     ` Alex Bennée
2016-06-12  8:16 ` [Qemu-devel] [PATCH v2 0/3] Support building qemu-user powered docker test images Fam Zheng
2016-06-13  9:22   ` Alex Bennée
2016-06-13 11:11     ` Fam Zheng
2016-06-13 11:38     ` Riku Voipio
2016-06-13 12:30       ` Alex Bennée
2016-06-13 12:39         ` Riku Voipio
2016-06-13 14:19           ` Alex Bennée

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=1465403752-30348-2-git-send-email-alex.bennee@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=famz@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=riku.voipio@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).