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
예제 #2
0
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
예제 #3
0
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)
예제 #4
0
def create_docker_image(args):
    """Create a directory containing all the necessary ingredients to construct a docker image.

    Returns the created DockerDevice objects.
    """
    cfg = metrics_config(args)
    imgzip = [args.imgzip]
    if not os.path.exists(imgzip[0]):
        imgzip = 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(r"\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 = []
    logging.info("Using repo %s", args.repo)
    for (img, emu) in itertools.product(imgzip, emuzip):
        logging.info("Processing %s, %s", img, emu)
        sys_docker = SystemImageContainer(img, args.repo)
        if not sys_docker.available() and not sys_docker.can_pull():
            sys_docker.build(args.dest)
        else:
            print("No need to build {}, it's already available".format(
                sys_docker))
        if args.push:
            sys_docker.push()

        if args.sys:
            continue

        emu_docker = EmulatorContainer(emu, sys_docker, args.repo,
                                       cfg.collect_metrics(), args.extra)
        emu_docker.build(args.dest)

        if args.start:
            emu_docker.launch({"5555/tcp": 5555, "8554/tcp": 8554})
        if args.push:
            emu_docker.push()

        devices.append(emu_docker)

    return devices
예제 #5
0
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",
    )
예제 #6
0
def cloud_build(args):
    """Prepares the cloud build yaml and all its dependencies.

    The cloud builder will generate a single cloudbuild.yaml and generates the build
    scripts for every individual container.

    It will construct the proper dependencies as needed.
    """
    accept_licenses(True)

    mkdir_p(args.dest)
    image_zip = [args.img]

    # Check if we are building a custom image from a zip file
    if not os.path.exists(image_zip[0]):
        # We are using a standard image, we likely won't need to download it.
        image_zip = emu_downloads_menu.find_image(image_zip[0])

    emulator_zip = [args.emuzip]
    if emulator_zip[0] in ["stable", "canary", "all"]:
        emulator_zip = [
            x.download()
            for x in emu_downloads_menu.find_emulator(emulator_zip[0])
        ]
    elif re.match(r"\d+", emulator_zip[0]):
        # We must be looking for a build id
        logging.warning("Treating %s as a build id", emulator_zip[0])
        emulator_zip = [emu_downloads_menu.download_build(emulator_zip[0])]

    steps = []
    images = []
    emulators = set()
    emulator_images = []

    for (img, emu) in itertools.product(image_zip, emulator_zip):
        logging.info("Processing %s, %s", img, emu)
        system_container = SystemImageContainer(img, args.repo)
        if args.sys:
            steps.append(create_build_step(system_container, args.dest))
        else:
            for metrics in [True, False]:
                emulator_container = EmulatorContainer(emu, system_container,
                                                       args.repo, metrics)
                emulators.add(emulator_container.props["emu_build_id"])
                steps.append(create_build_step(emulator_container, args.dest))
                images.append(emulator_container.full_name())
                images.append(emulator_container.latest_name())
                emulator_images.append(emulator_container.full_name())
                emulator_images.append(emulator_container.latest_name())

    cloudbuild = {"steps": steps, "images": images, "timeout": "21600s"}
    logging.info("Writing cloud yaml [%s] in %s", yaml, args.dest)
    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 emulator_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": next(iter(images), None),
        },
        rename_as="REGISTRY.MD",
    )

    if args.git:
        git_commit_and_push(args.dest)
예제 #7
0
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)