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:
		
				
					committed by
					
						
						Daniel Wagner
					
				
			
			
				
	
			
			
			
						parent
						
							dce5c0029a
						
					
				
				
					commit
					2f7650bb05
				
			@@ -77,6 +77,13 @@ Environment variables
 | 
				
			|||||||
| ``KAS_TARGET``        |                                                     |
 | 
					| ``KAS_TARGET``        |                                                     |
 | 
				
			||||||
| ``KAS_TASK``          |                                                     |
 | 
					| ``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   |
 | 
					| ``SSH_PRIVATE_KEY``   | Path to the private key file that should be added   |
 | 
				
			||||||
|                       | to an internal ssh-agent. This key cannot be        |
 | 
					|                       | to an internal ssh-agent. This key cannot be        |
 | 
				
			||||||
|                       | password protected. This setting is useful for CI   |
 | 
					|                       | password protected. This setting is useful for CI   |
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -213,7 +213,8 @@ fi
 | 
				
			|||||||
set -- ${DOCKER_ARGS}
 | 
					set -- ${DOCKER_ARGS}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
for var in SHELL TERM KAS_DISTRO KAS_MACHINE KAS_TARGET KAS_TASK \
 | 
					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
 | 
						if [ -n "$(eval echo \$${var})" ]; then
 | 
				
			||||||
		set -- "$@" -e "${var}='$(eval echo \"\$${var}\")'"
 | 
							set -- "$@" -e "${var}='$(eval echo \"\$${var}\")'"
 | 
				
			||||||
	fi
 | 
						fi
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										15
									
								
								kas/repos.py
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								kas/repos.py
									
									
									
									
									
								
							@@ -23,6 +23,7 @@
 | 
				
			|||||||
    This module contains the Repo class.
 | 
					    This module contains the Repo class.
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import re
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import asyncio
 | 
					import asyncio
 | 
				
			||||||
import logging
 | 
					import logging
 | 
				
			||||||
@@ -62,6 +63,16 @@ class Repo:
 | 
				
			|||||||
                    .replace(':', '.')
 | 
					                    .replace(':', '.')
 | 
				
			||||||
                    .replace('/', '.')
 | 
					                    .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
 | 
					        # Default behaviour
 | 
				
			||||||
        raise AttributeError
 | 
					        raise AttributeError
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -273,7 +284,7 @@ class GitRepo(RepoImpl):
 | 
				
			|||||||
    """
 | 
					    """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def clone_cmd(self, gitsrcdir):
 | 
					    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):
 | 
					        if get_context().kas_repo_ref_dir and os.path.exists(gitsrcdir):
 | 
				
			||||||
            cmd.extend(['--reference', gitsrcdir])
 | 
					            cmd.extend(['--reference', gitsrcdir])
 | 
				
			||||||
        return cmd
 | 
					        return cmd
 | 
				
			||||||
@@ -308,7 +319,7 @@ class MercurialRepo(RepoImpl):
 | 
				
			|||||||
    """
 | 
					    """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def clone_cmd(self, gitsrcdir, config):
 | 
					    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):
 | 
					    def contains_refspec_cmd(self):
 | 
				
			||||||
        return ['hg', 'log', '-r', self.refspec]
 | 
					        return ['hg', 'log', '-r', self.refspec]
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user