Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(hub): add docker readme push #559

Merged
merged 5 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jina/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# do not change this line manually
# this is managed by git tag and updated on every release
__version__ = '0.2.11'
__version__ = '0.3.0'

# do not change this line manually
# this is managed by proto/build-proto.sh and updated on every execution
Expand Down
29 changes: 25 additions & 4 deletions jina/hubapi/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self, args: 'argparse.Namespace'):
self.logger.critical('requires "docker" dependency, please install it via "pip install jina[docker]"')
raise

def push(self, name: str = None):
def push(self, name: str = None, readme_path: str = None):
"""A wrapper of docker push """
name = name or self.args.name
check_registry(self.args.registry, name, _repo_prefix)
Expand All @@ -57,14 +57,31 @@ def push(self, name: str = None):
self.logger.debug(line)
self.logger.success(f'🎉 {name} is now published!')

if False and readme_path:
# unfortunately Docker Hub Personal Access Tokens cannot be used as they are not supported by the API
_volumes = {os.path.dirname(os.path.abspath(readme_path)): {'bind': '/workspace'}}
_env = get_default_login()
_env = {
'DOCKERHUB_USERNAME': _env['username'],
'DOCKERHUB_PASSWORD': _env['password'],
'DOCKERHUB_REPOSITORY': name.split(':')[0],
'README_FILEPATH': '/workspace/README.md',
}

self._client.containers.run('peterevans/dockerhub-description:2.1',
auto_remove=True,
volumes=_volumes,
environment=_env)

share_link = f'https://api.jina.ai/hub/?jh={urllib.parse.quote_plus(name)}'

try:
webbrowser.open(share_link, new=2)
except:
pass
finally:
self.logger.info(f'Check out the usage {colored(share_link, "cyan", attrs=["underline"])} and share it with others!')
self.logger.info(
f'Check out the usage {colored(share_link, "cyan", attrs=["underline"])} and share it with others!')

def pull(self):
"""A wrapper of docker pull """
Expand Down Expand Up @@ -96,7 +113,11 @@ def _check_docker_image(self, name: str):

def login(self):
"""A wrapper of docker login """
password = self.args.password or (self.args.password_stdin and self.args.password_stdin.read())
try:
password = self.args.password or (self.args.password_stdin and self.args.password_stdin.read())
except ValueError:
password = ''

if self.args.username and password:
self._client.login(username=self.args.username, password=password,
registry=self.args.registry)
Expand All @@ -119,7 +140,7 @@ def build(self):
f'🎉 built {image.tags[0]} ({image.short_id}) uncompressed size: {get_readable_size(image.attrs["Size"])}')

if self.args.push:
self.push(image.tags[0])
self.push(image.tags[0], self.readme_path)

def _check_completeness(self):
self.dockerfile_path = get_exist_path(self.args.path, 'Dockerfile')
Expand Down
9 changes: 4 additions & 5 deletions jina/main/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,10 @@ def set_hub_base_parser(parser=None):
import sys
parser.add_argument('--username', type=str, help='the registry username')
_gp = parser.add_mutually_exclusive_group()
_gp.add_argument('--password-stdin', type=argparse.FileType('r'), default=(None if sys.stdin.isatty() else sys.stdin),
help='take the password from stdin')
_gp.add_argument('--password', type=str,
default=(None if sys.stdin.isatty() else sys.stdin),
help='the plaintext password')
_gp.add_argument('--password-stdin', type=argparse.FileType('r'),
default=sys.stdin,
help='take the password from stdin')
_gp.add_argument('--password', type=str, help='the plaintext password')
parser.add_argument('--registry', type=str, default='https://index.docker.io/v1/',
help='the URL to the registry, e.g. https://index.docker.io/v1/')

Expand Down
2 changes: 1 addition & 1 deletion release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function git_commit {
git config --local user.name "Jina Dev Bot"
git tag "v$RELEASE_VER" -m "$(cat ./CHANGELOG.tmp)"
git add $INIT_FILE ./CHANGELOG.md
git commit -m "chore(version): bumping version to $NEXT_VER"
git commit -m "chore(version): the next version will be $NEXT_VER"
}


Expand Down