[Piuparts-devel] [Git][debian/piuparts][develop] 3 commits: fix(docker): getting Container ID
Nicolas Dandrimont (@olasd)
gitlab at salsa.debian.org
Sat Jan 13 12:03:51 GMT 2024
Nicolas Dandrimont pushed to branch develop at Debian / piuparts
Commits:
3ba4c38d by Philipp Hahn at 2024-01-13T12:25:18+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.
Co-Authored-By: Nicolas Dandrimont <olasd at debian.org> (use temporary directory)
- - - - -
76a5f861 by Philipp Hahn at 2024-01-13T12:27:12+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.
- - - - -
6980c395 by Philipp Hahn at 2024-01-13T12:27:15+01:00
refactor(docker): improve log output
Include path in debug output.
Let logging.debug() handle the variable substitution.
- - - - -
1 changed file:
- piuparts.py
Changes:
=====================================
piuparts.py
=====================================
@@ -36,7 +36,6 @@ VERSION = "__PIUPARTS_VERSION__"
import errno
-import json
import logging
import optparse
import os
@@ -935,15 +934,18 @@ 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.TemporaryDirectory() as tmpdir:
+ cidfile = pathlib.Path(tmpdir) / "cidfile"
+ ret_code, output = run(["docker", "run", "-d", "-it", "--cidfile", str(cidfile), docker_image, "bash"])
+ if ret_code != 0:
+ logging.error("Couldn't start the container from '%s'" % docker_image)
+ panic()
+
+ self.docker_container = cidfile.read_text().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/57611cd624e776cad228b47412766dc9ba18c5d9...6980c39586865a01267ec49758efd4ddb85514d9
--
View it on GitLab: https://salsa.debian.org/debian/piuparts/-/compare/57611cd624e776cad228b47412766dc9ba18c5d9...6980c39586865a01267ec49758efd4ddb85514d9
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/20240113/edff9f29/attachment-0001.htm>
More information about the Piuparts-devel
mailing list