diff --git a/biosimulators_utils/_version.py b/biosimulators_utils/_version.py index 112abf13..ac1125f5 100644 --- a/biosimulators_utils/_version.py +++ b/biosimulators_utils/_version.py @@ -1 +1 @@ -__version__ = '0.1.14' +__version__ = '0.1.15' diff --git a/biosimulators_utils/image.py b/biosimulators_utils/image.py index 780935dc..63facced 100644 --- a/biosimulators_utils/image.py +++ b/biosimulators_utils/image.py @@ -35,16 +35,16 @@ def login_to_docker_registry(registry, username, password): return docker_client -def pull_docker_image(url): +def pull_docker_image(docker_client, url): """ Pull Docker image Args: + docker_client (:obj:`docker.client.DockerClient`): Docker client url (:obj:`str`): URL for Docker image Returns: :obj:`docker.models.images.Image`: Docker image """ - docker_client = docker.from_env() try: return docker_client.images.pull(url) except docker.errors.NotFound: @@ -54,15 +54,15 @@ def pull_docker_image(url): url, str(error).replace('\n', '\n '))) -def tag_and_push_docker_image(image, tag): +def tag_and_push_docker_image(docker_client, image, tag): """ Tag and push Docker image Args: + docker_client (:obj:`docker.client.DockerClient`): Docker client image (:obj:`docker.models.images.Image`): Docker image tag (:obj:`str`): tag """ assert image.tag(tag) - docker_client = docker.from_env() response = docker_client.images.push(tag) response = json.loads(response.rstrip().split('\n')[-1]) if 'error' in response: diff --git a/tests/test_image.py b/tests/test_image.py index 81e4f67f..b06300e0 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -19,26 +19,26 @@ def test_pull_docker_image(self): 'docker.io', os.getenv("DOCKER_HUB_USERNAME"), os.getenv("DOCKER_HUB_TOKEN")) - image.pull_docker_image('hello-world') + image.pull_docker_image(docker_client, 'hello-world') with self.assertRaises(docker.errors.NotFound): - image.pull_docker_image('hello-undefined') + image.pull_docker_image(docker_client, 'hello-undefined') with self.assertRaises(Exception): - image.pull_docker_image('---undefined---') + image.pull_docker_image(docker_client, '---undefined---') def test_tag_and_push_docker_image(self): docker_client = image.login_to_docker_registry( 'docker.io', os.getenv("DOCKER_HUB_USERNAME"), os.getenv("DOCKER_HUB_TOKEN")) - img = image.pull_docker_image('hello-world') + img = image.pull_docker_image(docker_client, 'hello-world') response = '{"error": "x"}' docker_client = mock.Mock(images=mock.Mock(push=lambda tag: response)) with mock.patch('docker.from_env', return_value=docker_client): with self.assertRaisesRegex(Exception, 'Unable to push image to'): - image.tag_and_push_docker_image(img, 'hello-world-2') + image.tag_and_push_docker_image(docker_client, img, 'hello-world-2') def test_convert_docker_image_to_singularity(self): filename = image.convert_docker_image_to_singularity('hello-world')