Skip to content

Commit

Permalink
Merge pull request #160 from Burning1020/extra-common-shell
Browse files Browse the repository at this point in the history
building: extra common scriptes for image building and bump ttrpc-compiler
  • Loading branch information
Vanient authored Aug 15, 2024
2 parents e89aa15 + 9d2a32f commit 837a900
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 149 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install WasmEdge
if: ${{ matrix.wasmEdge }}
run: curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- -v ${{ matrix.wasmEdge }} >> /dev/null
run: curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | sudo -E bash -s -- -v ${{ matrix.wasmEdge }} >> /dev/null
- name: Test
env:
RUST_BACKTRACE: full
Expand Down
12 changes: 6 additions & 6 deletions vmm/sandbox/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vmm/scripts/image/build_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ AGENT_INIT=${AGENT_INIT:-yes}

# Align image to (size in MB) according to different architecture.
case "$(uname -m)" in
aarch64) readonly mem_boundary_mb=16 ;;
aarch64) readonly mem_boundary_mb=128 ;;
*) readonly mem_boundary_mb=128 ;;
esac

Expand Down Expand Up @@ -339,7 +339,7 @@ create_disk() {
# The partition is the rootfs content
info "Creating partitions"
parted -s -a optimal "${image}" -- \
mklabel gpt \
mklabel msdos \
mkpart primary "${fs_type}" "${part_start}"M "${rootfs_end}"M

OK "Partitions created"
Expand Down
136 changes: 2 additions & 134 deletions vmm/scripts/image/centos/build_rootfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,144 +19,12 @@ golang_version="1.20.5"
cert_file_path="/kuasar/proxy.crt"
ARCH=$(uname -m)

make_vmm_task() {
local repo_dir="$1"

yum install -y cmake make gcc-c++ wget

# update cert file under internal proxy scenario
if [ -f "${cert_file_path}" ]; then
cp ${cert_file_path} /etc/pki/ca-trust/source/anchors/
update-ca-trust extract
fi

# install rust to compile vmm-task
pushd ${repo_dir}

source vmm/scripts/image/install_rust.sh

make bin/vmm-task ARCH=${ARCH}
popd
}

install_golang() {
pushd /home/
arch_name=""
if [ "${ARCH}" == "aarch64" ]; then
arch_name="arm64"
elif [ "${ARCH}" == "x86_64" ]; then
arch_name="amd64"
else
echo "Unsupported arch: ${ARCH}"
exit 1
fi
rm -f go${golang_version}.linux-${arch_name}.tar.gz
wget -q "https://go.dev/dl/go${golang_version}.linux-${arch_name}.tar.gz"
rm -rf /usr/local/go && tar -C /usr/local -xzf "go${golang_version}.linux-${arch_name}.tar.gz"
echo "export PATH=$PATH:/usr/local/go/bin" >>/etc/profile
source /etc/profile
go version
popd
}

build_runc() {
local repo_dir="$1"
mkdir -p /tmp/gopath
GOPATH=/tmp/gopath go install github.com/opencontainers/[email protected]
cp /tmp/gopath/bin/runc ${repo_dir}/bin/
}

create_tmp_rootfs() {
local rootfs_dir="$1"
rm -rf ${rootfs_dir}/*
mkdir -p ${rootfs_dir}/lib \
${rootfs_dir}/lib64 \
${rootfs_dir}/lib/modules

mkdir -m 0755 -p ${rootfs_dir}/dev \
${rootfs_dir}/sys \
${rootfs_dir}/sbin \
${rootfs_dir}/bin \
${rootfs_dir}/tmp \
${rootfs_dir}/proc \
${rootfs_dir}/etc \
${rootfs_dir}/run \
${rootfs_dir}/var

ln -s ../run ${rootfs_dir}/var/run
touch ${rootfs_dir}/etc/resolv.conf
}

install_and_copy_rpm() {
set +e
local rpm_list_file="$1"
local rootfs_dir="$2"
cat ${rpm_list_file} | while read rpm; do
if [ "${rpm:0:1}" != "#" ]; then
rpm -ql $rpm >/dev/null 2>&1
if [ $? -ne 0 ]; then
yum install -y $rpm >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Can not install $rpm by yum"
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
dst_file=${rootfs_dir}$file
dst_folder=${dst_file%/*}
if [ ! -d "$dst_folder" ] && [ ! -L "$dst_folder" ]; then
mkdir -p $dst_folder
fi
cp -r -f -d $source $dst_folder
done
fi
done
set -e
}

copy_binaries() {
local binaries_list_file="$1"
local rootfs_dir="$2"
cat $binaries_list_file | while read line; do
if [ -n "${line}" ] && [ "${line:0:1}" != "#" ]; then
source=$(echo "${line}" | awk '{print $1}')
des=$(echo "${line}" | awk '{print $2}')
if [ ! -d "$des" ]; then
mkdir -p $des
fi
cp -r -d $source ${rootfs_dir}/$des
fi
done
}

copy_libs() {
local binaries_list_file="$1"
local rootfs_dir="$2"
binaries_list=$(cat $binaries_list_file | grep -v "#" | awk '{print $1}')
binaries_list=(${binaries_list[@]} ${rootfs_dir}/sbin/init)
for bin in ${binaries_list[@]}; do
ldd ${bin} | while read line; do
arr=(${line// / })

for lib in ${arr[@]}; do
echo $lib
if [ "${lib:0:1}" = "/" ]; then
dir=${rootfs_dir}/$(dirname $lib)
mkdir -p "${dir}"
cp -f $lib $dir
fi
done
done
done
}
current_dir=$(dirname "$(realpath "$0")")
source $current_dir/../common.sh

main() {
local rootfs_dir=${ROOTFS_DIR:-/tmp/kuasar-rootfs}
local repo_dir=${REPO_DIR:-/kuasar}
local current_dir="$(dirname $(readlink -f $0))"
make_vmm_task ${repo_dir}
install_golang
build_runc ${repo_dir}
Expand Down
148 changes: 148 additions & 0 deletions vmm/scripts/image/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
#!/bin/bash
# Copyright 2024 The Kuasar Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

make_vmm_task() {
local repo_dir="$1"

yum install -y cmake make gcc-c++ wget

# update cert file under internal proxy scenario
if [ -f "${cert_file_path}" ]; then
cp ${cert_file_path} /etc/pki/ca-trust/source/anchors/
update-ca-trust extract
fi

# install rust to compile vmm-task
pushd ${repo_dir}

source vmm/scripts/image/install_rust.sh

make bin/vmm-task ARCH=${ARCH}
popd
}

install_golang() {
pushd /home/
arch_name=""
if [ "${ARCH}" == "aarch64" ]; then
arch_name="arm64"
elif [ "${ARCH}" == "x86_64" ]; then
arch_name="amd64"
else
echo "Unsupported arch: ${ARCH}"
exit 1
fi
rm -f go${golang_version}.linux-${arch_name}.tar.gz
wget -q "https://go.dev/dl/go${golang_version}.linux-${arch_name}.tar.gz"
rm -rf /usr/local/go && tar -C /usr/local -xzf "go${golang_version}.linux-${arch_name}.tar.gz"
echo "export PATH=$PATH:/usr/local/go/bin" >>/etc/profile
source /etc/profile
go version
popd
}

build_runc() {
local repo_dir="$1"
mkdir -p /tmp/gopath
GOPATH=/tmp/gopath go install github.com/opencontainers/[email protected]
cp /tmp/gopath/bin/runc ${repo_dir}/bin/
}

create_tmp_rootfs() {
local rootfs_dir="$1"
rm -rf ${rootfs_dir}/*
mkdir -p ${rootfs_dir}/lib \
${rootfs_dir}/lib64 \
${rootfs_dir}/lib/modules

mkdir -m 0755 -p ${rootfs_dir}/dev \
${rootfs_dir}/sys \
${rootfs_dir}/sbin \
${rootfs_dir}/bin \
${rootfs_dir}/tmp \
${rootfs_dir}/proc \
${rootfs_dir}/etc \
${rootfs_dir}/run \
${rootfs_dir}/var

ln -s ../run ${rootfs_dir}/var/run
touch ${rootfs_dir}/etc/resolv.conf
}

install_and_copy_rpm() {
set +e
local rpm_list_file="$1"
local rootfs_dir="$2"
cat ${rpm_list_file} | while read rpm; do
if [ "${rpm:0:1}" != "#" ]; then
rpm -ql $rpm >/dev/null 2>&1
if [ $? -ne 0 ]; then
yum install -y $rpm >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Can not install $rpm by yum"
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
dst_file=${rootfs_dir}$file
dst_folder=${dst_file%/*}
if [ ! -d "$dst_folder" ] && [ ! -L "$dst_folder" ]; then
mkdir -p $dst_folder
fi
cp -r -f -d $source $dst_folder
done
fi
done
set -e
}

copy_binaries() {
local binaries_list_file="$1"
local rootfs_dir="$2"
cat $binaries_list_file | while read line; do
if [ -n "${line}" ] && [ "${line:0:1}" != "#" ]; then
source=$(echo "${line}" | awk '{print $1}')
des=$(echo "${line}" | awk '{print $2}')
if [ ! -d "$des" ]; then
mkdir -p $des
fi
cp -r -d $source ${rootfs_dir}/$des
fi
done
}

copy_libs() {
local binaries_list_file="$1"
local rootfs_dir="$2"
binaries_list=$(cat $binaries_list_file | grep -v "#" | awk '{print $1}')
binaries_list=(${binaries_list[@]} ${rootfs_dir}/sbin/init)
for bin in ${binaries_list[@]}; do
ldd ${bin} | while read line; do
arr=(${line// / })

for lib in ${arr[@]}; do
echo $lib
if [ "${lib:0:1}" = "/" ]; then
dir=${rootfs_dir}/$(dirname $lib)
mkdir -p "${dir}"
cp -f $lib $dir
fi
done
done
done
}
12 changes: 6 additions & 6 deletions vmm/task/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 837a900

Please sign in to comment.