[Piuparts-devel] [Git][debian/piuparts][phahn/docker-fixes] 2 commits: fix(docker) getting Container ID
Philipp Hahn (@pmhahn)
gitlab at salsa.debian.org
Tue Sep 19 08:34:58 BST 2023
Philipp Hahn pushed to branch phahn/docker-fixes at Debian / piuparts
Commits:
27d7d1e5 by Philipp Hahn at 2023-09-19T09:31:38+02: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.
- - - - -
940cf1ae by Philipp Hahn at 2023-09-19T09:31:38+02:00
refactor(docker) Let `docker inspect` return path
Directly use golang templating to only get the MergedDir path instead of
using JSON in Python.
Include path in debug output.
Let logging.debug() handle the variable substitution.
- - - - -
1 changed file:
- piuparts.py
Changes:
=====================================
piuparts.py
=====================================
@@ -35,7 +35,6 @@ from __future__ import print_function
VERSION = "__PIUPARTS_VERSION__"
-import json
import logging
import optparse
import os
@@ -923,15 +922,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/482c6e486529522f49f4822a40c23ead589842d6...940cf1ae8e7cf419a25a87087e50e317ed1f6589
--
View it on GitLab: https://salsa.debian.org/debian/piuparts/-/compare/482c6e486529522f49f4822a40c23ead589842d6...940cf1ae8e7cf419a25a87087e50e317ed1f6589
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/20230919/2329718a/attachment-0001.htm>
More information about the Piuparts-devel
mailing list