Skip to content

address comments for containerize command#884

Merged
parano merged 7 commits intobentoml:masterfrom
jackyzha0:update-containerize
Jul 14, 2020
Merged

address comments for containerize command#884
parano merged 7 commits intobentoml:masterfrom
jackyzha0:update-containerize

Conversation

@jackyzha0
Copy link
Contributor

  • rename _echo -> echo
  • refactor to use load_bento_service_metadata to support file paths
  • callback tag validation to cleanup containerize
  • parameterized testing

@pep8speaks
Copy link

pep8speaks commented Jul 11, 2020

Hello @jackyzha0, Thanks for updating this PR.

There are currently no PEP 8 issues detected in this PR. Cheers! 🍻

Comment last updated at 2020-07-14 05:23:15 UTC

@codecov
Copy link

codecov bot commented Jul 11, 2020

Codecov Report

Merging #884 into master will decrease coverage by 0.12%.
The diff coverage is 57.14%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #884      +/-   ##
==========================================
- Coverage   61.82%   61.69%   -0.13%     
==========================================
  Files         120      120              
  Lines        7918     7780     -138     
==========================================
- Hits         4895     4800      -95     
+ Misses       3023     2980      -43     
Impacted Files Coverage Δ
bentoml/cli/bento_service.py 63.40% <55.55%> (+2.34%) ⬆️
bentoml/cli/utils.py 47.45% <100.00%> (ø)
bentoml/saved_bundle/py_module_utils.py 76.47% <0.00%> (-9.81%) ⬇️
bentoml/yatai/deployment/operator.py 48.00% <0.00%> (-7.18%) ⬇️
bentoml/cli/config.py 31.50% <0.00%> (-5.21%) ⬇️
bentoml/exceptions.py 75.60% <0.00%> (-3.99%) ⬇️
bentoml/cli/deployment.py 45.88% <0.00%> (-3.57%) ⬇️
bentoml/cli/aws_lambda.py 48.93% <0.00%> (-3.07%) ⬇️
bentoml/cli/aws_sagemaker.py 51.96% <0.00%> (-2.67%) ⬇️
bentoml/adapters/dataframe_output.py 24.56% <0.00%> (-2.56%) ⬇️
... and 49 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1ee7be5...74ac658. Read the comment docs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably not do this either, "latest" is the default for docker, it is also a bad decision on docker side. And I think the behavior we want, is to use the BentoService version as the default if the user did not specify a version right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's separate this to two separate functions? to_valid_docker_image_name and to_valid_docker_image_tag? Since the logic itself has nothing to do with BentoML

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bento here can be a local file path, you will need to update this message

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behavior might be confusing to the end-user, I'd prefer to avoid implicitly converting the command argument they provide. For example, I write the following bash script to automate my deployment process:

saved_path="/Users/chaoyu/bentoml/repository/IrisClassifier/20200701222443_EC5EAB"
image_name="my-image-something-that-is-very-long..........."
bentoml containerize $saved_path -t $image_name
docker run $image_name

I will get an Unable to find image error due to the fact that the image name was modified implicitly.

I'm inclined to go with a simpler approach and only do the conversion if the value is automatically set from the BentoService metadata:

...
bs_metadata = load_bento_service_metadata(bento_service_bundle_path)

_echo(f"Building docker image for BentoService {bs_metadata.name}:{bs_metadata.version}")

if not tag:
   tag = "{to_valid_docker_image_name(bs_metadata.name)}:{to_valid_docker_image_tag(bs_metadata.version)}"

if ":" not in tag:  # user have specified image name but not image tag in -t
   version= to_valid_docker_image_tag(bs_metadata.version)
   tag = f"{tag}:{version}"

_echo("Building docker image with tag: {tag}")

docker_api = docker.APIClient()
...

else:
name, version = tag, ""
if to_valid_docker_image_name(name) != name:
raise click.BadParameter(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use a regex to actually validate the input? This can break if the user provides an upper case character or a non-ASCII character. see https://docs.docker.com/engine/reference/commandline/tag/#extended-description

Name components may contain lowercase letters, digits and separators. A separator is defined as a period, one or two underscores, or one or more dashes. A name component may not start or end with a separator.

A tag name must be valid ASCII and may contain lowercase and uppercase letters, digits, underscores, periods, and dashes. A tag name may not start with a period or a dash and may contain a maximum of 128 characters.

If it's too tricky to get this validation to match docker's rules, we can also just try to catch the invalid argument error when running docker build command, and show a proper error message to the user. Currently it shows a confusing Broken pip error when using an invalid docker tag:

> bentoml containerize IrisClassifier:latest -t abc___def

[2020-07-12 18:06:02,231] INFO - Getting latest version IrisClassifier:20200701222443_EC5EAB
Found Bento: /Users/chaoyu/bentoml/repository/IrisClassifier/20200701222443_EC5EAB
Bento tag was changed to be Docker compatible.
"IrisClassifier:latest" -> "abc___def:latest"
Building Docker image: abc___def
Traceback (most recent call last):
  File "/Users/chaoyu/opt/miniconda3/envs/btml-dev/lib/python3.7/site-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/Users/chaoyu/opt/miniconda3/envs/btml-dev/lib/python3.7/site-packages/urllib3/connectionpool.py", line 354, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/Users/chaoyu/opt/miniconda3/envs/btml-dev/lib/python3.7/http/client.py", line 1252, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Users/chaoyu/opt/miniconda3/envs/btml-dev/lib/python3.7/http/client.py", line 1298, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Users/chaoyu/opt/miniconda3/envs/btml-dev/lib/python3.7/http/client.py", line 1247, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Users/chaoyu/opt/miniconda3/envs/btml-dev/lib/python3.7/http/client.py", line 1065, in _send_output
    self.send(chunk)
  File "/Users/chaoyu/opt/miniconda3/envs/btml-dev/lib/python3.7/http/client.py", line 987, in send
    self.sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

valid_name_pattern = re.compile(
r"""
^(
[a-z0-9]+ # alphanumeric
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love the regex inline comments here!

@parano parano self-requested a review July 14, 2020 16:52
@parano parano merged commit 5fab602 into bentoml:master Jul 14, 2020
aarnphm pushed a commit to aarnphm/BentoML that referenced this pull request Jul 29, 2022
* address comments for containerize command

* linting + naming fixes

* containerize and tag validation refactor

* fix tests

* linting + formatting + more logging

* add fix for non-ascii

* regex based validation and updated tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments