improve singularity local build
@@ -246,22 +246,10 @@ class ContainerClient:
else:
if HAS_DOCKER:
docker_image = self._get_docker_image(container_image)
- if docker_image:
- print('Building singularity image from local docker image')
- # Save docker image as tar and build singularity image
- tmp_file = sif_file.replace('sif', 'tar').replace(':', '_')
- f = open(tmp_file, 'wb')
- try:
- for chunk in docker_image.save(chunk_size=100*1024*1024): # 100 MB
- f.write(chunk)
- singularity_image = Client.build(f'docker-archive://{tmp_file}', sif_file, sudo=False)
- except Exception as e:
- print(f'Failed to build singularity image from local: {e}')
- finally:
- # Clean up
- f.close()
- if os.path.exists(tmp_file):
- os.remove(tmp_file)
+ if docker_image and len(docker_image.tags) > 0:
+ tag = docker_image.tags[0]
+ print(f'Building singularity image from local docker image: {tag}')
+ singularity_image = Client.build(f'docker-daemon://{tag}', sif_file, sudo=False)
if not singularity_image:
print(f"Singularity: pulling image {container_image}")
singularity_image = Client.pull(f'docker://{container_image}')
