Repository navigation
Containerize command - #847
Conversation
Codecov Report
@@ Coverage Diff @@
## master #847 +/- ##
==========================================
- Coverage 62.35% 62.24% -0.11%
==========================================
Files 117 118 +1
Lines 7783 7846 +63
==========================================
+ Hits 4853 4884 +31
- Misses 2930 2962 +32
Continue to review full report at Codecov.
|
|
|
||
| try: | ||
| docker_api = docker.APIClient() | ||
| ensure_docker_available_or_raise() |
There was a problem hiding this comment.
Since we are building with Docker, let's move the checking all the way to the top
There was a problem hiding this comment.
Looks like Python Docker SDK will give an error if Docker isn't installed anyways, so I removed it because it was redundant
|
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-09 06:55:26 UTC |
| click.echo('Service %s artifact directory => %s' % (name, target_dir)) | ||
|
|
||
| @cli.command( | ||
| help='Containerize given Bento into a Docker image', |
There was a problem hiding this comment.
Better help message, maybe something along the line of Containerize the given BentoService into a BentoML model service docker image.? You probably can find a better way to phrase it
|
|
||
| click.echo('Service %s artifact directory => %s' % (name, target_dir)) | ||
|
|
||
| @cli.command( |
There was a problem hiding this comment.
Maybe we should rename the command to create-docker-image using the name=? I want something very simple and direct. What do you think?
There was a problem hiding this comment.
IMO containerize is pretty self-explanatory and can be left as-is. Thoughts, @parano?
| with Spinner(f"Building Docker image: {name}\n"): | ||
| _echo_docker_api_result( | ||
| docker_api.build( | ||
| path=bento_service_bundle_path, tag=tag, decode=True, |
There was a problem hiding this comment.
Could you write a test for building from the local path and remote s3 URL?
There was a problem hiding this comment.
I've tested this locally with both local and remote s3 URL but I have no clue how to go about writing a unit test for this ://
| tag=version, | ||
| stream=True, | ||
| decode=True, | ||
| auth_config=auth_config_payload, |
There was a problem hiding this comment.
when username and password are not provided via the CLI, does docker_api.push pick up the local docker authentication information?
| f'{cmd_group.name} {command_name} failed: {str(e)}' | ||
| ) | ||
| msg = f'{cmd_group.name} {command_name} failed: {str(e)}' | ||
| raise ClickException(click.style(msg, fg='red')) |
…ntainerize-command
…ainerize-command
…ainerize-command
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import re |
There was a problem hiding this comment.
FYI: it looks like you moved this stuff to bento_service.py. You can use git mv or git cp when you migrate a lot of code from one file into a new file--that way, the new file will retain the old file's version history (and diffs will be more reasonable).
| def get_name_version_from_tag(bento): | ||
| # returns name:version | ||
| if ":" in bento: | ||
| return bento.split(":")[:2] |
There was a problem hiding this comment.
Would be good to log a warning or something if there is more than one colon in the string--[:2] is a nice way to make things run smoothly, but doing this cleanup silently might have surprising results for a naive user.
There was a problem hiding this comment.
will log a warning here
There was a problem hiding this comment.
oh wait actually it seems like the resolve_bundle_path function above this should catch this and raise an error
| 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 tag name must be valid ASCII and may contain lowercase and uppercase letters, |
There was a problem hiding this comment.
Are name and tag validated somewhere beforehand?
There was a problem hiding this comment.
no but we decided to just reformat it to be compatible and notify the user as per https://bentoml.slack.com/archives/CKC2JP3TM/p1593107935076500
| return file_path | ||
|
|
||
|
|
||
| def assert_equal_lists(res, expected): |
There was a problem hiding this comment.
Hmm, my understanding is that
assert res == expected
will work fine for lists. If you're concerned about arbitrary types of iterable, you can do
assert list(res) == list(expected)
| assert all([a == b for a, b in zip(expected, res)]) | ||
|
|
||
|
|
||
| def test_make_bento_name_docker_compatible(): |
There was a problem hiding this comment.
This is a good use case for parametrized tests. Internally, pytest will run a separate fixture with each set of parameters, so if there's a failure, you'll see exactly which set of parameters failed.
| }, | ||
| ] | ||
|
|
||
| with pytest.raises(BentoMLException) as e: |
|
|
||
| _echo(f"Found Bento: {bento_service_bundle_path}") | ||
|
|
||
| name, version = get_name_version_from_tag(bento) |
There was a problem hiding this comment.
This will break when the bento parameter is a file path. You can get the name and version with load_bento_service_metadata(bento_service_bundle_path)
There was a problem hiding this comment.
This will allow us to use the containerize by giving it the saved_path:
bentoml containerize $SAVED_PATH -t test_image
There was a problem hiding this comment.
Currently it breaks with the follow error:
$ bentoml containerize /Users/chaoyu/bentoml/repository/IrisClassifier/20200701222443_EC5EAB -t test_image
Found Bento: /Users/chaoyu/bentoml/repository/IrisClassifier/20200701222443_EC5EAB
Traceback (most recent call last):
File "/Users/chaoyu/opt/miniconda3/envs/btml-dev/bin/bentoml", line 33, in <module>
sys.exit(load_entry_point('BentoML', 'console_scripts', 'bentoml')())
File "/Users/chaoyu/opt/miniconda3/envs/btml-dev/lib/python3.7/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/Users/chaoyu/opt/miniconda3/envs/btml-dev/lib/python3.7/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/Users/chaoyu/opt/miniconda3/envs/btml-dev/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/chaoyu/opt/miniconda3/envs/btml-dev/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/chaoyu/opt/miniconda3/envs/btml-dev/lib/python3.7/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/Users/chaoyu/workspace/BentoML/bentoml/cli/click_utils.py", line 140, in wrapper
return func(*args, **kwargs)
File "/Users/chaoyu/workspace/BentoML/bentoml/cli/click_utils.py", line 117, in wrapper
return_value = func(*args, **kwargs)
File "/Users/chaoyu/workspace/BentoML/bentoml/cli/click_utils.py", line 101, in wrapper
return func(*args, **kwargs)
File "/Users/chaoyu/workspace/BentoML/bentoml/cli/bento_service.py", line 484, in containerize
name, version = make_bento_name_docker_compatible(name, version)
File "/Users/chaoyu/workspace/BentoML/bentoml/cli/bento_service.py", line 110, in make_bento_name_docker_compatible
tag = tag.lstrip(".-")[:128]
AttributeError: 'NoneType' object has no attribute 'lstrip'
| return | ||
|
|
||
|
|
||
| def make_bento_name_docker_compatible(name, tag): |
There was a problem hiding this comment.
what's the difference between name and tag here? It wasn't clear to me.
tag parameter here is the docker image version, not the entire docker image tag, right?
| '--tag', | ||
| help="Optional image tag. If not specified, Bento will generate one from " | ||
| "the name of the Bento.", | ||
| required=False, |
There was a problem hiding this comment.
I feel if you could valid this tag parameter here with a validation callback here, the rest of the code could be simplified https://click.palletsprojects.com/en/7.x/options/#callbacks-for-validation
| if tag is not None: | ||
| name, v = get_name_version_from_tag(tag) | ||
| if v is not None: | ||
| version = v |
There was a problem hiding this comment.
add a log message here? f"Tag {tag} does not specify an image version, using BentoService version {bento_service_version} as docker image version."
| f'Bento tag was changed to be Docker compatible. \n' | ||
| f'"{bento}" -> "{full_tag}"', | ||
| CLI_COLOR_WARNING, | ||
| ) |
There was a problem hiding this comment.
Assuming you added some validation for the tag parameter, this part could be rewritten to something like this:
bs_metadata = load_bento_service_metadata(bento_service_bundle_path)
if ":" not in tag:
_echo(f"Tag {tag} does not specify an image version, using BentoService version {bs_metadata.version} as docker image version.")
version= to_docker_tag_compatible_string(bs_metadata.version)
tag = f"{tag}:{version}"
_echo("Containerizing BentoService {bs_metadata.name}:{bs_metadata.version}, docker image tag: {tag}")
docker_api = docker.APIClient()
...
|
Great work @jackyzha0! I tried it out locally and it works great and I really love the UX. I just finished a pass with a few minor comments. I think the most important one being fixing running containerize with a file path to saved bundle. As the PR is getting really large, I will go ahead and merge it, feel free to address those comments in a follow-up PR. |
* add basic draft containerize * more wip stuff * linting + formatting * refactored to use CLIException * fix bad api catch and better docs * fix bad push catching and add colour * linting * fixed bad layer size calculation * better unpack * address comments * address naming * update containerize docs * wip migration * fixed bad imports * refactor bento_service tag handling behaviour * fix bad patch * update makefile and properly fix patch * add _echo_docker_api_result tests * fixed bad comparison in test * add basic e2e and test_make_bento_name_docker_compatible * remove e2e for another pr
Description
bentoml containerizewith--pushand--tagflagsMotivation and Context
How Has This Been Tested?
Types of changes
Component(s) if applicable
Checklist:
./dev/format.shand./dev/lint.shscript have passed(instructions).