Exemple #1
0
def build_debs_from_sbuild(context: Context, series: str) -> List[str]:
    """Create a chroot and build the package using sbuild


    Will stop the development instance after deb build succeeds.

    :return: A list of paths to applicable deb files published.
    """
    deb_paths = []

    if context.config.debs_path:
        logging.info("--- Checking if debs can be reused in {}".format(
            context.config.debs_path))
        debs_path = context.config.debs_path
        if os.path.isdir(debs_path):
            deb_paths = [
                os.path.join(debs_path, deb_file)
                for deb_file in os.listdir(debs_path) if series in deb_file
            ]

    if len(deb_paths):
        logging.info("--- Reusing debs: {}".format(", ".join(deb_paths)))
    else:
        logging.info(
            "--- Could not find any debs to reuse. Building it locally")
        deb_paths = build_debs(
            series=series,
            cache_source=context.config.cache_source,
            chroot=context.config.sbuild_chroot,
        )

    if "pro" in context.config.machine_type:
        return deb_paths
    # Redact ubuntu-advantage-pro deb as inapplicable
    return [deb_path for deb_path in deb_paths if "pro" not in deb_path]
Exemple #2
0
def build_debs_from_dev_instance(context: Context, series: str) -> "List[str]":
    """Create a development instance, instal build dependencies and build debs


    Will stop the development instance after deb build succeeds.

    :return: A list of paths to applicable deb files published.
    """
    time_suffix = datetime.datetime.now().strftime("%s%f")
    debs_path = get_debs_path_from_series(series, context)
    if debs_path:
        if os.path.isdir(debs_path):
            deb_paths = [
                os.path.join(debs_path, deb_file)
                for deb_file in os.listdir(debs_path)
            ]
    else:
        print(
            "--- Launching vm to build ubuntu-advantage*debs from local source"
        )
        if context.config.cloud_manager:
            cloud_manager = context.config.cloud_manager
            inst = cloud_manager.launch(
                series=series, user_data=USERDATA_INSTALL_DAILY_PRO_UATOOLS)

            def cleanup_instance() -> None:
                if not context.config.destroy_instances:
                    print("--- Leaving instance running: {}".format(inst.id))
                else:
                    inst.delete(wait=False)

            build_container_name = cloud_manager.get_instance_id(inst)
        else:
            build_container_name = ("behave-image-pre-build-%s-" % series +
                                    time_suffix)
            is_vm = bool(context.config.machine_type == "lxd.vm")
            if is_vm and series == "xenial":
                # FIXME: use lxd custom cloud images which containt HWE kernel
                # for vhost-vsock support
                lxc_ubuntu_series = "images:ubuntu/16.04/cloud"
            else:
                lxc_ubuntu_series = "ubuntu-daily:%s" % series
            launch_lxd_container(
                context,
                series=series,
                image_name=lxc_ubuntu_series,
                container_name=build_container_name,
                is_vm=is_vm,
            )
        with emit_spinner_on_travis("Building debs from local source... "):
            deb_paths = build_debs(
                build_container_name,
                output_deb_dir=LOCAL_BUILD_ARTIFACTS_DIR,
                cloud_api=context.config.cloud_api,
            )

    if "pro" in context.config.machine_type:
        return deb_paths
    # Redact ubuntu-advantage-pro deb as inapplicable
    return [deb_path for deb_path in deb_paths if "pro" not in deb_path]
Exemple #3
0
def main(series=None, chroot=None):
    logging.basicConfig()
    logging.getLogger().setLevel(logging.INFO)
    print(
        json.dumps({
            "state_hash": repo_state_hash(),
            "debs": build_debs(series, chroot=chroot),
        }))
Exemple #4
0
def build_debs_from_dev_instance(context: Context, series: str) -> "List[str]":
    """Create a development instance, instal build dependencies and build debs


    Will stop the development instance after deb build succeeds.

    :return: A list of paths to applicable deb files published.
    """
    time_suffix = datetime.datetime.now().strftime("%s%f")
    deb_paths = []

    print("--- Checking if debs can be reused")
    if context.config.debs_path:
        debs_path = context.config.debs_path
        if os.path.isdir(debs_path):
            deb_paths = [
                os.path.join(debs_path, deb_file)
                for deb_file in os.listdir(debs_path) if series in deb_file
            ]

    if len(deb_paths):
        print("--- Reusing debs")
    else:
        print("--- Could not find any debs to reuse. Building it locally")
        print(
            "--- Launching vm to build ubuntu-advantage*debs from local source"
        )
        build_container_name = ("ubuntu-behave-image-pre-build-%s-" % series +
                                time_suffix)

        cloud_manager = context.config.cloud_manager
        if "pro" in context.config.machine_type:
            user_data = USERDATA_BLOCK_AUTO_ATTACH
        else:
            user_data = ""
        inst = cloud_manager.launch(
            instance_name=build_container_name,
            series=series,
            user_data=user_data,
        )

        build_container_name = cloud_manager.get_instance_id(inst)

        with emit_spinner_on_travis("Building debs from local source... "):
            deb_paths = build_debs(
                build_container_name,
                output_deb_dir=LOCAL_BUILD_ARTIFACTS_DIR,
                cloud_api=context.config.cloud_api,
            )

    if "pro" in context.config.machine_type:
        return deb_paths
    # Redact ubuntu-advantage-pro deb as inapplicable
    return [deb_path for deb_path in deb_paths if "pro" not in deb_path]