Beispiel #1
0
def _print_status(lp: LaunchpadClient):
    if lp.has_outstanding_build():
        build_status = lp.get_build_status()
        for arch, status in build_status.items():
            echo.info(f"Build status for arch {arch}: {status}")
    else:
        echo.info("No build found.")
Beispiel #2
0
def remote_build(
    recover: bool,
    status: bool,
    build_on: str,
    launchpad_accept_public_upload: bool,
    launchpad_timeout: int,
    package_all_sources: bool,
    echoer=echo,
) -> None:
    """Dispatch a snap for remote build.

    Command remote-build sends the current project to be built remotely. After the build
    is complete, packages for each architecture are retrieved and will be available in
    the local filesystem.

    If not specified in the snapcraft.yaml file, the list of architectures to build
    can be set using the --build-on option. If both are specified, an error will occur.

    Interrupted remote builds can be resumed using the --recover option, followed by
    the build number informed when the remote build was originally dispatched. The
    current state of the remote build for each architecture can be checked using the
    --status option.

    \b
    Examples:
        snapcraft remote-build
        snapcraft remote-build --build-on=amd64
        snapcraft remote-build --build-on=amd64,arm64,armhf,i386,ppc64el,s390x
        snapcraft remote-build --recover
        snapcraft remote-build --status
    """
    if not launchpad_accept_public_upload:
        raise errors.AcceptPublicUploadError()

    echo.warning(
        "snapcraft remote-build is experimental and is subject to change - use with caution."
    )

    project = get_project()

    # TODO: use project.is_legacy() when available.
    base = project.info.get_build_base()
    if base is None:
        raise errors.BaseRequiredError()

    # Use a hash of current working directory to distinguish between other
    # potential project builds occurring in parallel elsewhere.
    project_hash = project._get_project_directory_hash()
    build_id = f"snapcraft-{project.info.name}-{project_hash}"
    architectures = _determine_architectures(project, build_on)

    # Calculate timeout timestamp, if specified.
    if launchpad_timeout > 0:
        deadline = int(time.time()) + launchpad_timeout
    else:
        deadline = 0

    lp = LaunchpadClient(
        project=project,
        build_id=build_id,
        architectures=architectures,
        deadline=deadline,
    )

    if status:
        _print_status(lp)
        return

    if lp.has_outstanding_build():
        echo.info("Found previously started build.")
        _print_status(lp)

        # If recovery specified, monitor build and exit.
        if recover or echo.confirm("Do you wish to recover this build?",
                                   default=True):
            _monitor_build(lp)
            return

        # Otherwise clean running build before we start a new one.
        _clean_build(lp)

    _start_build(
        lp=lp,
        project=project,
        build_id=build_id,
        package_all_sources=package_all_sources,
    )

    _monitor_build(lp)
Beispiel #3
0
def remote_build(
    recover: bool,
    status: bool,
    build_on: str,
    build_id: str,
    launchpad_accept_public_upload: bool,
    launchpad_timeout: int,
    package_all_sources: bool,
    echoer=echo,
) -> None:
    """Dispatch a snap for remote build.

    Command remote-build sends the current project to be built remotely. After the build
    is complete, packages for each architecture are retrieved and will be available in
    the local filesystem.

    If not specified in the snapcraft.yaml file, the list of architectures to build
    can be set using the --build-on option. If both are specified, an error will occur.

    Interrupted remote builds can be resumed using the --recover option, followed by
    the build number informed when the remote build was originally dispatched. The
    current state of the remote build for each architecture can be checked using the
    --status option.

    \b
    Examples:
        snapcraft remote-build
        snapcraft remote-build --build-on=amd64
        snapcraft remote-build --build-on=amd64,arm64,armhf,i386,ppc64el,s390x
        snapcraft remote-build --recover
        snapcraft remote-build --recover --build-id snapcraft-my-snap-b98a6bd3
        snapcraft remote-build --status
        snapcraft remote-build --status --build-id snapcraft-my-snap-b98a6bd3
    """
    if os.getenv("SUDO_USER") and os.geteuid() == 0:
        echo.warning(
            "Running with 'sudo' may cause permission errors and is discouraged."
        )

    echo.warning(
        "snapcraft remote-build is experimental and is subject to change - use with caution."
    )

    project = get_project()

    try:
        project._get_build_base()
    except RuntimeError:
        raise errors.BaseRequiredError()

    if not build_id:
        # If the option wasn't provided, use the project directory hash
        # to create one unique to the status of the working tree, allowing
        # us to distinguish between multiple builds for this project
        # (and others).
        project_hash = project._get_project_directory_hash()
        build_id = f"snapcraft-{project.info.name}-{project_hash}"

    echo.info(f"Using build ID {build_id}")
    architectures = _determine_architectures(project, build_on)

    # Calculate timeout timestamp, if specified.
    if launchpad_timeout > 0:
        deadline = int(time.time()) + launchpad_timeout
    else:
        deadline = 0

    lp = LaunchpadClient(
        project=project,
        build_id=build_id,
        architectures=architectures,
        deadline=deadline,
    )

    if status:
        _print_status(lp)
        return

    has_outstanding_build = lp.has_outstanding_build()
    if recover and not has_outstanding_build:
        echo.info("No build found.")
        return
    elif has_outstanding_build:
        echo.info("Found previously started build.")
        _print_status(lp)

        # If recovery specified, monitor build and exit.
        if recover or echo.confirm("Do you wish to recover this build?",
                                   default=True):
            _monitor_build(lp)
            return

        # Otherwise clean running build before we start a new one.
        _clean_build(lp)

    _check_launchpad_acceptance(launchpad_accept_public_upload)

    _start_build(
        lp=lp,
        project=project,
        build_id=build_id,
        package_all_sources=package_all_sources,
    )

    _monitor_build(lp)