diff --git a/jina/docker/hubio.py b/jina/docker/hubio.py index 9dc82b546ec6e..00e139f053f96 100644 --- a/jina/docker/hubio.py +++ b/jina/docker/hubio.py @@ -560,7 +560,7 @@ def _freeze_jina_version(self) -> None: fp.write('\n'.join(new_requirements)) def _check_completeness(self) -> Dict: - dockerfile_path = get_exist_path(self.args.path, 'Dockerfile') + dockerfile_path = get_exist_path(self.args.path, self.args.file) manifest_path = get_exist_path(self.args.path, 'manifest.yml') self.config_yaml_path = get_exist_path(self.args.path, 'config.yml') self.readme_path = get_exist_path(self.args.path, 'README.md') diff --git a/jina/parsers/hub/build.py b/jina/parsers/hub/build.py index ca3da0608f471..db3eba85f964c 100644 --- a/jina/parsers/hub/build.py +++ b/jina/parsers/hub/build.py @@ -14,6 +14,8 @@ def mixin_hub_build_parser(parser): 'zero or more yaml config, ' 'zero or more Python file. ' 'All files in this directory will be shipped into a Docker image') + gp.add_argument('-f', '--file', type=str, default='Dockerfile', + help='Name of the Dockerfile (Default is `path/Dockerfile`') gp.add_argument('--pull', action='store_true', default=False, help='If set, downloads any updates to the FROM image in Dockerfiles') gp.add_argument('--push', action='store_true', default=False, diff --git a/tests/integration/hub_usage/hub-mwu-multistage/README.md b/tests/integration/hub_usage/hub-mwu-multistage/README.md deleted file mode 100644 index 2826920f84173..0000000000000 --- a/tests/integration/hub_usage/hub-mwu-multistage/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# MWUEncoder - -A dummy encoder encodes any input into a random 3-dimensional vector. This encoder has a dummy parameter `greetings` which prints a greeting message on start and on every encode. \ No newline at end of file diff --git a/tests/integration/hub_usage/hub-mwu-multistage/__init__.py b/tests/integration/hub_usage/hub-mwu-multistage/__init__.py deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/tests/integration/hub_usage/hub-mwu-multistage/manifest.yml b/tests/integration/hub_usage/hub-mwu-multistage/manifest.yml deleted file mode 100644 index 1fddc6ecbb12c..0000000000000 --- a/tests/integration/hub_usage/hub-mwu-multistage/manifest.yml +++ /dev/null @@ -1,16 +0,0 @@ -manifest_version: 1 -name: Dummy MWU Encoder -description: a minimum working unit of a containerized encoder, used for tutorial only -author: Jina AI Dev-Team (dev-team@jina.ai) -url: https://jina.ai -documentation: https://github.com/jina-ai/jina-hub -version: 0.0.6 -vendor: Jina AI Limited -license: apache-2.0 -update: nightly -keywords: - - example - - demo - - toy-example -kind: encoder -type: pod diff --git a/tests/integration/hub_usage/hub-mwu-multistage/mwu_encoder.py b/tests/integration/hub_usage/hub-mwu-multistage/mwu_encoder.py deleted file mode 100644 index 027002551a732..0000000000000 --- a/tests/integration/hub_usage/hub-mwu-multistage/mwu_encoder.py +++ /dev/null @@ -1,17 +0,0 @@ -from typing import Any - -import numpy as np - -from jina.executors.encoders import BaseEncoder - - -class MWUEncoder(BaseEncoder): - - def __init__(self, greetings: str, *args, **kwargs): - super().__init__(*args, **kwargs) - self._greetings = greetings - self.logger.success(f'look at me! {greetings}') - - def encode(self, data: Any, *args, **kwargs) -> Any: - self.logger.info(f'{self._greetings} {data}') - return np.random.random([data.shape[0], 3]) diff --git a/tests/integration/hub_usage/hub-mwu-multistage/mwu_encoder.yml b/tests/integration/hub_usage/hub-mwu-multistage/mwu_encoder.yml deleted file mode 100644 index 23b9927d74473..0000000000000 --- a/tests/integration/hub_usage/hub-mwu-multistage/mwu_encoder.yml +++ /dev/null @@ -1,7 +0,0 @@ -!MWUEncoder -with: - greetings: im from internal yaml! -metas: - name: my-mwu-encoder - py_modules: mwu_encoder.py - workspace: ./ \ No newline at end of file diff --git a/tests/integration/hub_usage/hub-mwu-multistage/Dockerfile b/tests/integration/hub_usage/hub-mwu/multistage.Dockerfile similarity index 100% rename from tests/integration/hub_usage/hub-mwu-multistage/Dockerfile rename to tests/integration/hub_usage/hub-mwu/multistage.Dockerfile diff --git a/tests/integration/hub_usage/test_hub_usage.py b/tests/integration/hub_usage/test_hub_usage.py index 77e642b8291d2..6a0ff04c37e79 100644 --- a/tests/integration/hub_usage/test_hub_usage.py +++ b/tests/integration/hub_usage/test_hub_usage.py @@ -155,11 +155,11 @@ def test_hub_build_push_push_again(monkeypatch, mocker): @pytest.mark.timeout(360) @pytest.mark.parametrize('dockerfile_path', - [os.path.join(cur_dir, 'hub-mwu-multistage'), + [os.path.join(cur_dir, 'hub-mwu'), os.path.relpath( - os.path.join(cur_dir, 'hub-mwu-multistage'), + os.path.join(cur_dir, 'hub-mwu'), os.getcwd())]) def test_hub_build_multistage(dockerfile_path): - args = set_hub_build_parser().parse_args([dockerfile_path, '--raise-error']) + args = set_hub_build_parser().parse_args([dockerfile_path, '--raise-error', '-f', 'multistage.Dockerfile']) result = HubIO(args).build() assert result['is_build_success'] diff --git a/tests/unit/docker/hub-mwu/another.Dockerfile b/tests/unit/docker/hub-mwu/another.Dockerfile new file mode 100644 index 0000000000000..eb3ed572810a1 --- /dev/null +++ b/tests/unit/docker/hub-mwu/another.Dockerfile @@ -0,0 +1,5 @@ +FROM jinaai/jina:test-pip + +ADD *.py mwu_encoder.yml ./ + +ENTRYPOINT ["jina", "pod", "--uses", "mwu_encoder.yml"] \ No newline at end of file diff --git a/tests/unit/docker/test_hubio.py b/tests/unit/docker/test_hubio.py index 1d13ff43eda29..78198957c7a2e 100644 --- a/tests/unit/docker/test_hubio.py +++ b/tests/unit/docker/test_hubio.py @@ -72,11 +72,16 @@ def _mock_home(): assert fp.read() == 'access_token: access\n' -def test_dry_run(): +@pytest.mark.parametrize('dockerfile', ['', 'Dockerfile', 'another.Dockerfile']) +@pytest.mark.parametrize('argument', ['--file', '-f']) +def test_dry_run(dockerfile, argument): hub_mwu_path = os.path.join(cur_dir, 'hub-mwu') - args = set_hub_build_parser().parse_args([hub_mwu_path, '--dry-run']) + _args_list = [hub_mwu_path, '--dry-run'] + if dockerfile: + _args_list += [argument, dockerfile] + args = set_hub_build_parser().parse_args(_args_list) result = HubIO(args).build() - assert result['Dockerfile'] == os.path.join(hub_mwu_path, 'Dockerfile') + assert result['Dockerfile'] == os.path.join(hub_mwu_path, dockerfile if dockerfile else 'Dockerfile') assert result['manifest.yml'] == os.path.join(hub_mwu_path, 'manifest.yml') assert result['config.yml'] == os.path.join(hub_mwu_path, 'mwu_encoder.yml') assert result['README.md'] == os.path.join(hub_mwu_path, 'README.md')