Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debugged copy download-miniconda.sh and added support for multi-platform build #780

Merged
merged 2 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading