summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordd <dd@wx.tnyzeq.icu>2024-10-07 16:18:30 +0200
committerdd <dd@wx.tnyzeq.icu>2024-10-07 16:30:18 +0200
commitf9b38ae09ff2d7c454172bee036408fb412673f1 (patch)
treeec50410601029c13a6dfeb84d58d296941bd9792
parent01ade8cc2df27625a1e7c3fe122aeb863ca72d20 (diff)
downloadvyos-jenkins-f9b38ae09ff2d7c454172bee036408fb412673f1.tar.gz
vyos-jenkins-f9b38ae09ff2d7c454172bee036408fb412673f1.zip
added circinus docker cleanup
-rw-r--r--new/lib/docker.py19
-rw-r--r--new/lib/helpers.py11
2 files changed, 25 insertions, 5 deletions
diff --git a/new/lib/docker.py b/new/lib/docker.py
index 916bb82..ec1261d 100644
--- a/new/lib/docker.py
+++ b/new/lib/docker.py
@@ -3,7 +3,7 @@ import os
from shlex import quote
import shutil
-from lib.helpers import execute, quote_all, project_dir
+from lib.helpers import execute, quote_all, project_dir, ProcessException
class Docker:
@@ -17,9 +17,24 @@ class Docker:
def pull(self, passthrough=True):
docker_image = self.get_full_image_name()
- execute("docker ")
+ previous_docker_image = "previous-%s" % docker_image
+
+ # We mark current image with custom tag, so we don't lose track when image gets updated because then the
+ # regular tag will shift to the new image from the old image.
+ try:
+ execute("docker tag %s %s" % quote_all(docker_image, previous_docker_image))
+ except ProcessException:
+ pass # Ignore if image doesn't exist.
+
execute("docker pull %s" % quote_all(docker_image), passthrough=passthrough)
+ # Now we can just delete the previous tag, this will delete the image if it's different from the regular tag
+ # or only delete the previous tag if it's the same image (the image wasn't updated).
+ try:
+ execute("docker rmi %s" % quote_all(previous_docker_image))
+ except ProcessException:
+ pass # Ignore if image doesn't exist.
+
def rmtree(self, target):
# This is sanity check, we really don't want to rm -rf something that isn't ours by mistake.
target = os.path.realpath(target)
diff --git a/new/lib/helpers.py b/new/lib/helpers.py
index cc3ee4f..cbb3f3d 100644
--- a/new/lib/helpers.py
+++ b/new/lib/helpers.py
@@ -74,10 +74,12 @@ def execute(command, timeout: int = None, passthrough=False, passthrough_prefix=
if exit_code != 0:
message = "Command '%s' failed, exit code: %s" % (command, exit_code)
+ output = None
if not passthrough:
# noinspection PyUnresolvedReferences
- message += ", output: %s" % process.stdout.read().decode("utf-8")
- raise ProcessException(message)
+ output = process.stdout.read().decode("utf-8")
+ message += ", output: %s" % output
+ raise ProcessException(message, exit_code, output)
if passthrough:
return exit_code
@@ -87,7 +89,10 @@ def execute(command, timeout: int = None, passthrough=False, passthrough_prefix=
class ProcessException(Exception):
- pass
+ def __init__(self, message, exit_code, output):
+ super().__init__(message)
+ self.exit_code = exit_code
+ self.output = output
class TerminalLineBuffer: