def create_docker_image(args): """Create a directory containing all the necessary ingredients to construct a docker image. Returns the created DockerDevice objects. """ cfg = DockerConfig() if args.metrics: cfg.set_collect_metrics(True) if args.no_metrics: cfg.set_collect_metrics(False) if not cfg.decided_on_metrics(): logging.warning( "Please opt in or out of metrics collection.\n" "You will receive this warning until an option is selected.\n" "To opt in or out pass the --metrics or --no-metrics flag\n" "Note, that metrics will only be collected if you opt in.") imgzip = [args.imgzip] if not os.path.exists(imgzip[0]): imgzip = [ x.download() for x in emu_downloads_menu.find_image(imgzip[0]) ] emuzip = [args.emuzip] if emuzip[0] in ["stable", "canary", "all"]: emuzip = [ x.download() for x in emu_downloads_menu.find_emulator(emuzip[0]) ] elif re.match("\d+", emuzip[0]): # We must be looking for a build id logging.info("Treating %s as a build id", emuzip[0]) emuzip = [emu_downloads_menu.download_build(emuzip[0])] devices = [] for (img, emu) in itertools.product(imgzip, emuzip): logging.info("Processing %s, %s", img, emu) rel = emu_downloads_menu.AndroidReleaseZip(img) if not rel.is_system_image(): raise Exception( "{} is not a zip file with a system image".format(img)) rel = emu_downloads_menu.AndroidReleaseZip(emu) if not rel.is_emulator(): raise Exception( "{} is not a zip file with an emulator".format(emu)) device = DockerDevice(emu, img, args.dest, args.gpu, args.repo, args.tag) device.create_docker_file(args.extra, cfg.collect_metrics()) img = device.create_container() if img and args.start: device.launch(img) if args.push: device.push(img) devices.append(device) return devices
def create_docker_image(args): """Create a directory containing all the necessary ingredients to construct a docker image.""" device = DockerDevice(args.emuzip, args.imgzip, args.dest) device.create_docker_file(args.extra) img = device.create_container() if img and args.start: device.launch(img)
def create_docker_image(args): """Create a directory containing all the necessary ingredients to construct a docker image. Returns the DockerDevice object. """ imgzip = args.imgzip if not os.path.exists(imgzip): imgzip = emu_downloads_menu.find_image(imgzip).download() emuzip = args.emuzip if emuzip in ["stable", "canary"]: emuzip = emu_downloads_menu.find_emulator(emuzip).download() rel = emu_downloads_menu.AndroidReleaseZip(imgzip) if not rel.is_system_image(): raise Exception( "{} is not a zip file with a system image".format(imgzip)) rel = emu_downloads_menu.AndroidReleaseZip(emuzip) if not rel.is_emulator(): raise Exception("{} is not a zip file with an emulator".format(imgzip)) device = DockerDevice(emuzip, imgzip, args.dest, args.tag) device.create_docker_file(args.extra) img = device.create_container() if img and args.start: device.launch(img) return device
def create_docker_image_interactive(args): """Interactively create a docker image by selecting the desired combination from a menu.""" img = emu_downloads_menu.select_image(args.arm) or sys.exit(1) emulator = emu_downloads_menu.select_emulator() or sys.exit(1) img_zip = img.download() emu_zip = emulator.download("linux") device = DockerDevice(emu_zip, img_zip, args.dest) device.create_docker_file(args.extra) img = device.create_container() if img and args.start: device.launch(img)
def create_docker_image(args): """Create a directory containing all the necessary ingredients to construct a docker image.""" imgzip = args.imgzip if not os.path.exists(imgzip): imgzip = emu_downloads_menu.find_image(imgzip).download() emuzip = args.emuzip if emuzip in ['stable', 'canary']: emuzip = emu_downloads_menu.find_emulator(emuzip).download() device = DockerDevice(emuzip, imgzip, args.dest, args.tag) device.create_docker_file(args.extra) img = device.create_container() if img and args.start: device.launch(img)
def create_docker_image_interactive(args): """Interactively create a docker image by selecting the desired combination from a menu.""" img = emu_downloads_menu.select_image(args.arm) or sys.exit(1) emulator = emu_downloads_menu.select_emulator() or sys.exit(1) cfg = DockerConfig() metrics = False if not cfg.decided_on_metrics(): cfg.set_collect_metrics( click.confirm( "Would you like to help make the emulator better by sending usage statistics to Google upon (graceful) emulator exit?" )) metrics = cfg.collect_metrics() img_zip = img.download() emu_zip = emulator.download("linux") device = DockerDevice(emu_zip, img_zip, args.dest, args.gpu) device.create_docker_file(args.extra, metrics) img = device.create_container() if img and args.start: device.launch(img)
def cloud_build(args): licenses = set([x.license for x in emu_downloads_menu.get_emus_info()] + [x.license for x in emu_downloads_menu.get_images_info()]) for l in licenses: l.force_accept() imgzip = [x.download() for x in emu_downloads_menu.find_image(args.img)] emuzip = [x.download() for x in emu_downloads_menu.find_emulator("canary")] devices = [] steps = [] images = [] emulators = set() for (img, emu) in itertools.product(imgzip, emuzip): logging.info("Processing %s, %s", img, emu) img_rel = emu_downloads_menu.AndroidReleaseZip(img) if not img_rel.is_system_image(): logging.warn( "{} is not a zip file with a system image (Unexpected description), skipping" .format(img)) continue emu_rel = emu_downloads_menu.AndroidReleaseZip(emu) if not emu_rel.is_emulator(): raise Exception( "{} is not a zip file with an emulator".format(emu)) emulators.add(emu_rel.build_id()) for metrics in [True, False]: name = img_rel.repo_friendly_name() if not metrics: name += "-no-metrics" dest = os.path.join(args.dest, name) logging.info("Generating %s", name) device = DockerDevice(emu, img, dest, gpu=False, repo=args.repo, tag=emu_rel.build_id(), name=name) device.create_docker_file("", metrics=True, by_copying_zip_files=True) steps.append(device.create_cloud_build_step()) images.append(device.tag) cloudbuild = {"steps": steps, "images": images} with open(os.path.join(args.dest, "cloudbuild.yaml"), "w") as ymlfile: yaml.dump(cloudbuild, ymlfile) writer = TemplateWriter(args.dest) writer.write_template( "cloudbuild.README.MD", { "emu_version": ", ".join(emulators), "emu_images": "\n".join(images) }, rename_as="README.MD", )
def cloud_build(args): licenses = set( [x.license for x in emu_downloads_menu.get_emus_info()] + [x.license for x in emu_downloads_menu.get_images_info()] ) for l in licenses: l.force_accept() imgzip = [x.download() for x in emu_downloads_menu.find_image(args.img)] emuzip = [args.emuzip] if emuzip[0] in ["stable", "canary", "all"]: emuzip = [x.download() for x in emu_downloads_menu.find_emulator(emuzip[0])] elif re.match("\d+", emuzip[0]): # We must be looking for a build id logging.info("Treating %s as a build id", emuzip[0]) emuzip = [emu_downloads_menu.download_build(emuzip[0])] steps = [] images = [] desserts = set() emulators = set() for (img, emu) in itertools.product(imgzip, emuzip): logging.info("Processing %s, %s", img, emu) img_rel = emu_downloads_menu.AndroidReleaseZip(img) if not img_rel.is_system_image(): logging.warning("{} is not a zip file with a system image (Unexpected description), skipping".format(img)) continue emu_rel = emu_downloads_menu.AndroidReleaseZip(emu) if not emu_rel.is_emulator(): raise Exception("{} is not a zip file with an emulator".format(emu)) emulators.add(emu_rel.build_id()) desserts.add(img_rel.codename()) for metrics in [True, False]: name = img_rel.repo_friendly_name() if not metrics: name += "-no-metrics" dest = os.path.join(args.dest, name) logging.info("Generating %s", name) device = DockerDevice(emu, img, dest, gpu=False, repo=args.repo, tag=emu_rel.build_id(), name=name) device.create_docker_file("", metrics=True, by_copying_zip_files=True) steps.append(device.create_cloud_build_step()) images.append(device.tag) images.append(device.latest) steps[-1]["waitFor"] = ["-"] cloudbuild = {"steps": steps, "images": images, "timeout": "21600s"} with open(os.path.join(args.dest, "cloudbuild.yaml"), "w") as ymlfile: yaml.dump(cloudbuild, ymlfile) writer = TemplateWriter(args.dest) writer.write_template( "cloudbuild.README.MD", {"emu_version": ", ".join(emulators), "emu_images": "\n".join(["* {}".format(x) for x in images])}, rename_as="README.MD", ) writer.write_template( "registry.README.MD", { "emu_version": ", ".join(emulators), "emu_images": "\n".join(["* {}".format(x) for x in images]), "first_image": images[0] }, rename_as="REGISTRY.MD", ) if args.git: git_commit_and_push(args.dest)