mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-29 21:33:53 -06:00
tests/docker/docker.py: docker_dir outside build
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> Reviewed-by: Fam Zheng <famz@redhat.com> Message-id: 1468934445-32183-2-git-send-email-famz@redhat.com Signed-off-by: Fam Zheng <famz@redhat.com>
This commit is contained in:
parent
5d3217340a
commit
a9f8d03891
1 changed files with 13 additions and 8 deletions
|
@ -20,7 +20,7 @@ import atexit
|
||||||
import uuid
|
import uuid
|
||||||
import argparse
|
import argparse
|
||||||
import tempfile
|
import tempfile
|
||||||
from shutil import copy
|
from shutil import copy, rmtree
|
||||||
|
|
||||||
def _text_checksum(text):
|
def _text_checksum(text):
|
||||||
"""Calculate a digest string unique to the text content"""
|
"""Calculate a digest string unique to the text content"""
|
||||||
|
@ -87,20 +87,20 @@ class Docker(object):
|
||||||
labels = json.loads(resp)[0]["Config"].get("Labels", {})
|
labels = json.loads(resp)[0]["Config"].get("Labels", {})
|
||||||
return labels.get("com.qemu.dockerfile-checksum", "")
|
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:
|
if argv == None:
|
||||||
argv = []
|
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(dockerfile)
|
||||||
|
|
||||||
tmp_df.write("\n")
|
tmp_df.write("\n")
|
||||||
tmp_df.write("LABEL com.qemu.dockerfile-checksum=%s" %
|
tmp_df.write("LABEL com.qemu.dockerfile-checksum=%s" %
|
||||||
_text_checksum(dockerfile))
|
_text_checksum(dockerfile))
|
||||||
tmp_df.flush()
|
tmp_df.flush()
|
||||||
|
|
||||||
self._do(["build", "-t", tag, "-f", tmp_df.name] + argv + \
|
self._do(["build", "-t", tag, "-f", tmp_df.name] + argv + \
|
||||||
[tmp_dir],
|
[docker_dir],
|
||||||
quiet=quiet)
|
quiet=quiet)
|
||||||
|
|
||||||
def image_matches_dockerfile(self, tag, dockerfile):
|
def image_matches_dockerfile(self, tag, dockerfile):
|
||||||
|
@ -164,10 +164,15 @@ class BuildCommand(SubCommand):
|
||||||
if dkr.image_matches_dockerfile(tag, dockerfile):
|
if dkr.image_matches_dockerfile(tag, dockerfile):
|
||||||
if not args.quiet:
|
if not args.quiet:
|
||||||
print "Image is up to date."
|
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
|
return 0
|
||||||
|
|
||||||
class CleanCommand(SubCommand):
|
class CleanCommand(SubCommand):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue