Skip to content

Commit

Permalink
Merge pull request #780 from emmakodes/master
Browse files Browse the repository at this point in the history
debugged copy download-miniconda.sh and added support for multi-platform build
  • Loading branch information
GemmaTuron committed Aug 17, 2023
2 parents 131c8e5 + 6d0865f commit b4b176f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
35 changes: 28 additions & 7 deletions ersilia/db/environments/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

from ...default import DOCKERHUB_ORG, DOCKERHUB_LATEST_TAG

import subprocess
import sys

BENTOML_DOCKERPORT = 5000
INTERNAL_DOCKERPORT = 80
Expand Down Expand Up @@ -123,7 +125,7 @@ def _build_ersilia_base(self):
path = tempfile.mkdtemp(prefix="ersilia-")
base_folder = os.path.join(path, "base")
os.mkdir(base_folder)
base_files = ["Dockerfile", "docker-entrypoint.sh", "nginx.conf"]
base_files = ["Dockerfile", "docker-entrypoint.sh", "nginx.conf", "download-miniconda.sh"]
for f in base_files:
cmd = "cd {0}; wget {2}/base/{1}".format(
base_folder, f, self._model_deploy_dockerfiles_url
Expand All @@ -134,7 +136,7 @@ def _build_ersilia_base(self):
)
run_command(cmd)

def build_with_ersilia(self, model_id):
def build_with_ersilia(self, model_id, docker_user, docker_pwd):
self.logger.debug("Creating docker image with ersilia incorporated")
if self.image_exists("base"):
pass
Expand All @@ -153,16 +155,35 @@ def build_with_ersilia(self, model_id):
text = text.replace("eos_identifier", model_id)
with open(file_path, "w") as f:
f.write(text)
cmd = "cd {0}; docker build -t {1}/{2}:{3} .".format(
model_folder, DOCKERHUB_ORG, model_id, DOCKERHUB_LATEST_TAG
)
# login to docker so as to be able to push images to dockerhub
cmd = "docker login --password {0} --username {1}".format(
docker_pwd, docker_user
)
run_command(cmd)

def build(self, model_id, use_cache=True):
try:
# Attempt to build for linux/amd64 and linux/arm64
print('building for both linux/amd64,linux/arm64')
cmd = "cd {0}; docker buildx build --builder=container --platform linux/amd64,linux/arm64 -t {1}/{2}:{3} --push .".format(
model_folder, DOCKERHUB_ORG, model_id, DOCKERHUB_LATEST_TAG
)
run_command(cmd)
print('done building for linux/amd64,linux/arm64')
sys.exit() # This will terminate the program immediately only if build for linux/amd64,linux/arm64 complete successfully

except:
# Build failed for multi-platforms, now try building only for linux/amd64
self.logger.warning("Build failed for multi-platform, trying linux/amd64 only")
cmd = "cd {0}; docker build -t {1}/{2}:{3} .".format(
model_folder, DOCKERHUB_ORG, model_id, DOCKERHUB_LATEST_TAG
)
run_command(cmd)

def build(self, model_id, docker_user, docker_pwd, use_cache=True):
if self.with_bentoml:
self.build_with_bentoml(model_id=model_id, use_cache=use_cache)
else:
self.build_with_ersilia(model_id=model_id)
self.build_with_ersilia(model_id=model_id, docker_user=docker_user, docker_pwd=docker_pwd)

def remove(self, model_id):
self.docker.delete(org=DOCKERHUB_ORG, img=model_id, tag=DOCKERHUB_LATEST_TAG)
Expand Down
2 changes: 1 addition & 1 deletion ersilia/publish/dockerhub.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def set_credentials(self, docker_user, docker_pwd):

def build_image(self):
dm = DockerManager()
dm.build(self.model_id)
dm.build(self.model_id, self.docker_user, self.docker_pwd)

def upload(self):
self.build_image()
Expand Down

0 comments on commit b4b176f

Please sign in to comment.