Your message dated Sat, 14 Apr 2018 21:37:31 +0000
with message-id <e1f7srt-0002nj...@fasolo.debian.org>
and subject line Bug#893731: fixed in piuparts 0.85
has caused the Debian Bug report #893731,
regarding [piuparts] Please add docker support
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact ow...@bugs.debian.org
immediately.)


-- 
893731: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=893731
Debian Bug Tracking System
Contact ow...@bugs.debian.org with problems
--- Begin Message ---
Package: piuparts
Version: 0.84
Severity: normal
Tags: patch

I have written a patch for adding docker support on piuparts. A new option is
introduced `--docker-image` e.g.

$ piuparts --docker-image debian:unstable package.deb

Honestly I didn't do too much testing on this, I just have tried using the new
feature of course and I have tried using schroot to check it's not breaking
something. I am willing to help you if you need/want to do extra testing on 
this.
The patch attached is made against origin/master.

Cheers,

-- 
TiN
diff --git a/piuparts.py b/piuparts.py
index 3daba797..a13bd9fc 100644
--- a/piuparts.py
+++ b/piuparts.py
@@ -47,6 +47,7 @@ import os
 import tarfile
 import stat
 import re
+import json
 import pickle
 import subprocess
 import traceback
@@ -191,6 +192,7 @@ class Settings:
         self.skip_minimize = True
         self.minimize = False
         self.debfoster_options = None
+        self.docker_image = None
         # tests and checks
         self.no_install_purge_test = False
         self.no_upgrade_test = False
@@ -769,7 +771,7 @@ class Chroot:
     def create(self, temp_tgz=None):
         """Create a chroot according to user's wishes."""
         self.panic_handler_id = do_on_panic(self.remove)
-        if not settings.schroot:
+        if not settings.schroot and not settings.docker_image:
             self.create_temp_dir()
 
         if temp_tgz:
@@ -782,10 +784,12 @@ class Chroot:
             self.setup_from_dir(settings.existing_chroot)
         elif settings.schroot:
             self.setup_from_schroot(settings.schroot)
+        elif settings.docker_image:
+            self.setup_from_docker(settings.docker_image)
         else:
             self.setup_minimal_chroot()
 
-        if not settings.schroot:
+        if not settings.schroot and not settings.docker_image:
             self.mount_proc()
         self.configure_chroot()
 
@@ -807,7 +811,7 @@ class Chroot:
         self.run_scripts("post_chroot_unpack")
 
         self.run(["apt-get", "update"])
-        if settings.basetgz or settings.schroot or settings.existing_chroot:
+        if settings.basetgz or settings.docker_image or settings.schroot or settings.existing_chroot:
             self.run(["apt-get", "-yf", "dist-upgrade"])
         self.minimize()
         self.remember_available_md5()
@@ -832,7 +836,10 @@ class Chroot:
             if settings.schroot:
                 logging.debug("Terminate schroot session '%s'" % self.name)
                 run(['schroot', '--end-session', '--chroot', "session:" + self.schroot_session])
-            if not settings.schroot:
+            if settings.docker_image:
+                logging.debug("Destroy docker container '%s'" % self.docker_container)
+                run(['docker', 'rm', '-f', self.docker_container])
+            if not settings.schroot and not settings.docker_image:
                 run(['rm', '-rf', '--one-file-system', self.name])
                 if os.path.exists(self.name):
                     create_file(os.path.join(self.name, ".piuparts.tmpdir"), "removal failed")
@@ -840,6 +847,8 @@ class Chroot:
         elif settings.keep_tmpdir:
             if settings.schroot:
                 logging.debug("Keeping schroot session %s at %s" % (self.schroot_session, self.name))
+            elif settings.docker_image:
+                logging.debug("Keeping container %s" % self.docker_container)
             else:
                 logging.debug("Keeping directory tree at %s" % self.name)
         dont_do_on_panic(self.panic_handler_id)
@@ -892,6 +901,25 @@ class Chroot:
         self.name = output.strip()
         logging.info("New schroot session in '%s'" % self.name)
 
+    @staticmethod
+    def check_if_docker_storage_driver_is_supported():
+        ret_code, output = run(['docker', 'info'])
+        if 'overlay2' not in output:
+            logging.error('Only overlay2 storage driver is supported')
+            panic()
+
+    def setup_from_docker(self, docker_image):
+        self.check_if_docker_storage_driver_is_supported()
+        ret_code, output = run(['docker', 'run', '-d', '-it', docker_image, 'bash'])
+        if ret_code != 0:
+            logging.error("Couldn't start the container from '%s'" % docker_image)
+            panic()
+        self.docker_container = output.strip()
+        ret_code, output = run(['docker', 'inspect', self.docker_container])
+        container_data = json.loads(output)[0]
+        self.name = container_data['GraphDriver']['Data']['MergedDir']
+        logging.info("New container created '%s'" % self.docker_container)
+
     def setup_from_lvm(self, lvm_volume):
         """Create a chroot by creating an LVM snapshot."""
         self.lvm_base = os.path.dirname(lvm_volume)
@@ -938,6 +966,12 @@ class Chroot:
                 ["schroot", "--preserve-environment", "--run-session", "--chroot", "session:" +
                     self.schroot_session, "--directory", "/", "-u", "root", "--"] + prefix + command,
                    ignore_errors=ignore_errors, timeout=settings.max_command_runtime)
+        elif settings.docker_image:
+            return run(
+                ['docker', 'exec', self.docker_container,] + prefix + command,
+                ignore_errors=ignore_errors,
+                timeout=settings.max_command_runtime
+            )
         else:
             return run(["chroot", self.name] + prefix + command,
                        ignore_errors=ignore_errors, timeout=settings.max_command_runtime)
@@ -1042,6 +1076,9 @@ class Chroot:
 
     def create_resolv_conf(self):
         """Update resolv.conf based on the current configuration in the host system. Strip comments and whitespace."""
+        if settings.docker_image:
+            # Do nothing, docker already takes care of this
+            return
         full_name = self.relative("etc/resolv.conf")
         resolvconf = ""
         with open("/etc/resolv.conf", "r") as f:
@@ -1624,8 +1661,12 @@ class Chroot:
 
     def check_for_no_processes(self, fail=None):
         """Check there are no processes running inside the chroot."""
-        (status, output) = run(["lsof", "-w", "+D", self.name], ignore_errors=True)
-        count = len(output.split("\n")) - 1
+        if settings.docker_image:
+            (status, output) = run(["docker", "top", self.docker_container])
+            count = len(output.strip().split("\n")) - 2 # header + bash launched on container creation
+        else:
+            (status, output) = run(["lsof", "-w", "+D", self.name], ignore_errors=True)
+            count = len(output.split("\n")) - 1
         if count > 0:
             if fail is None:
                 fail = not settings.allow_database
@@ -1637,6 +1678,9 @@ class Chroot:
 
     def terminate_running_processes(self):
         """Terminate all processes running in the chroot."""
+        if settings.docker_image:
+            # docker takes care of this
+            return
         seen = []
         while True:
             p = subprocess.Popen(["lsof", "-t", "+D", self.name],
@@ -2726,6 +2770,10 @@ def parse_command_line():
                       help="Use schroot session named SCHROOT-NAME for the chroot, instead of building " +
                            "a new one with debootstrap.")
 
+    parser.add_option("--docker-image", metavar="DOCKER-IMAGE", action="store",
+                      help="Use docker image DOCKER-IMAGE for the chroot, instead of building " +
+                           "a new one with debootstrap.")
+
     parser.add_option("-m", "--mirror", action="append", metavar="URL",
                       default=[],
                       help="Which Debian mirror to use.")
@@ -2948,6 +2996,7 @@ def parse_command_line():
     if settings.minimize:
         settings.skip_minimize = False
     settings.debfoster_options = opts.debfoster_options.split()
+    settings.docker_image = opts.docker_image
     # tests and checks
     settings.no_install_purge_test = opts.no_install_purge_test
     settings.no_upgrade_test = opts.no_upgrade_test

Attachment: signature.asc
Description: OpenPGP digital signature


--- End Message ---
--- Begin Message ---
Source: piuparts
Source-Version: 0.85

We believe that the bug you reported is fixed in the latest version of
piuparts, which is due to be installed in the Debian FTP archive.

A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to 893...@bugs.debian.org,
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Holger Levsen <hol...@debian.org> (supplier of updated piuparts package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing ftpmas...@ftp-master.debian.org)


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Format: 1.8
Date: Sat, 14 Apr 2018 17:39:13 -0300
Source: piuparts
Binary: piuparts piuparts-master piuparts-slave piuparts-common
Architecture: source
Version: 0.85
Distribution: unstable
Urgency: medium
Maintainer: piuparts developers team <piuparts-de...@lists.alioth.debian.org>
Changed-By: Holger Levsen <hol...@debian.org>
Description:
 piuparts   - .deb package installation, upgrading, and removal testing tool
 piuparts-common - common piuparts components
 piuparts-master - piuparts master components
 piuparts-slave - piuparts slave components
Closes: 893731 894232
Changes:
 piuparts (0.85) unstable; urgency=medium
 .
   [ Agustin Henze ]
   * piuparts.py:
     - Add docker support, new param is introduced `--docker-image`.
       (Closes: #893731)
     - Deprecate --keep-tmpdir in favor of --keep-env (Closes: #894232)
     - Create ${ENV}/dev/ptmx path if it doesn't exist
     - Create ${ENV}/dev/null if it doesn't exist ASAP
   * Add `docker.io` as suggested package.
   * Reworded documentation for `--keep-env` and `--schroot` parameters.
 .
   [ Holger Levsen ]
   * dwke.py: change logging to make relevant information more visible.
   * detect_*_issues.in: improve output.
   * report_untestable_packages.in: improve output.
   * piuparts.1.txt: improve wording for docker related changes and add
     explaination about the limitations of docker support.
   * Bump standards version to 4.1.4, no changes needed.
Checksums-Sha1:
 40be74652c7a34a22a7e5e927804a6037ab85ec0 2016 piuparts_0.85.dsc
 498590930890078d64854eb0e312417ed7b91006 262954 piuparts_0.85.tar.gz
 c978757e6411d9fde8a7eab341c253774a812ae3 8267 piuparts_0.85_source.buildinfo
Checksums-Sha256:
 17b1f4174a22c0b293d8d28984dd5a2429df5842f0a2da12be2f5d738636f6c7 2016 
piuparts_0.85.dsc
 862e2af7782da1beda3fcab145d81a06c7ef6308ed9c7d616ed9c521bd77f73d 262954 
piuparts_0.85.tar.gz
 35ae85d3b1049967be92c925950a6c8597fb60cb45742f31118818b6f3c92ffa 8267 
piuparts_0.85_source.buildinfo
Files:
 0e1cc78626e7fea51cc70702dff8ba47 2016 devel optional piuparts_0.85.dsc
 557d15a56a1c8c4b512c38a0b5766af4 262954 devel optional piuparts_0.85.tar.gz
 d79475a31015ac13c22353974f3ed692 8267 devel optional 
piuparts_0.85_source.buildinfo

-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEuL9UE3sJ01zwJv6dCRq4VgaaqhwFAlrSbKIACgkQCRq4Vgaa
qhxc3xAAlAdjHTSsK3TPFM61cYXJpfMMm2FuunhnpwiB/aSYAvE+KVjx1c9ceI/X
rHbGLnby73lMSPpc2uiA14i+riLnTJ4649Qwh2Md2Nv3AjJbl4XzSJfkeJJfXDMo
xScpRA4SYF3VCLSP1Rhwz3AVGLjUXRDt2IFRXmEBJu3bd4Q3We3Y4/1cmEZdT1Sf
NYAvYCRT99Z5dgClIW6t9479WcOR7dA7c4yP+tYBSe5KRkVN80WMWTwHgU/00Avc
Se/ktkAhG6LLjpbTX27YSqe+H6HJExE36mFnwlyOIaRv3NaXo77t5WFM9PVyBFa1
3GwysDUI8BCdpycbBBYGCDsY9EMQoge4AJDipSLYOcrbuI/7pTv0l3/8/lWs4HPF
Yq2OO8dwML8vaXfaRE9JiM0aCu2Fo2J79+YiCq99exF94m03HY4X5RUi6rPp0gyU
vvFQ49bOTBTmZNOb90mXMBd/56mdLdlxiSxtYCb0FsZAlK6mTFD5ow9q+kcNkpwR
iGtXEjXAMKmNKgAUC+rp4gOdieHjD5tWaWuelNmHixi6EppLYLTwVW+UTJx4rmA9
MOpPSNtBXEpptaHcDCoSXy6zYJqZxsorPmZ/N+39ojVtp/r/X1CDXcMORvxv5yXD
9XVGur4yyUYOzJeT7r/MgXEeTteCs0+t5LjnP26dEQbbPWzpKjc=
=pdPp
-----END PGP SIGNATURE-----

--- End Message ---

Reply via email to