Add docker_runner, new versioned tags, fix images order and actually apply tags

This commit is contained in:
Ayaz Salikhov
2021-03-22 00:42:00 +03:00
parent 4376da031e
commit aa2b3645e2
3 changed files with 84 additions and 25 deletions

29
tagging/docker_runner.py Normal file
View File

@@ -0,0 +1,29 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import docker
import logging
logger = logging.getLogger(__name__)
class DockerRunner:
def __init__(self, image_name, docker_client=docker.from_env(), command="sleep infinity"):
self.container = None
self.image_name = image_name
self.command = command
self.docker_client = docker_client
def __enter__(self):
logger.info(f"Creating container for image {self.image_name} ...")
self.container = self.docker_client.containers.run(
image=self.image_name, command=self.command, detach=True,
)
logger.info(f"Container {self.container.name} created")
return self.container
def __exit__(self, exc_type, exc_value, traceback):
logger.info(f"Removing container {self.container.name} ...")
if self.container:
self.container.remove(force=True)
logger.info(f"Container {self.container.name} removed")