-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate.py
More file actions
48 lines (37 loc) · 1.61 KB
/
Copy pathcreate.py
File metadata and controls
48 lines (37 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
import requests
import hashlib
import os
import sys
endpoint = os.environ.get('ENDPOINT')
containershare = os.environ.get('CONTAINERSHARE')
singularity_cache = os.environ.get('SINGULARITY_CACHEDIR', '%s/.singularity' %os.environ.get('HOME'))
if endpoint is None or containershare is None or singularity_cache is None:
print('Please export ENDPOINT, CONTAINERSHARE, and SINGULARITY_CACHEDIR to the environment first!')
sys.exit(1)
# Sanity check for the user
print('Endpoint: %s' %endpoint)
print('Containershare: %s' %containershare)
print('Singularity Cache: %s' %singularity_cache)
# Ensure containers are pulled to share
os.environ['SINGULARITY_PULLFOLDER'] = containershare
os.putenv('SINGULARITY_PULLFOLDER', containershare)
containers = requests.get(endpoint).json()
for container in containers:
github = container['github'].split('/')[-2:]
gh_pages = "https://%s.github.io/%s/tags.json" %(github[0], github[1])
tags = requests.get(gh_pages).text.split('\n')
for tag in tags:
if tag:
container_name = "docker://%s:%s" %(container['name'], tag)
print(container_name)
# Get the hash
m = hashlib.md5()
m.update(container_name.encode('utf-8'))
container_hash = m.hexdigest()
container_path = "%s/%s" %(containershare, container_hash)
try:
if not os.path.exists(container_path):
os.system('singularity pull --name %s.simg %s' %(container_hash, container_name))
except:
print('Error pulling %s' %container_name)