[Piuparts-devel] [Git][debian/piuparts][phahn/docker-fixes] 3 commits: fix(docker): getting Container ID

Philipp Hahn (@pmhahn) gitlab at salsa.debian.org
Wed Dec 6 07:03:20 GMT 2023



Philipp Hahn pushed to branch phahn/docker-fixes at Debian / piuparts


Commits:
7435139b by Philipp Hahn at 2023-12-06T08:02:20+01:00
fix(docker): getting Container ID

in case the image does not exists locally docker will pull it from any
remote registry, but will include the progress information in the
output:

> Unable to find image 'docker-registry.XXX/YYY:ZZZ' locally
> ZZZ: Pulling from YYY
...
> Digest: sha256:4b9bfe7b0a6c970e3613c04f267ba6319cfceb8cc120b0435d9ee7b8037a1f06
> Status: Downloaded newer image for docker-registry.XXX/YYY:ZZZ
> 8be38c89d12937b98c8be5ab7466dd45b0e4a306862f282b58077ac7193251eb

The old code expected the output to be the container ID, which fails in that case.

- - - - -
1c1a303c by Philipp Hahn at 2023-12-06T08:02:29+01:00
refactor(docker): Let `docker inspect` return path

Directly use golang templating to only get the MergedDir path instead of
using JSON in Python.

- - - - -
1dba2029 by Philipp Hahn at 2023-12-06T08:02:29+01:00
refactor(docker): improve log output

Include path in debug output.

Let logging.debug() handle the variable substitution.

- - - - -


2 changed files:

- debian/changelog
- piuparts.py


Changes:

=====================================
debian/changelog
=====================================
@@ -1,8 +1,12 @@
 piuparts (1.2.1) UNRELEASED; urgency=medium
 
+  [ Nicolas Dandrimont ]
   * Start 1.2.1 development. Use `gbp dch --since=1.2` to generate a
     changelog for this release.
 
+  [ Philipp Hahn ]
+  * Fix detecting Docker container ID when image is pulled.
+
  -- Nicolas Dandrimont <olasd at debian.org>  Sun, 29 Oct 2023 12:49:51 +0100
 
 piuparts (1.2) unstable; urgency=medium


=====================================
piuparts.py
=====================================
@@ -36,7 +36,6 @@ VERSION = "__PIUPARTS_VERSION__"
 
 
 import errno
-import json
 import logging
 import optparse
 import os
@@ -924,15 +923,17 @@ class Chroot:
 
     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)
+        with tempfile.NamedTemporaryFile("r") as cidfile:
+            ret_code, output = run(['docker', 'run', '-d', '-it', '--cidfile', cidfile.name, docker_image, 'bash'])
+            if ret_code != 0:
+                logging.error("Couldn't start the container from '%s'" % docker_image)
+                panic()
+
+            self.docker_container = cidfile.read().strip()
+
+        ret_code, output = run(['docker', 'inspect', '-f', '{{ .GraphDriver.Data.MergedDir }}', self.docker_container])
+        self.name = output.strip()
+        logging.info("New container created %r at %r", self.docker_container, self.name)
 
     def setup_from_lvm(self, lvm_volume):
         """Create a chroot by creating an LVM snapshot."""



View it on GitLab: https://salsa.debian.org/debian/piuparts/-/compare/9817cf0cb411777f69cb07ef6a9d9fe839cfa341...1dba202921645e8975c91dbd32ee37e668f2baf8

-- 
View it on GitLab: https://salsa.debian.org/debian/piuparts/-/compare/9817cf0cb411777f69cb07ef6a9d9fe839cfa341...1dba202921645e8975c91dbd32ee37e668f2baf8
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/piuparts-devel/attachments/20231206/75477cad/attachment-0001.htm>


More information about the Piuparts-devel mailing list