Skip to content

Commit

Permalink
build: add some commands and make build.sh independent
Browse files Browse the repository at this point in the history
1. add some command binaries for debug in vm
2. build.sh is for docker/ctr/isula to prepare guest rootfs
and build it to image or initrd, thus it should not have any
difference with each guest os.

Signed-off-by: Zhang Tianyang <burning9699@gmail.com>
  • Loading branch information
Burning1020 committed Apr 9, 2024
1 parent af4128a commit 57a4643
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ bin/vmlinux.bin:
@mkdir -p bin && cp vmm/scripts/kernel/${HYPERVISOR}/vmlinux.bin bin/vmlinux.bin && rm vmm/scripts/kernel/${HYPERVISOR}/vmlinux.bin

bin/kuasar.img:
@bash vmm/scripts/image/${GUESTOS_IMAGE}/build.sh image
@bash vmm/scripts/image/build.sh image ${GUESTOS_IMAGE}
@mkdir -p bin && cp /tmp/kuasar.img bin/kuasar.img && rm /tmp/kuasar.img

bin/kuasar.initrd:
@bash vmm/scripts/image/${GUESTOS_IMAGE}/build.sh initrd
@bash vmm/scripts/image/build.sh initrd ${GUESTOS_IMAGE}
@mkdir -p bin && cp /tmp/kuasar.initrd bin/kuasar.initrd && rm /tmp/kuasar.initrd

bin/wasm-sandboxer:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

exit_flag=0
export GUESTOS_IMAGE=${2:-"centos"}
export IMAGE_NAME=${IMAGE_NAME:-"centos:7"}
export ROOTFS_DIR=${ROOTFS_DIR:-"/tmp/kuasar-rootfs"}
export CONTAINER_RUNTIME=${RUNTIME:-"containerd"}
Expand All @@ -40,7 +41,7 @@ echo "build in ${IMAGE_NAME}"

if [ ! -n "${REPO_DIR}" ]; then
current_dir=$(dirname "$(readlink -f "$0")")
pushd ${current_dir}/../../../..
pushd ${current_dir}/../../..
REPO_DIR=$(pwd)
popd
fi
Expand Down Expand Up @@ -68,7 +69,7 @@ containerd)
--mount type=bind,src="${ROOTFS_DIR}",dst=/tmp/kuasar-rootfs,options=rbind:rw \
${IMAGE_NAME} \
${container_name} \
bash /kuasar/vmm/scripts/image/centos/build_rootfs.sh
bash /kuasar/vmm/scripts/image/${GUESTOS_IMAGE}/build_rootfs.sh
fn_check_result $? "ctr run ${container_name} return error!"
;;
docker)
Expand All @@ -80,7 +81,7 @@ docker)
-v "${REPO_DIR}":/kuasar \
-v "${ROOTFS_DIR}":"/tmp/kuasar-rootfs" \
${IMAGE_NAME} \
bash /kuasar/vmm/scripts/image/centos/build_rootfs.sh
bash /kuasar/vmm/scripts/image/${GUESTOS_IMAGE}/build_rootfs.sh
fn_check_result $? "docker run ${container_name} return error!"
;;
isulad)
Expand All @@ -93,7 +94,7 @@ isulad)
-v "${REPO_DIR}":/kuasar \
-v "${ROOTFS_DIR}":"/tmp/kuasar-rootfs" \
${IMAGE_NAME} \
bash /kuasar/vmm/scripts/image/centos/build_rootfs.sh
bash /kuasar/vmm/scripts/image/${GUESTOS_IMAGE}/build_rootfs.sh
fn_check_result $? "isula run ${container_name} return error!"
;;
*)
Expand Down
9 changes: 0 additions & 9 deletions vmm/scripts/image/build_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,6 @@ check_rootfs() {

[ -d "${rootfs}" ] || die "${rootfs} is not a directory"

init_path="/sbin/init"
init="${rootfs}${init_path}"
if [ ! -x "${init}" ] && [ ! -L "${init}" ]; then
error "${init_path} is not installed in ${rootfs}"
return 1
fi
OK "init is installed"


candidate_systemd_paths="/usr/lib/systemd/systemd /lib/systemd/systemd"

# check agent or systemd
Expand Down
19 changes: 19 additions & 0 deletions vmm/scripts/image/centos/binaries.list
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
/usr/bin/sh /bin
# procps-ng
/usr/bin/ps /bin
/usr/bin/kill /bin
/usr/bin/free /bin
/usr/bin/top /bin
# kmod
/usr/sbin/modprobe /sbin
/usr/sbin/depmod /sbin
Expand All @@ -23,6 +26,7 @@
/usr/bin/quotasync /bin
# cni
/usr/sbin/arping /sbin
/usr/bin/ping /sbin
/usr/bin/echo /bin
# iptables
/usr/sbin/iptables /sbin
Expand All @@ -32,3 +36,18 @@
/usr/bin/ls /bin
/usr/bin/cat /bin
/usr/bin/cp /bin
/usr/bin/mv /bin
/usr/bin/rm /bin
/usr/bin/mkdir /bin
/usr/bin/find /bin
/usr/bin/awk /bin
/usr/bin/grep /bin
/usr/bin/chmod /bin
/usr/bin/chown /bin
/usr/bin/dmesg /bin
/usr/bin/ln /bin
/usr/bin/curl /bin
/usr/sbin/ethtool /sbin
/usr/bin/netstat /bin
/usr/sbin/ip /sbin
# End of file, do not delete
5 changes: 3 additions & 2 deletions vmm/scripts/image/centos/build_rootfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,16 @@ install_and_copy_rpm() {
yum install -y $rpm >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Can not install $rpm by yum"
exit 1
continue
fi
rpm -ql $rpm >/dev/null 2>&1 || continue
fi
array=($(rpm -ql $rpm | grep -v "share" | grep -v ".build-id"))
for file in ${array[@]}; do
source=$file
dts_file=${rootfs_dir}$file
dts_folder=${dts_file%/*}
if [ ! -d "$dts_folder" ]; then
if [ ! -d "$dts_folder" ] && [ ! -L "$dts_folder" ]; then
mkdir -p $dts_folder
fi
cp -r -f -d $source $dts_folder
Expand Down
5 changes: 5 additions & 0 deletions vmm/scripts/image/centos/rpm.list
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ libpcap
iptables
ipvsadm
conntrack-tools
curl
ethtool
net-tools
iproute
# End of file, do not delete

0 comments on commit 57a4643

Please sign in to comment.