Skip to content

Commit

Permalink
debugging, bumping version version
Browse files Browse the repository at this point in the history
  • Loading branch information
jonrkarr committed Dec 22, 2020
1 parent d7a5b51 commit c95f2b8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion biosimulators_utils/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.14'
__version__ = '0.1.15'
8 changes: 4 additions & 4 deletions biosimulators_utils/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit c95f2b8

Please sign in to comment.