Add KAS_PREMIRRORS support

Analogously to bitbake's PREMIRRORS, this allows to define alternative
sources for repo URLs specified in kas files.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Daniel Wagner <daniel.wagner@siemens.com>
This commit is contained in:
Jan Kiszka 2019-01-31 10:12:08 +01:00 committed by Daniel Wagner
parent dce5c0029a
commit 2f7650bb05
3 changed files with 22 additions and 3 deletions

View File

@ -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 |

View File

@ -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

View File

@ -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]