Skip to content

Instantly share code, notes, and snippets.

@dirtycajunrice
Last active January 16, 2019 21:26
Show Gist options
  • Save dirtycajunrice/f05d8f66c8d8a5ce90a26a760c1cccd9 to your computer and use it in GitHub Desktop.
Save dirtycajunrice/f05d8f66c8d8a5ce90a26a760c1cccd9 to your computer and use it in GitHub Desktop.
Manifest YAML Generator
import yaml
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
VERSION = '0.1.0'
# Docker image, arch, variant, os
ARCH_LIST = [
('arm', 'arm', 'v6', 'linux'),
('armhf', 'arm', 'v7', 'linux'),
('arm64', 'arm64', 'v8', 'linux'),
('amd64', 'amd64', None, 'linux')
]
if __name__ == "__main__":
parser = ArgumentParser(description='Manifest YAML Generator', formatter_class=ArgumentDefaultsHelpFormatter,
epilog='EXAMPLE: manifest_yaml_generator.py -o pyouroboros -p ouroboros -tags latest v1.0')
parser.add_argument('-v', '--version', action='version', version=VERSION)
parser.add_argument('-o', '--organization', required=True, help='Name of docker organizaton')
parser.add_argument('-p', '--project', required=True, help='Name of docker project')
parser.add_argument('-t', '--tags', nargs='+', default=['latest'], help='Tags to push')
parser.add_argument('-a', '--arches', nargs='+', default=[arch[0] for arch in ARCH_LIST], help='Arches to include')
parser.add_argument('-O', '--output-file', default='.manifest.yml')
args = parser.parse_args()
namespace = "{}/{}".format(args.organization.lower(), args.project.lower())
yaml_arr = []
args.arches = [arch.lower() for arch in args.arches]
arches = [arch for arch in ARCH_LIST if arch[0] in args.arches]
for tag in args.tags:
yaml_doc = {
'image': '{}:{}'.format(namespace, tag),
'manifests': []
}
for arch in arches:
info = {
'image': "{}:{}-{}".format(namespace, tag, arch[0]),
'platform': {
'architecture': arch[1],
'os': arch[3]
}
}
if arch[2]:
info['platform']['variant'] = arch[2]
yaml_doc['manifests'].append(info)
yaml_arr.append(yaml_doc)
with open(args.output_file, 'w') as file:
yaml.dump_all(yaml_arr, file, default_flow_style=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment