Ejemplo n.º 1
0
def _process_site_repository(repo_url_or_path, repo_revision):
    """Process the primary or site repository located at ``repo_url_or_path``.

    Also validate that the provided ``repo_url_or_path`` is a valid Git
    repository. If ``repo_url_or_path`` doesn't already exist, clone it.
    If it does, extract the appropriate revision and check it out.

    :param repo_url_or_path: Repo path or URL and associated auth information.
        If URL, examples include:

        * ssh://REPO_USERNAME@<GIT_URL>:29418/global-manifests.git@<ref>
        * https://<GIT_URL>/global-manifests.git@<ref>
        * http://<GIT_URL>/global-manifests.git@<ref>
        * <LOCAL_REPO_PATH>@<ref>
        * same values as above without @<ref>
    :param str repo_revision: branch, commit or ref in the repo to checkout.

    """

    repo_alias = 'site'  # We are processing the site repo necessarily.
    repo_key = config.get_repo_key()
    repo_user = config.get_repo_username()

    LOG.info(
        "Processing repository %s with url=%s, repo_key=%s, "
        "repo_username=%s, revision=%s", repo_alias, repo_url_or_path,
        repo_key, repo_user, repo_revision)
    return _handle_repository(repo_url_or_path,
                              ref=repo_revision,
                              auth_key=repo_key)
Ejemplo n.º 2
0
def _format_url_with_repo_username(repo_url_or_path):
    # If a repo user is provided, do the necessary replacements.
    repo_user = config.get_repo_username()
    if repo_user:
        if "REPO_USERNAME" not in repo_url_or_path:
            LOG.warning(
                "A repository username was specified but no REPO_USERNAME "
                "string found in repository url %s", repo_url_or_path)
        else:
            repo_url_or_path = repo_url_or_path.replace(
                'REPO_USERNAME', repo_user)
    return repo_url_or_path
Ejemplo n.º 3
0
def process_repositories(site_name):
    """Process and setup all repositories including ensuring we are at the
    right revision based on the site's own site-definition.yaml file.

    :param site_name: Site name for which to clone relevant repos.

    """

    # Only tracks extra repositories - not the site (primary) repository.
    extra_repos = []

    site_repo = process_site_repository()

    # Retrieve extra repo data from site-definition.yaml files.
    site_data = util.definition.load_as_params(site_name,
                                               primary_repo_base=site_repo)
    site_def_repos = _get_and_validate_site_repositories(site_name, site_data)

    # Dict mapping repository names to associated URL/revision info for clone.
    repo_overrides = _process_repository_overrides(site_def_repos)
    if not site_def_repos:
        LOG.info(
            'No repositories found in site-definition.yaml for site: %s. '
            'Defaulting to specified repository overrides.', site_name)
        site_def_repos = repo_overrides

    # Extract user/key that we will use for all repositories.
    repo_key = config.get_repo_key()
    repo_user = config.get_repo_username()

    for repo_alias in site_def_repos.keys():
        if repo_alias == "site":
            LOG.warning(
                "The primary site repository path must be specified "
                "via the -r flag. Ignoring the provided "
                "site-definition entry: %s", site_def_repos[repo_alias])
            continue

        # Extract URL and revision, prioritizing overrides over the defaults in
        # the site-definition.yaml.
        if repo_alias in repo_overrides:
            repo_url_or_path = repo_overrides[repo_alias]['url']
            repo_revision = repo_overrides[repo_alias]['revision']
        else:
            repo_url_or_path = site_def_repos[repo_alias]['url']
            repo_revision = site_def_repos[repo_alias]['revision']

        repo_url_or_path = _format_url_with_repo_username(repo_url_or_path)

        LOG.info(
            "Processing repository %s with url=%s, repo_key=%s, "
            "repo_username=%s, revision=%s", repo_alias, repo_url_or_path,
            repo_key, repo_user, repo_revision)

        temp_extra_repo = _process_repository(repo_url_or_path, repo_revision)
        extra_repos.append(temp_extra_repo)

    # Overwrite the site repo and extra repos in the config because further
    # processing will fail if they contain revision info in their paths.
    LOG.debug("Updating site_repo=%s extra_repo_list=%s in config", site_repo,
              extra_repos)
    config.set_site_repo(site_repo)
    config.set_extra_repo_list(extra_repos)