def _prompt_artifact_selection(self, service_name, artifact_key, deployment_repo, env, artifacts):
current_image = deployment_repo['tfvars'].get(artifact_key, env)
io.info('found artifacts for "%s/%s"' % (self.config.get('dockerhub')['organization'], service_name,))
table_data = [
('id', 'tag name (* = current)', 'created at', 'size',),
]
for i, artifact in enumerate(artifacts, 1):
created_at = datetime.strptime(artifact['last_updated'], '%Y-%m-%dT%H:%M:%S.%fZ')
created_at = pretty_print_datetime(created_at)
image_size = humanize.naturalsize(artifact['full_size'])
image_name = artifact['name']
if image_name in current_image: # indicate the current artifact.
image_name += ' *'
table_data.append((str(i), image_name, created_at, image_size,))
io.print_table(table_data, 'recent artifacts')
# Handle the case where the selected artifact is the current artifact.
selected_artifact = io.collect_input('select the artifact you want to use [q]:', artifacts)
if selected_artifact and selected_artifact['name'] in current_image:
io.err('selected artifact is already the current active artifact')
return None
return selected_artifact
评论列表
文章目录