3 # Copyright (C) The Arvados Authors. All rights reserved.
5 # SPDX-License-Identifier: AGPL-3.0
7 from __future__ import print_function
16 return arv.users().current().execute()['uuid'][:5]
19 def findormake_project(arv, prefix, project_name):
20 system_user_uuid = prefix+'-tpzed-000000000000000'
21 groups = arv.groups().list(
23 ['name', '=', project_name],
24 ['owner_uuid', '=', system_user_uuid],
26 select=['uuid', 'group_class']).execute()['items']
29 logger.debug('found project %s', proj['uuid'])
30 if proj['group_class'] != 'project':
31 logger.info('project %s has group_class %s, changing to %s',
32 proj['uuid'], proj['group_class'], 'project')
36 'group_class': 'project',
39 uuid = arv.groups().create(body={
40 'group_class': 'project',
42 'owner_uuid': system_user_uuid,
44 logger.info('created project %s: %s', uuid, project_name)
48 def findormake_project_perm(arv, prefix, project_uuid):
49 all_users_group_uuid = prefix+'-j7d0g-fffffffffffffff'
50 links = arv.links().list(
52 ['tail_uuid', '=', all_users_group_uuid],
53 ['head_uuid', '=', project_uuid],
54 ['link_class', '=', 'permission'],
55 ['name', '=', 'can_read'],
57 select=['uuid']).execute()['items']
59 logger.debug('found permission link %s', links[0]['uuid'])
61 uuid = arv.links().create(body={
62 'tail_uuid': all_users_group_uuid,
63 'head_uuid': project_uuid,
64 'link_class': 'permission',
67 logger.info('created permission link %s: %s -> %s',
68 uuid, all_users_group_uuid, project_uuid)
72 def findorpull_image(want_repo, want_tag, project_uuid):
73 logger.info('pulling repo %s tag %s', want_repo, want_tag)
74 subprocess.check_call([
76 '--pull', '--project-uuid='+project_uuid,
80 def tag_latest(repo, tag, project_uuid):
81 logger.debug('tagging %s:%s as %s:latest', repo, tag, repo)
82 tag_cmd = ['docker', 'tag']
83 if subprocess.check_output(tag_cmd + ['--help']).find('--force') >= 0:
84 tag_cmd += ['--force']
85 tag_cmd += [repo+':'+tag, repo+':latest']
86 subprocess.check_call(tag_cmd)
88 logger.debug('arv-keepdocker %s:latest', repo)
89 subprocess.check_call([
91 '--project-uuid='+project_uuid,
96 logger = logging.getLogger(__name__)
97 logger.setLevel(logging.INFO)
99 parser = argparse.ArgumentParser(
100 description='Pull a specific version of the arvados/jobs image to Keep, and tag it as :latest')
102 '--git-commit', type=str, required=True,
103 help='git commit hash of desired version')
105 '--verbose', '-v', action='count', default=0,
106 help='print more debug messages')
107 args = parser.parse_args()
108 logger.setLevel(logging.INFO - 10 * args.verbose)
110 arv = arvados.api('v1')
111 prefix = uuid_prefix(arv)
112 project_uuid = findormake_project(arv, prefix, 'Arvados Standard Docker Images')
113 findormake_project_perm(arv, prefix, project_uuid)
114 findorpull_image('arvados/jobs', args.git_commit, project_uuid)
115 tag_latest('arvados/jobs', args.git_commit, project_uuid)