From e024dd2bebfde57e5f49a51f553cafa7d8bbbe02 Mon Sep 17 00:00:00 2001 From: hmilylmk Date: Tue, 4 Jul 2023 11:18:57 +0800 Subject: [PATCH] oebuild: add host proxy to docker * get the shell proxy value from host env, and set these proxy to shell and git in docker. http and https is enough. Signed-off-by: hmilylmk --- src/oebuild/app/plugins/bitbake/bitbake.py | 4 +++- src/oebuild/app/plugins/bitbake/in_container.py | 11 +++++++++-- src/oebuild/util.py | 15 +++++++++++++++ src/oebuild/version.py | 2 +- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/oebuild/app/plugins/bitbake/bitbake.py b/src/oebuild/app/plugins/bitbake/bitbake.py index e9fc707..6981e26 100644 --- a/src/oebuild/app/plugins/bitbake/bitbake.py +++ b/src/oebuild/app/plugins/bitbake/bitbake.py @@ -19,6 +19,7 @@ from oebuild.configure import Configure from oebuild.parse_compile import ParseCompile, CheckCompileError from oebuild.parse_env import ParseEnv import oebuild.util as oebuild_util +from oebuild.util import PROXY_LIST from oebuild.app.plugins.bitbake.in_container import InContainer from oebuild.app.plugins.bitbake.in_host import InHost from oebuild.parse_template import BUILD_IN_HOST @@ -101,7 +102,8 @@ class Bitbake(OebuildCommand): except DockerException as d_e: logger.error(str(d_e)) return - in_container = InContainer(self.configure) + host_proxy = oebuild_util.get_host_proxy(PROXY_LIST) + in_container = InContainer(self.configure, host_proxy) in_container.exec(parse_env=parse_env, parse_compile=parse_compile, command=command) diff --git a/src/oebuild/app/plugins/bitbake/in_container.py b/src/oebuild/app/plugins/bitbake/in_container.py index d497d7c..db2392c 100644 --- a/src/oebuild/app/plugins/bitbake/in_container.py +++ b/src/oebuild/app/plugins/bitbake/in_container.py @@ -29,9 +29,10 @@ class InContainer(BaseBuild): bitbake command execute in container ''' - def __init__(self, configure: Configure): + def __init__(self, configure: Configure, host_proxy): self.configure = configure self.client = DockerProxy() + self.host_proxy = host_proxy self.container_id = None def __del__(self): @@ -292,7 +293,13 @@ class InContainer(BaseBuild): set_template = f'export TEMPLATECONF="{bitbake_const.CONTAINER_SRC}/yocto-meta-openeuler/.oebuild"' init_oe_comand = f'. {bitbake_const.CONTAINER_SRC}/yocto-poky/oe-init-build-env \ {bitbake_const.CONTAINER_BUILD}/{build_dir}' - init_command = [init_sdk_command, set_template, init_oe_comand] + + init_proxy_command = "" + for key, value in self.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_command = [init_sdk_command, set_template, init_oe_comand, init_proxy_command] 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 5378b3e..2032536 100644 --- a/src/oebuild/util.py +++ b/src/oebuild/util.py @@ -15,6 +15,7 @@ import os import time import random import getpass +import subprocess from ruamel.yaml import YAML from docker.errors import DockerException @@ -25,6 +26,7 @@ from oebuild.version import __version__ CONFIG_YAML = 'config.yaml' UPGRADE_YAML = 'upgrade.yaml' COMPILE_YAML = 'compile.yaml.sample' +PROXY_LIST = ['http_proxy', 'https_proxy'] def read_yaml(yaml_dir : pathlib.Path): ''' @@ -138,3 +140,16 @@ def get_instance(factory): Instantiate a class ''' return factory() + +def get_host_proxy(proxy_name): + host_proxy = {} + if proxy_name is None: + return host_proxy + + for name in proxy_name: + command = "env | grep %s | awk -F'=' '{print$NF}'" % name + value = subprocess.run(command, shell=True, capture_output=True).stdout.decode().strip() + if value != "": + host_proxy[name] = value + + return host_proxy diff --git a/src/oebuild/version.py b/src/oebuild/version.py index d705e18..c1c1845 100644 --- a/src/oebuild/version.py +++ b/src/oebuild/version.py @@ -10,4 +10,4 @@ MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. See the Mulan PSL v2 for more details. ''' -__version__ = '0.0.26' +__version__ = '0.0.28' -- Gitee