3 from __future__ import print_function
12 return arv.users().current().execute()['uuid'][:5]
15 def findormake_project(arv, prefix, project_name):
16 system_user_uuid = prefix+'-tpzed-000000000000000'
17 groups = arv.groups().list(
19 ['name', '=', project_name],
20 ['owner_uuid', '=', system_user_uuid],
22 select=['uuid', 'group_class']).execute()['items']
25 logger.debug('found project %s', proj['uuid'])
26 if proj['group_class'] != 'project':
27 logger.info('project %s has group_class %s, changing to %s',
28 proj['uuid'], proj['group_class'], 'project')
32 'group_class': 'project',
35 uuid = arv.groups().create(body={
36 'group_class': 'project',
38 'owner_uuid': system_user_uuid,
40 logger.info('created project %s: %s', uuid, project_name)
44 def findormake_project_perm(arv, prefix, project_uuid):
45 all_users_group_uuid = prefix+'-j7d0g-fffffffffffffff'
46 links = arv.links().list(
48 ['tail_uuid', '=', all_users_group_uuid],
49 ['head_uuid', '=', project_uuid],
50 ['link_class', '=', 'permission'],
51 ['name', '=', 'can_read'],
53 select=['uuid']).execute()['items']
55 logger.debug('found permission link %s', links[0]['uuid'])
57 uuid = arv.links().create(body={
58 'tail_uuid': all_users_group_uuid,
59 'head_uuid': project_uuid,
60 'link_class': 'permission',
63 logger.info('created permission link %s: %s -> %s',
64 uuid, all_users_group_uuid, project_uuid)
68 def findorpull_image(want_repo, want_tag, project_uuid):
69 for line in subprocess.check_output(['arv-keepdocker']).splitlines():
71 repo, tag, image_id, collection, created = line.split(None, 4)
74 if repo == want_repo and tag == want_tag:
75 logger.debug('found image tag %s collection %s created %s',
76 tag, collection, created)
78 logger.info('pulling repo %s tag %s', want_repo, want_tag)
79 subprocess.check_call([
81 '--pull', '--project-uuid='+project_uuid,
85 def tag_latest(repo, tag, project_uuid):
86 logger.debug('tagging %s:%s as %s:latest', repo, tag, repo)
87 tag_cmd = ['docker', 'tag']
88 if subprocess.check_output(tag_cmd + ['--help']).find('--force') >= 0:
89 tag_cmd += ['--force']
90 tag_cmd += [repo+':'+tag, repo+':latest']
91 subprocess.check_call(tag_cmd)
93 logger.debug('arv-keepdocker %s:latest', repo)
94 subprocess.check_call([
96 '--project-uuid='+project_uuid,
100 logging.basicConfig()
101 logger = logging.getLogger(__name__)
102 logger.setLevel(logging.INFO)
104 parser = argparse.ArgumentParser(
105 description='Pull a specific version of the arvados/jobs image to Keep, and tag it as :latest')
107 '--git-commit', type=str, required=True,
108 help='git commit hash of desired version')
110 '--verbose', '-v', action='count', default=0,
111 help='print more debug messages')
112 args = parser.parse_args()
113 logger.setLevel(logging.INFO - 10 * args.verbose)
115 arv = arvados.api('v1')
116 prefix = uuid_prefix(arv)
117 project_uuid = findormake_project(arv, prefix, 'Arvados Standard Docker Images')
118 findormake_project_perm(arv, prefix, project_uuid)
119 findorpull_image('arvados/jobs', args.git_commit, project_uuid)
120 tag_latest('arvados/jobs', args.git_commit, project_uuid)