Advertisement
yiorgos

copy_registry.py

Mar 22nd, 2020
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. # copy from one registry to the next
  2.  
  3. import requests
  4. import os
  5.  
  6. old_registry = "old.registry.tld"
  7. new_registry = "new.registry.tld"
  8.  
  9. old_catalog = "https://" + old_registry + "/v2/_catalog";
  10.  
  11. catalog = requests.get(old_catalog, auth=requests.auth.HTTPBasicAuth('admin', 'PASSWORD'))
  12.  
  13. repositories = catalog.json()['repositories']
  14.  
  15. image_list = []
  16. for r in repositories:
  17.     tags = requests.get('https://' + old_registry + '/v2/' + r + '/tags/list', auth=requests.auth.HTTPBasicAuth('admin', 'PASSWORD'))
  18.     if 'name' not in tags.json().keys():
  19.         continue
  20.     else:
  21.         if tags.json()['tags'] == None:
  22.             image_list.append(tags.json()['name'])
  23.             continue
  24.  
  25.         for t in tags.json()['tags']:
  26.             image_list.append("{}:{}".format(tags.json()['name'], t))
  27.  
  28. for i in image_list:
  29.     old_image = old_registry + '/' + i
  30.     new_image = new_registry + '/' + i
  31.     os.system("docker pull " + old_image)
  32.     os.system("docker tag " + old_image + " " + new_image)
  33.     os.system("docker push " + new_image)
  34.  
  35. for i in image_list:
  36.     old_image = old_registry + '/' + i
  37.     new_image = new_registry + '/' + i
  38.     os.system("docker rmi " + old_image + "  " + new_image)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement