6 parser = argparse.ArgumentParser()
8 parser.add_argument('-d', action='store', dest='directory', help='Directory location to store ONAP docker images')
9 parser.add_argument('-l', action='store', dest='docker_images_list', help='List of ONAP docker images')
10 args = parser.parse_args()
13 def get_image_tokens(image_list):
15 with open(image_list) as f:
16 for line in f.readlines():
17 pattern = re.compile("^(.*):([0-9.]*)\\s#(.*)$")
18 matches = re.match(pattern, line)
19 tokens.append(matches.groups())
24 def docker_save_images(tokens, directory):
25 if not os.path.exists(directory):
26 os.makedirs(directory)
31 docker_save(token, directory)
32 docker_remove_image(token)
35 def docker_save(token, directory):
36 image, version, sha = token
38 print("Saving docker image: {image} (Version: {version})".format(image=image, version=version))
40 src_str = os.path.join("registry.nordix.org", "onap", "online-install")
41 repl_str = "nexus.onap.org:10001"
42 image_target = "{dir}{sep}{image}_{tag}.tar".format(dir=directory, sep=os.path.sep, image=image.replace(
43 src_str, repl_str).replace(os.path.sep, "_").replace(":", "_"), tag=version)
45 if not os.path.exists(image_target):
47 subprocess.check_output(['docker', 'save', '{image}:{tag}'.format(image=image, tag=version), '-o',
49 except subprocess.CalledProcessError as e:
50 print("Error saving docker file ({file}): {error}".format(file=image_target, error=e.message))
53 def docker_tag(token):
54 image, version, sha = token
56 target_image = image.replace("registry.nordix.org/onap/online-install", "nexus.onap.org:10001")
58 print("Tagging docker image...\n\t/Source: {image} (SHA: {sha}, Version: {version}\n\tTarget: {target})".format(
59 image=image, sha=sha, version=version, target=target_image))
61 subprocess.check_output(['docker', 'tag', '{image}@{tag}'.format(image=image, tag=sha),
62 '{image}:{tag}'.format(image=target_image, tag=version)])
63 except subprocess.CalledProcessError as e:
64 print("Error tagging docker image ({image}): {error}".format(image=image, error=e.message))
67 def docker_remove_image(token):
68 image, version, sha = token
70 print("Removing docker image: {image}:{version})".format(image=image, version=version))
72 subprocess.check_output(['docker', 'rmi', '{image}:{tag}'.format(image=image, tag=version)])
73 except subprocess.CalledProcessError as e:
74 print("Error tagging docker image ({image}): {error}".format(image=image, error=e.message))
77 def docker_pull(token):
78 image, version, sha = token
80 print("Pulling docker image: {image} (Version: {version})".format(image=image, version=version))
82 subprocess.check_output(['docker', 'pull', '{image}:{tag}'.format(image=image, tag=version)])
83 except subprocess.CalledProcessError as e:
84 print("Error pulling docker image ({image}): {error}".format(image=image, error=e.message))
87 image_tokens = get_image_tokens(args.docker_images_list)
88 docker_save_images(image_tokens, args.directory)