Skip to content

Commit

Permalink
feat: enable to select dockerfile (#2056)
Browse files Browse the repository at this point in the history
  • Loading branch information
nan-wang authored Mar 2, 2021
1 parent ab537dc commit 9cc8934
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 50 deletions.
2 changes: 1 addition & 1 deletion jina/docker/hubio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 2 additions & 0 deletions jina/parsers/hub/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 0 additions & 3 deletions tests/integration/hub_usage/hub-mwu-multistage/README.md

This file was deleted.

Empty file.
16 changes: 0 additions & 16 deletions tests/integration/hub_usage/hub-mwu-multistage/manifest.yml

This file was deleted.

17 changes: 0 additions & 17 deletions tests/integration/hub_usage/hub-mwu-multistage/mwu_encoder.py

This file was deleted.

This file was deleted.

6 changes: 3 additions & 3 deletions tests/integration/hub_usage/test_hub_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
5 changes: 5 additions & 0 deletions tests/unit/docker/hub-mwu/another.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM jinaai/jina:test-pip

ADD *.py mwu_encoder.yml ./

ENTRYPOINT ["jina", "pod", "--uses", "mwu_encoder.yml"]
11 changes: 8 additions & 3 deletions tests/unit/docker/test_hubio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

0 comments on commit 9cc8934

Please sign in to comment.