diff --git a/docs/userguide.rst b/docs/userguide.rst index f4c6c7e..403d866 100644 --- a/docs/userguide.rst +++ b/docs/userguide.rst @@ -77,6 +77,13 @@ Environment variables | ``KAS_TARGET`` | | | ``KAS_TASK`` | | +-----------------------+-----------------------------------------------------+ +| ``KAS_PREMIRRORS`` | Specifies alternatives for repo URLs. Just like | +| | bitbake ``PREMIRRORS``, this variable consists of | +| | new-line separated entries. Each entry defines a | +| | regular expression to match a URL and, space- | +| | separated, its replacement. E.g.: | +| | "https://.*\.somehost\.io/ https://localmirror.net/"| ++-----------------------+-----------------------------------------------------+ | ``SSH_PRIVATE_KEY`` | Path to the private key file that should be added | | | to an internal ssh-agent. This key cannot be | | | password protected. This setting is useful for CI | diff --git a/kas-docker b/kas-docker index 993b2eb..56ad506 100755 --- a/kas-docker +++ b/kas-docker @@ -213,7 +213,8 @@ fi set -- ${DOCKER_ARGS} for var in SHELL TERM KAS_DISTRO KAS_MACHINE KAS_TARGET KAS_TASK \ - http_proxy https_proxy ftp_proxy no_proxy NO_PROXY; do + http_proxy https_proxy ftp_proxy no_proxy NO_PROXY \ + KAS_PREMIRRORS; do if [ -n "$(eval echo \$${var})" ]; then set -- "$@" -e "${var}='$(eval echo \"\$${var}\")'" fi diff --git a/kas/repos.py b/kas/repos.py index add94dc..0596520 100644 --- a/kas/repos.py +++ b/kas/repos.py @@ -23,6 +23,7 @@ This module contains the Repo class. """ +import re import os import asyncio import logging @@ -62,6 +63,16 @@ class Repo: .replace(':', '.') .replace('/', '.') .replace('*', '.')) + elif item == 'effective_url': + mirrors = os.environ.get('KAS_PREMIRRORS', '') + for mirror in mirrors.split('\n'): + try: + expr, subst = mirror.split() + if re.match(expr, self.url): + return re.sub(expr, subst, self.url) + except ValueError: + continue + return self.url # Default behaviour raise AttributeError @@ -273,7 +284,7 @@ class GitRepo(RepoImpl): """ def clone_cmd(self, gitsrcdir): - cmd = ['git', 'clone', '-q', self.url, self.path] + cmd = ['git', 'clone', '-q', self.effective_url, self.path] if get_context().kas_repo_ref_dir and os.path.exists(gitsrcdir): cmd.extend(['--reference', gitsrcdir]) return cmd @@ -308,7 +319,7 @@ class MercurialRepo(RepoImpl): """ def clone_cmd(self, gitsrcdir, config): - return ['hg', 'clone', self.url, self.path] + return ['hg', 'clone', self.effective_url, self.path] def contains_refspec_cmd(self): return ['hg', 'log', '-r', self.refspec]