yiorgos icon

copy_registry.py

yiorgos | PRO | 03/22/20 03:16:31 PM UTC | 0 ⭐ | 361 👁️ | Never ⏰ | []
Python |

1.13 KB

|

None

|

0 👍

/

0 👎

# copy from one registry to the next
 
import requests
import os
 
old_registry = "old.registry.tld"
new_registry = "new.registry.tld"
 
old_catalog = "https://" + old_registry + "/v2/_catalog";
 
catalog = requests.get(old_catalog, auth=requests.auth.HTTPBasicAuth('admin', 'PASSWORD'))
 
repositories = catalog.json()['repositories']
 
image_list = []
for r in repositories:
    tags = requests.get('https://' + old_registry + '/v2/' + r + '/tags/list', auth=requests.auth.HTTPBasicAuth('admin', 'PASSWORD'))
    if 'name' not in tags.json().keys():
        continue
    else:
        if tags.json()['tags'] == None:
            image_list.append(tags.json()['name'])
            continue
 
        for t in tags.json()['tags']:
            image_list.append("{}:{}".format(tags.json()['name'], t))
 
for i in image_list:
    old_image = old_registry + '/' + i
    new_image = new_registry + '/' + i
    os.system("docker pull " + old_image)
    os.system("docker tag " + old_image + " " + new_image)
    os.system("docker push " + new_image)
 
for i in image_list:
    old_image = old_registry + '/' + i
    new_image = new_registry + '/' + i
    os.system("docker rmi " + old_image + "  " + new_image)

Comments