Skip to content

Commit

Permalink
deal with amd64 at fetch time
Browse files Browse the repository at this point in the history
  • Loading branch information
miquelduranfrigola committed Jun 27, 2023
1 parent 43463ce commit 15088c3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ersilia/hub/pull/pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def pull(self):
DOCKERHUB_ORG, self.model_id, DOCKERHUB_LATEST_TAG
)
)
# except:
# except: #TODO add better error
# raise DockerImageArchitectureNotAvailableError(model=self.model_id)
else:
self.logger.info("Image {0} is not available".format(self.image_name))
Expand Down
3 changes: 3 additions & 0 deletions ersilia/serve/autoservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,10 @@ def clean_docker_containers(self):
self.logger.debug("Silencing docker containers if necessary")
dm = DockerManager(config_json=self.config_json)
if dm.is_inside_docker():
self.logger.debug("It is inside docker")
return
if dm.is_installed():
self.logger.debug("It is not inside docker")
dm.stop_containers(self.model_id)

def serve(self):
Expand All @@ -311,6 +313,7 @@ def close(self):
os.remove(tmp_file)
self.clean_temp_dir()
self.clean_docker_containers()
self.service.close()

def api(
self, api_name, input, output=DEFAULT_OUTPUT, batch_size=DEFAULT_BATCH_SIZE
Expand Down
8 changes: 4 additions & 4 deletions ersilia/serve/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def __init__(self, model_id, config_json=None, preferred_port=None):
self.image_name = "{0}/{1}:{2}".format(
DOCKERHUB_ORG, self.model_id, DOCKERHUB_LATEST_TAG
)
self.logger.debug("Staring Docker Daemon service")
self.logger.debug("Starting Docker Daemon service")
self.tmp_folder = tempfile.mkdtemp(prefix="ersilia-")
self.logger.debug(
"Creating temporary folder {0} and mounting as volume in container".format(
Expand Down Expand Up @@ -507,7 +507,9 @@ def _stop_all_containers_of_image(self):
"Stopping and removing container {0}".format(container.name)
)
container.stop()
self.logger.debug("Container stopped")
container.remove()
self.logger.debug("Container removed")

def _get_apis(self):
file_name = os.path.join(
Expand Down Expand Up @@ -575,7 +577,5 @@ def api(self, api_name, input):
return self._api_with_url(api_name=api_name, input=input)

def close(self):
self.logger.debug(
"Stopping and removing container {0}".format(self.container_id)
)
self.logger.debug("Stopping and removing container")
self._stop_all_containers_of_image()
17 changes: 14 additions & 3 deletions ersilia/utils/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,25 @@ def remove(name):
run_command(cmd)

@staticmethod
def cp_from_container(name, img_path, local_path):
def cp_from_container(name, img_path, local_path, org=None, img=None, tag=None):
local_path = os.path.abspath(local_path)
cmd = "docker cp %s:%s %s" % (name, img_path, local_path)
tmp_file = os.path.join(tempfile.mkdtemp(prefix="ersilia-"), "tmp.txt")
cmd = "docker cp %s:%s %s &> %s" % (name, img_path, local_path, tmp_file)
run_command(cmd)
with open(tmp_file, "r") as f:
output = f.read()
if "No such container" in output:
img_name = "{0}/{1}:{2}".format(org, img, tag)
cmd = "docker run --platform linux/amd64 -d --name={0} {1}".format(
name, img_name
)
run_command(cmd)
cmd = "docker cp %s:%s %s" % (name, img_path, local_path)
run_command(cmd)

def cp_from_image(self, img_path, local_path, org, img, tag):
name = self.run(org, img, tag, name=None)
self.cp_from_container(name, img_path, local_path)
self.cp_from_container(name, img_path, local_path, org=org, img=img, tag=tag)
self.remove(name)

@staticmethod
Expand Down

0 comments on commit 15088c3

Please sign in to comment.