Skip to content

Commit

Permalink
feat(bookkeeping): fixing push flow, file read issues
Browse files Browse the repository at this point in the history
  • Loading branch information
deepankarm authored and JoanFM committed Sep 17, 2020
1 parent 9c8066f commit 88c1bc4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 35 deletions.
2 changes: 1 addition & 1 deletion jina/docker/checker.py
Expand Up @@ -77,7 +77,7 @@ def get_exist_path(directory, s):
return r

def get_summary_path(image_name: str):
return os.path.join(tempfile.gettempdir(), image_name.replace('/', '_'), 'summary.json')
return os.path.join(tempfile.gettempdir(), image_name.replace('/', '_') + '_summary.json')


def is_error_message(s):
Expand Down
58 changes: 24 additions & 34 deletions jina/docker/hubio.py
Expand Up @@ -75,45 +75,31 @@ def new(self):
self.logger.info('nothing is created, bye!')

def push(self, name: str = None, readme_path: str = None):
""" A wrapper of docker push """
is_build_success, is_push_success = True, False
""" A wrapper of docker push
- Checks for the tempfile, returns without push if it cannot find
- Pushes to docker hub, returns withput writing to db if it fails
- Writes to the db
"""
name = name or self.args.name
file_path = get_summary_path(name)
if not os.path.isfile(file_path):
self.logger.error(f'can not find the build summary file')
return

try:
self._push_docker_hub(name, readme_path)
is_push_success = True
except:
self.logger.error(f'can not push to the registry')

file_path = get_summary_path(name)
if os.path.isfile(file_path):
with open(file_path) as f:
result = json.load(f)
else:
image = self._client.images.get(name)
_details = {
'inspect': self._raw_client.inspect_image(image.tags[0]),
'tag': image.tags[0],
'hash': image.short_id,
'size': get_readable_size(image.attrs['Size']),
}

result = {
'name': name,
'path': getattr(self.args, 'path', ''),
'details': _details,
'last_build_time': get_now_timestamp(),
'build_duration': '',
'is_build_success': is_build_success,
'is_push_success': is_push_success,
'build_logs': [],
'exception': []
}

return

with open(file_path) as f:
result = json.load(f)
if result['is_build_success']:
self._write_summary_to_db(summary=result)

def _push_docker_hub(self, name: str = None, readme_path: str = None):
""" Helper push function """
name = name or self.args.name
name = name
check_registry(self.args.registry, name, _repo_prefix)
self._check_docker_image(name)
self.login()
Expand Down Expand Up @@ -264,9 +250,9 @@ def build(self) -> Dict:
self.logger.error(f'can not use it in the Flow')
is_build_success = False

if is_build_success and self.args.push:
if self.args.push:
try:
self.push(image.tags[0], self.readme_path)
self._push_docker_hub(image.tags[0], self.readme_path)
is_push_success = True
except Exception:
self.logger.error(f'can not push to the registry')
Expand All @@ -286,9 +272,13 @@ def build(self) -> Dict:
'build_logs': _logs,
'exception': _excepts
}

# only successful build (NOT dry run) writes the summary to disk
self._write_summary_to_file(result)

if result['is_build_success']:
self._write_summary_to_file(summary=result)
if self.args.push:
self._write_summary_to_db(summary=result)

if not result['is_build_success'] and self.args.raise_error:
# remove the very verbose build log when throw error
result.pop('build_logs')
Expand Down

0 comments on commit 88c1bc4

Please sign in to comment.