From d72a5be3046d9031459f92d8e7a2a1cf45a6ad88 Mon Sep 17 00:00:00 2001 From: yyjeqhc Date: Tue, 24 Jun 2025 12:48:27 +0800 Subject: [PATCH] feat:add select local image to build package. --- 0002-feat_add_select_local_image.patch | 137 +++++++++++++++++++++++++ ccb.spec | 7 +- 2 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 0002-feat_add_select_local_image.patch diff --git a/0002-feat_add_select_local_image.patch b/0002-feat_add_select_local_image.patch new file mode 100644 index 0000000..82a8ee6 --- /dev/null +++ b/0002-feat_add_select_local_image.patch @@ -0,0 +1,137 @@ +diff --git a/sbin/cli/local-build b/sbin/cli/local-build +index 7b484e8..b9bf330 100755 +--- a/sbin/cli/local-build ++++ b/sbin/cli/local-build +@@ -15,6 +15,7 @@ require "#{LKP_SRC}/sbin/cli/ccb_api_client" + debug_flag = false + debug_stage = nil + clean_flag = false ++local_image = nil + config_hash = {} + dailybuild_hash = {"local" => "http://172.16.1.236:31744", + "remote" => "http://121.36.84.172"} +@@ -25,6 +26,8 @@ options = OptionParser.new do |opts| + + opts.separator ' eg.1: ccb local-build os_project=openEuler:Mainline package=gcc --rm --debug=bp' + opts.separator ' eg.2: ccb local-build os_project=openEuler:Mainline package=gcc spec=gcc.spec --rm --debug=bp' ++ opts.separator ' eg.3: ccb local-build os_project=openEuler:Mainline package=gcc --local-image openeuler:22.03' ++ opts.separator ' eg.4: ccb local-build os_project=openEuler:Mainline package=gcc arch=riscv64' + opts.separator '' + opts.separator 'options:' + +@@ -37,6 +40,10 @@ options = OptionParser.new do |opts| + debug_stage = debug + end + ++ opts.on('--local-image IMAGE', 'use existing local docker image (e.g., openeuler:22.03)') do |image| ++ local_image = image ++ end ++ + opts.on('-h', '--help', 'show this message') do + puts options + exit +@@ -64,8 +71,8 @@ begin + info = arg.split('=', 2) + key = info[0] + value = info[1] || '' +- if need_keys.include?(key) +- if value.length == 0 ++ if need_keys.include?(key) || key == 'arch' ++ if value.length == 0 && key != 'arch' + puts options + puts "\n[ERROR] The parameter: #{key} requires a value" + exit +@@ -364,7 +371,10 @@ def download_docker_image(config_hash, dailybuild_hash) + image_url = "#{dailybuild_hash['remote']}/EulerMaker/#{config_hash['branch']}/docker_img/#{config_hash['arch']}/#{image_name}" + puts "[INFO] Download docker image, please wait" + %x(wget #{image_url} -P #{config_hash['output_dir']} -q --show-progress) +- image_id=%x(docker load -i #{config_hash['output_dir']}/#{image_name} | awk -F':' '{print $NF}') ++ load_output = %x(docker load -i #{config_hash['output_dir']}/#{image_name} 2>&1).strip ++ if load_output =~ /Loaded image ID:\s*sha256:([a-f0-9]{64})/i ++ image_id = $1 ++ end + %x(rm -f #{config_hash['output_dir']}/#{image_name}) + if image_id.nil? + puts "[ERROR] Docker load failed" +@@ -376,7 +386,10 @@ end + def build_package(image_id, clean_flag, config_hash) + container_name = "local-build-#{config_hash["package"]}" + %x(docker rm -f #{container_name} &>/dev/null) +- system("docker run -itd --net=host --name #{container_name} #{image_id} /bin/bash -c 'exit'") ++ ++ puts "[INFO] Start building arch: #{config_hash["arch"]}" ++ system("docker run -itd --platform=#{config_hash["arch"]} --net=host --name #{container_name} #{image_id} bash") ++ + exec_result=$?.exitstatus + if exec_result != 0 + puts "[ERROR] Run a container failed" +@@ -415,6 +428,14 @@ def build_package(image_id, clean_flag, config_hash) + end + end + ++def get_build_image(local_image) ++ full_hash = %x(docker inspect #{local_image} --format "{{.Id}}" 2>/dev/null).strip ++ if full_hash.empty? ++ puts "[ERROR] Docker image '#{local_image}' not found locally" ++ exit 1 ++ end ++ return full_hash.gsub(/^sha256:/, '') ++end + + os_project = config_hash['os_project'] || '' + package = config_hash['package'] || '' +@@ -455,7 +476,7 @@ else + end + + arch = RbConfig::CONFIG['arch'].split('-')[0] +-config_hash["arch"] = arch ++config_hash["arch"] = config_hash['arch'].nil? || config_hash['arch'].empty? ? arch : config_hash['arch'] + config_hash['LKP_SRC'] = "/lkp-tests" + config_hash["build_user"] = "lkp" + config_hash['output_dir'] = "/tmp/#{os_project}/#{package}" +@@ -468,5 +489,9 @@ result = search_builds_info(os_project, arch, my_config) + projects_info = get_projects_data(os_project, my_config, config_hash) + repo_array = construct_repo_url(projects_info, config_hash, dailybuild_hash) + write_config_file(config_hash, repo_array) +-image_id = download_docker_image(config_hash, dailybuild_hash) ++if local_image.nil? ++ image_id = download_docker_image(config_hash, dailybuild_hash) ++else ++ image_id = get_build_image(local_image) ++end + build_package(image_id, clean_flag, config_hash) +diff --git a/tests/local-rpmbuild b/tests/local-rpmbuild +index fe8656f..1f0d2fc 100755 +--- a/tests/local-rpmbuild ++++ b/tests/local-rpmbuild +@@ -228,6 +228,20 @@ find_spec_file() + + check_specfile_exist() + { ++ has_lan_ip_repo=false ++ for file in /etc/yum.repos.d/*.repo; do ++ if grep -Eo 'https?://(10\.[0-9]+\.[0-9]+\.[0-9]+|172\.(1[6-9]|2[0-9]|3[0-1])\.[0-9]+\.[0-9]+|192\.168\.[0-9]+\.[0-9]+)' "$file" > /dev/null; then ++ has_lan_ip_repo=true ++ break ++ fi ++ done ++ ++ if [ "$has_lan_ip_repo" = false ]; then ++ dnf install -y git dnf-utils ++ dnf install -y git-lfs || true ++ else ++ echo "repo with LAN IP found, skipping git-lfs installation" ++ fi + git config --global http.lowSpeedLimit 0 + git config --global http.lowSpeedTime 3600 + git config --global lfs.activitytimeout 3600 +@@ -309,7 +323,7 @@ git_lfs_clone() + if [[ "${i}" -gt 1 ]];then + sleep 3 + fi +- git lfs clone ${1} -b ${2} --depth=1 2>/dev/null || continue ++ git lfs clone ${1} -b ${2} --depth=1 2>/dev/null|| git clone ${1} -b ${2} --depth=1 2>/dev/null || continue + return 0 + done + return 1 + diff --git a/ccb.spec b/ccb.spec index 210b061..d164e5d 100755 --- a/ccb.spec +++ b/ccb.spec @@ -2,7 +2,7 @@ Name: ccb Version: 1.0.1 -Release: 4 +Release: 5 Summary: ccb is a client-side tool for EulerMaker License: MulanPSL-2.0 URL: https://gitee.com/openeuler/ccb @@ -10,6 +10,7 @@ Source0: %{name}-%{version}.tar.gz BuildArch: noarch Patch1: 0001-Bugfix-ccb-log-error-url.patch +Patch2: 0002-feat_add_select_local_image.patch BuildRequires: ruby BuildRequires: rubygems @@ -71,6 +72,10 @@ fi %license LICENSE %changelog +* Tue Jun 24 2025 yyjeqhc - 1.0.1-5 +- Add select local image to build. +- Add support for setting target architecture during local builds. + * Thu Jun 05 2025 lulingyu - 1.0.1-4 - Added runtime dependency on wget for download functionality -- Gitee