diff --git a/src/oebuild/app/plugins/bitbake/in_container.py b/src/oebuild/app/plugins/bitbake/in_container.py index 37f103227b5cb49dec221a166e4167c975ed0074..65c452c3dea0051d25f85ff8a55833d129377fe5 100644 --- a/src/oebuild/app/plugins/bitbake/in_container.py +++ b/src/oebuild/app/plugins/bitbake/in_container.py @@ -279,11 +279,19 @@ class InContainer(BaseBuild): # read container default user .bashrc content content = self._get_bashrc_content(container=container) + # get host proxy information and set in container + init_proxy_command = "" + host_proxy = oebuild_util.get_host_proxy(oebuild_util.PROXY_LIST) + for key, value in host_proxy.items(): + key_git = key.replace('_', '.') + command = f'export {key}={value}; git config --global {key_git} {value};' + init_proxy_command = f'{init_proxy_command} {command}' + init_sdk_command = f'. {oebuild_util.NATIVESDK_DIR}/{oebuild_util.get_nativesdk_environment(container=container)}' set_template = f'export TEMPLATECONF="{oebuild_util.CONTAINER_SRC}/yocto-meta-openeuler/.oebuild"' init_oe_comand = f'. {oebuild_util.CONTAINER_SRC}/yocto-poky/oe-init-build-env \ {oebuild_util.CONTAINER_BUILD}/{build_dir_name}' - init_command = [init_sdk_command, set_template, init_oe_comand] + init_command = [init_proxy_command, init_sdk_command, set_template, init_oe_comand] new_content = self._init_bashrc_content(content, init_command) self.update_bashrc(container=container, content=new_content) diff --git a/src/oebuild/util.py b/src/oebuild/util.py index 748860b982a10ef419890b990bcd4a7c30dcb9a6..27a7d35033ef68c6e9cc805c0dba23006b46a6f6 100644 --- a/src/oebuild/util.py +++ b/src/oebuild/util.py @@ -17,6 +17,7 @@ import random import getpass import sys import re +import subprocess from ruamel.yaml import YAML from docker.errors import DockerException @@ -36,6 +37,7 @@ DEFAULT_DOCKER = "swr.cn-north-4.myhuaweicloud.com/openeuler-embedded/openeuler- CONTAINER_SRC = '/usr1/openeuler/src' CONTAINER_USER = "openeuler" NATIVESDK_DIR = "/opt/buildtools/nativesdk" +PROXY_LIST = ['http_proxy', 'https_proxy'] def get_nativesdk_environment(nativesdk_dir=NATIVESDK_DIR, container: Container = None): ''' @@ -219,3 +221,27 @@ def add_bashrc(content: str, line: str): content = content + line + BASH_END_FLAG + '\n' return content + +def get_host_proxy(proxy_name): + ''' + get proxy information from host + ''' + host_proxy = {} + if proxy_name is None: + return host_proxy + + for name in proxy_name: + command = "env | grep %s | awk -F'=' '{print$NF}'" % name + res = subprocess.run(command, + shell=True, + capture_output=True, + encoding="utf-8", + check=False) + if res.returncode != 0: + logger.error("get proxy variable failed") + sys.exit(res.returncode) + value = res.stdout.strip() + if value != "": + host_proxy[name] = value + + return host_proxy