From 275437138d1246da57ceb7933c88c3223f09317b Mon Sep 17 00:00:00 2001 From: wangchong1995924 <15229716099@163.com> Date: Tue, 7 Nov 2023 15:48:23 +0800 Subject: [PATCH] [update] docker image release --- script/tools/chroot_libs.sh | 79 +++++++++++++++++++++ script/tools/docker_image_update.sh | 106 +++++++++++++--------------- script/tools/make_docker.sh | 76 ++++++++++++++++++++ 3 files changed, 205 insertions(+), 56 deletions(-) create mode 100644 script/tools/chroot_libs.sh create mode 100644 script/tools/make_docker.sh diff --git a/script/tools/chroot_libs.sh b/script/tools/chroot_libs.sh new file mode 100644 index 0000000..3b1fe8e --- /dev/null +++ b/script/tools/chroot_libs.sh @@ -0,0 +1,79 @@ +#!/bin/bash +# yum_conf + +function chroot_init() +{ + root_path="/usr1/openeuler" + if [ -d ${root_path} ];then + rm -rf ${root_path} + fi + mkdir -p ${root_path} + + yum install lsof -y + yum install -c ${yum_conf} --installroot=${root_path} -y pigz expect wget bash \ + vim grep patch tar gzip bzip2 openssh-clients yum perl createrepo_c \ + dnf-utils git -x glibc32 + + mkdir -m 755 -p ${root_path}/dev/pts + test -d ${root_path}/dev/shm || rm -f ${root_path}/dev/shm + mkdir -m 755 -p ${root_path}/dev/shm + mount --bind /dev ${root_path}/dev/ + while read com file mode arg + do + rm -f ${root_path}/dev/$file + if [[ $com = ln ]];then + ln -s $arg ${root_path}/dev/$file + continue + fi + $com -m $mode ${root_path}/dev/$file $arg + done << DEVLIST + mknod null 666 c 1 3 + mknod zero 666 c 1 5 + mknod full 622 c 1 7 + mknod random 666 c 1 8 + mknod urandom 644 c 1 9 + mknod tty 666 c 5 0 + mknod ptmx 666 c 5 2 + mknod loop-control 600 c 10 237 + mknod loop0 640 b 7 0 + mknod loop1 640 b 7 1 + mknod loop2 640 b 7 2 + mknod loop3 640 b 7 3 + ln fd 777 /proc/self/fd + ln stdin 777 fd/0 + ln stdout 777 fd/1 + ln stderr 777 fd/2 +DEVLIST + + mount -n -tdevpts -omode=0620,gid=5 none ${root_path}/dev/pts + mkdir -p ${root_path}/proc ${root_path}/sys + mount --bind /sys ${root_path}/sys + mount --bind /proc ${root_path}/proc + + cp make_docker.sh "${root_path}/home/" + cp "/etc/resolv.conf" "${root_path}/etc/" + rm -f "${root_path}/etc/yum.repos.d"/* + cp "${yum_conf}" "${root_path}/etc/yum.repos.d/" +} + +function chroot_clean() +{ + if [ -d "${root_path}" ];then + for openeuler_pid in $(lsof | grep "${root_path}" | awk '{print $2}') + do + kill -9 "${openeuler_pid}" + done + umount -f "${root_path}/proc" + umount -f "${root_path}/sys" + umount -f "${root_path}/dev/pts" + umount -f "${root_path}/dev" + rm -rf ${root_path} + fi +} + +function chroot_run() +{ + chroot_init + chroot "${root_path}" /bin/bash --login -c "$@" + chroot_clean +} diff --git a/script/tools/docker_image_update.sh b/script/tools/docker_image_update.sh index 7090ed1..3282a91 100644 --- a/script/tools/docker_image_update.sh +++ b/script/tools/docker_image_update.sh @@ -2,22 +2,20 @@ # -------------------------------------------------------------------------------------------------------------------- # Author: # Copyright Huawei Technologies Co., Ltd. 2010-2018. All rights reserved. -# Decription: Create an UPDATE directory to add, delete, update, check and publish package binaries # -------------------------------------------------------------------------------------------------------------------- - +. chroot_libs.sh # usage function usage() { cat << EOF -Usage: sh docker_image_update.sh [Operation] [Branch] [Openeuler_dir] [Update_dir] [Source_ip] [Release_ip] [Publish_key] +Usage: bash docker_image_update.sh [Operation] [Branch] [Update_dir] [Source_ip] [Release_ip] [Publish_key] optional arguments: - Operation Operation method, include: create, update, delete_update_dir and release + Operation Operation method, include: create, delete_update_dir and release Branch Branch name, such as: openEuler-22.03-LTS - Openeuler_dir build directory start with openeuler- on the dailybuild server Update_dir Update directory name - Source_ip Server of store hotpatch - Release_ip Server of release hotpatch + Source_ip Server of source + Release_ip Server of release Publish_key Server of publish key EOF } @@ -76,18 +74,46 @@ function update_json_file() { fi } -# create update directory and add docker image -function create() { - echo "add docker image into the ${update_dir} directory." - for ar in ${arch_list[@]} +function config_repo() +{ + rm -rf /etc/yum.repos.d.bak + mv /etc/yum.repos.d /etc/yum.repos.d.bak + mkdir -p /etc/yum.repos.d + export yum_conf="/etc/yum.repos.d/my.repo" + touch ${yum_conf} + i=1 + for repo in ${repo_url[@]} do - cmd="if [ ! -d ${update_path}/${ar} ];then mkdir -p ${update_path}/${ar};fi" - ssh_cmd ${source_ip} "${cmd}" - cmd="cp ${source_img_dir}/${ar}/openEuler-docker.${ar}.tar.xz ${update_path}/${ar}/" - ssh_cmd ${source_ip} "${cmd}" - cmd="cp ${source_img_dir}/${ar}/openEuler-docker.${ar}.tar.xz.sha256sum ${update_path}/${ar}/" - ssh_cmd ${source_ip} "${cmd}" + cat >> ${yum_conf} <<-EOF + [repo_$i] + name=repo_$i + baseurl=${repo} + enabled=1 + gpgcheck=0 + + EOF + let i=i+1 done + cat /etc/yum.repos.d/my.repo +} + +# create update directory and docker image +function create() { + echo "add docker image into the ${update_dir} directory." + cmd="if [ ! -d ${update_path}/${ARCH} ];then mkdir -p ${update_path}/${ARCH};fi" + ssh_cmd ${source_ip} "${cmd}" + config_repo + chroot_init + chroot "${root_path}" /bin/bash --login -c "cd /home/; bash make_docker.sh" + if [ -f "${root_path}/result/docker_image/image/openEuler-docker.${ARCH}.tar.xz" ];then + scp -i ${publish_key} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR -r ${root_path}/result/docker_image/image/openEuler-docker.${ARCH}.tar.xz root@${source_ip}:${update_path}/${ARCH}/ + scp -i ${publish_key} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR -r ${root_path}/result/docker_image/image/openEuler-docker.${ARCH}.tar.xz.sha256sum root@${source_ip}:${update_path}/${ARCH}/ + else + echo "make docker image failed." + chroot_clean + exit 1 + fi + chroot_clean } # delete update_xxx directory @@ -97,27 +123,6 @@ function delete_update_dir() { ssh_cmd ${source_ip} "${cmd}" } -# delete docker image -function delete_docker_image() { - echo "delete docker image from the ${update_path} directory." - cmd="if [ ! -d ${update_path} ];then echo \"Error: ${update_path} is not exist.\" && exit 1;fi" - ssh_cmd ${source_ip} "${cmd}" - for ar in ${arch_list[@]} - do - cmd="rm -f ${update_path}/${ar}/openEuler-docker.${ar}.tar.xz" - ssh_cmd ${source_ip} "${cmd}" - cmd="rm -f ${update_path}/${ar}/openEuler-docker.${ar}.tar.xz.sha256sum" - ssh_cmd ${source_ip} "${cmd}" - done -} - -# update docker image -function update() { - echo "update docker image in the ${update_path} directory." - delete_docker_image - create -} - # publish docker image file function release() { cmd="if [ ! -d ${update_path} ];then echo \"Error: ${update_path} is not exist.\" && exit 1;fi" @@ -152,7 +157,7 @@ function release() { # main function function main() { - if [ $# -lt 6 ] || [ $# -gt 7 ];then + if [ $# -lt 5 ] || [ $# -gt 6 ];then echo "Error: please check the params." usage exit 1 @@ -160,11 +165,10 @@ function main() { operation=$1 branch_name=$2 - openeuler_dir=$3 - update_dir=$4 - source_ip=$5 - release_ip=$6 - publish_key=$7 + update_dir=$3 + source_ip=$4 + release_ip=$5 + publish_key=$6 if [ -z "${operation}" ] || [ -z "${branch_name}" ] || [ -z "${update_dir}" ] || [ -z "${source_ip}" ] || [ -z "${release_ip}" ] || [ -z "${publish_key}" ];then echo "Error: please check the params." @@ -172,22 +176,12 @@ function main() { exit 1 fi - need_openeuler_dir=(create update) - if [[ ${need_openeuler_dir[@]} =~ ${operation} ]];then - if [ -z "${openeuler_dir}" ];then - echo "Error: openeuler_dir is empty." - usage - exit 1 - fi - fi - if [ "x${update_dir}" == "x" ];then update_dir="update_"`date +%Y%m%d` fi arch_list=(aarch64 x86_64) need_modify_json=(create delete_update_dir release) - source_img_dir="/repo/openeuler/dailybuild/${branch_name}/${openeuler_dir}/docker_img" if [[ ${branch_name} =~ "EBS-" ]];then branch_name=${branch_name#*-} @@ -199,6 +193,8 @@ function main() { date_str="$(date +%Y-%m-%d)" backup_path="${branch_path}/docker_img/update/${date_str}" release_path="/repo/openeuler/${branch_name}/docker_img/update/${date_str}" + ARCH=$(arch) + export repo_url="https://repo.openeuler.org/${branch_name}/everything/${ARCH} https://repo.openeuler.org/${branch_name}/update/${ARCH}" if [ ${operation} == "create" ];then create @@ -206,8 +202,6 @@ function main() { elif [ ${operation} == "delete_update_dir" ];then delete_update_dir update_json_file - elif [ ${operation} == "update" ];then - update elif [ ${operation} == "release" ];then release update_json_file diff --git a/script/tools/make_docker.sh b/script/tools/make_docker.sh new file mode 100644 index 0000000..aa79fa3 --- /dev/null +++ b/script/tools/make_docker.sh @@ -0,0 +1,76 @@ +# repo_url + + +function kiwi_init() +{ + if [ ! -f /usr/share/perl5/vendor_perl/Env.pm ]; then + cp "${docker_config}/Env.pm" /usr/share/perl5/vendor_perl/ + fi + + if which kiwi &> /dev/null; then + echo "kiwi has been ok" + else + cat /etc/yum.repos.d/my.repo + yum clean all + yum install -y python3-setuptools python3-docopt python3-future libisofs libburn libisoburn kde-filesystem ostree-libs xorriso kiwi umoci containers-common skopeo + fi + umask_value=$(umask) + if [ "x${umask_value}" != "x0022" ]; then + umask 0022 + fi + if [ ! -d /var/run/screen/S-root ]; then + mkdir -p /var/run/screen/S-root + fi + chmod 700 /var/run/screen/S-root +} + +function make_image() +{ + ARCH="$(uname -m)" + + rm -rf /tmp/openeuler-os-build + git clone -b master https://gitee.com/openeuler/openeuler-os-build /tmp/openeuler-os-build + if [ $? -ne 0 ];then + echo "[ERROR] clone openeuler-os-build failed" + exit 1 + fi + + docker_config="/tmp/openeuler-os-build/script/config/docker_image" + img_dir="/result/docker_image/image" + repo_dir="/result/docker_image/repository" + cfg_dir="/result/docker_image/config" + rm -rf "${img_dir}" && mkdir -p "${img_dir}" + rm -rf "${repo_dir}" && mkdir -p "${repo_dir}" + rm -rf "${cfg_dir}" && mkdir -p "${cfg_dir}" + + kiwi_init + + rm -rf /var/adm/fillup-templates/ && mkdir -p /var/adm/fillup-templates/ + cp "${docker_config}/passwd" /var/adm/fillup-templates/passwd.aaa_base + cp "${docker_config}/group" /var/adm/fillup-templates/group.aaa_base + + version_time="openeuler-$(date +%Y-%m-%d-%H-%M-%S)" + sed -i "s#IMAGE_NAME#${version_time}#" "${docker_config}/config.xml" + sed -i "/obs_repo_here/a " "${docker_config}/config.xml" + cp "${docker_config}/config.xml" "${cfg_dir}" + cp "${docker_config}/images.sh" "${cfg_dir}" + + rm -rf /tmp/openeuler-os-build + rm -rf /var/cache/kiwi/yum + + kiwi compat --build "${cfg_dir}" -d "${img_dir}" + if [ $? -ne 0 ];then + echo "[ERROR] Failed on kiwi build docker image" + exit 1 + fi + + docker_img_name="openEuler-docker.${ARCH}.tar.xz" + cd "${img_dir}" + tmp_name=$(ls *.tar.xz) + mv "${tmp_name}" "${docker_img_name}" + sha256sum "${docker_img_name}" > "${docker_img_name}.sha256sum" + echo "[INFO] make docker image success" +} + + +make_image -- Gitee