-
Notifications
You must be signed in to change notification settings - Fork 9
fix: use user-template to generate dockerfile #40
Changes from 5 commits
2d27e42
dba589c
3c539b5
ddf0df1
2ea1f50
46ed788
537ec8a
3101d03
02412bd
6e7adca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{% extends bento__dockerfile %} | ||
{% set bento__home = "/tmp" %} | ||
{% block SETUP_BENTO_ENTRYPOINT %} | ||
EXPOSE 3000 | ||
|
||
RUN --mount=type=cache,mode=0777,target=/root/.cache/pip \ | ||
pip install awslambdaric==2.0.0 mangum==0.12.3 | ||
|
||
USER root | ||
|
||
ENTRYPOINT [ "/usr/local/bin/python", "-m", "awslambdaric" ] | ||
{% endblock %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,29 @@ | ||
import os | ||
import shutil | ||
|
||
from bentoctl.docker_utils import DOCKERFILE_PATH | ||
from bentoml._internal.bento.build_config import DockerOptions | ||
from bentoml._internal.bento.gen import generate_dockerfile | ||
|
||
path_to_aws_lambda_files = os.path.join(os.path.dirname(__file__), "./aws_lambda/") | ||
DOCKERFILE_TEMPLATE = os.path.join(path_to_aws_lambda_files, "Dockerfile.template") | ||
BENTOML_USER_TEMPLATE = os.path.join( | ||
path_to_aws_lambda_files, "bentoctl_user_template.j2" | ||
) | ||
APP_FILE = os.path.join(path_to_aws_lambda_files, "app.py") | ||
|
||
|
||
def generate_lambda_deployable(bento_path, bento_metadata, deployable_path): | ||
def generate_lambda_deployable(bento_path, _, deployable_path): | ||
# copy bento_bundle to project_path | ||
shutil.copytree(bento_path, deployable_path) | ||
|
||
# Make docker file with dockerfile template | ||
dockerfile = os.path.join(deployable_path, "Dockerfile") | ||
with open(DOCKERFILE_TEMPLATE, "r", encoding="utf-8") as f, open( | ||
dockerfile, "w" | ||
) as dockerfile: | ||
dockerfile_template = f.read() | ||
dockerfile.write( | ||
dockerfile_template.format( | ||
bentoml_version=bento_metadata["bentoml_version"], | ||
python_version=bento_metadata["python_version"], | ||
) | ||
) | ||
# Make docker file with user template | ||
docker_options_for_lambda = DockerOptions(dockerfile_template=BENTOML_USER_TEMPLATE) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. amazonlinux is not a requirement actually but we should pin the python version. we can use the same one from the bento |
||
dockerfile_generated = generate_dockerfile( | ||
docker_options_for_lambda.with_defaults(), use_conda=False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't this going to use the python version on the bentoctl build machine instead of the bento's python version? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep that is a bug. Thanks for pointing it out! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will take over from here |
||
) | ||
dockerfile = os.path.join(deployable_path, DOCKERFILE_PATH) | ||
with open(dockerfile, "w") as dockerfile: | ||
dockerfile.write(dockerfile_generated) | ||
|
||
# copy over app.py file | ||
shutil.copy( | ||
|
@@ -48,33 +50,25 @@ def create_deployable( | |
|
||
Returns | ||
------- | ||
dockerfile_path : str | ||
path to the dockerfile. | ||
docker_context_path : str | ||
path to the docker context. | ||
additional_build_args : dict | ||
Any addition build arguments that need to be passed to the | ||
docker build command | ||
""" | ||
|
||
deployable_path = os.path.join(destination_dir, "bentoctl_deployable") | ||
docker_context_path = deployable_path | ||
dockerfile_path = os.path.join(deployable_path, "Dockerfile") | ||
|
||
if os.path.exists(deployable_path): | ||
if overwrite_deployable: | ||
print(f"Overwriting existing deployable [{deployable_path}]") | ||
shutil.rmtree(deployable_path) | ||
else: | ||
print("Using existing deployable") | ||
return dockerfile_path, docker_context_path, additional_build_args | ||
return docker_context_path | ||
|
||
generate_lambda_deployable( | ||
bento_path=bento_path, | ||
bento_metadata=bento_metadata, | ||
deployable_path=deployable_path, | ||
) | ||
|
||
additional_build_args = None | ||
|
||
return dockerfile_path, docker_context_path, additional_build_args | ||
return docker_context_path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how would we start a bento again? since you are overwritting ENTRYPOINT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the CMD command is configured my the terraform template but I'll put it back here since that is less confusing